From 2428ed6d87bcd7854198570a1710b4bd2d6ba8ba Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:36:52 +0100 Subject: [PATCH] Try improved sed code https://github.com/alexbelgium/hassio-addons/issues/755 --- .../91-qbittorrent_configuration.sh | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh b/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh index 514c0cdff..7c7b5cf43 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh @@ -41,22 +41,13 @@ if bashio::config.has_value 'SavePath'; then # Set variable DOWNLOADS=$(bashio::config 'SavePath') + DOWNLOADS=${DOWNLOADS:-/share/downloads} # Default if not set # Replace save path - CURRENTSAVEPATH=$(sed -n '/Downloads\\\SavePath/p' qBittorrent.conf) - if [[ ${#CURRENTSAVEPATH} -gt 1 ]]; then - sed -i "s=${CURRENTSAVEPATH#*=}=$DOWNLOADS=g" qBittorrent.conf - else - sed -i "${LINE}a Downloads\\\SavePath=$DOWNLOADS" qBittorrent.conf - fi - - # Replace session save path - CURRENTSAVEPATH=$(sed -n '/Session\\\DefaultSavePath/p' qBittorrent.conf) - if [[ ${#CURRENTSAVEPATH} -gt 1 ]]; then - sed -i "s=${CURRENTSAVEPATH#*=}=$DOWNLOADS=g" qBittorrent.conf - else - sed -i "2a Session\\\DefaultSavePath=$DOWNLOADS" qBittorrent.conf - fi + sed -i -e "/SavePath/d" \ + -e "/\[Preferences\]/a Downloads\\\SavePath=$DOWNLOADS" \ + -e "/\[AutoRun\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \ + -e "/\[BitTorrent\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" qBittorrent.conf # Info bashio::log.info "Downloads can be found in $DOWNLOADS"