From 80ccd69a76197892324ae8be9bdb85b31599990b Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 19 May 2022 16:32:53 +0200 Subject: [PATCH] change files_default_path to "/share/resiliosync/downloads" https://github.com/alexbelgium/hassio-addons/issues/333 --- .../rootfs/etc/cont-init.d/00-folders.sh | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/resiliosync/rootfs/etc/cont-init.d/00-folders.sh b/resiliosync/rootfs/etc/cont-init.d/00-folders.sh index 0e458f5e8..be229a2d3 100644 --- a/resiliosync/rootfs/etc/cont-init.d/00-folders.sh +++ b/resiliosync/rootfs/etc/cont-init.d/00-folders.sh @@ -26,33 +26,40 @@ change_folders () { grep -rl "$ORIGINALLOCATION" /etc/services.d | xargs sed -i "s|$ORIGINALLOCATION|$CONFIGLOCATION|g" sed -i "s=$ORIGINALLOCATION=$CONFIGLOCATION=g" /etc/cont-init.d/10-adduser sed -i "s=$ORIGINALLOCATION=$CONFIGLOCATION=g" /defaults/* - if [ "$TYPE" = "config_location" ]; then - [ -f "$ORIGINALLOCATION"/sync.conf ] && sed "s|$(jq -r .storage_path "$ORIGINALLOCATION"/sync.conf)|$CONFIGLOCATION|g" "$ORIGINALLOCATION"/sync.conf - [ -f "$CONFIGLOCATION"/sync.conf ] && sed "s|$(jq -r .storage_path "$CONFIGLOCATION"/sync.conf)|$CONFIGLOCATION|g" "$CONFIGLOCATION"/sync.conf - [ -f "/defaults/sync.conf" ] && sed "s|$(jq -r .storage_path "/defaults"/sync.conf)|$CONFIGLOCATION|g" /defaults/sync.conf - fi - if [ "$TYPE" = "data_location" ]; then - [ -f "$ORIGINALLOCATION"/sync.conf ] && sed "s|$(jq -r .directory_root "$ORIGINALLOCATION"/sync.conf)|$CONFIGLOCATION/|g" "$ORIGINALLOCATION"/sync.conf - [ -f "$CONFIGLOCATION"/sync.conf ] && sed "s|$(jq -r .directory_root "$CONFIGLOCATION"/sync.conf)|$CONFIGLOCATION/|g" "$CONFIGLOCATION"/sync.conf - [ -f "/defaults/sync.conf" ] && sed "s|$(jq -r .directory_root "/defaults"/sync.conf)|$CONFIGLOCATION/|g" /defaults/sync.conf - mkdir -p "$CONFIGLOCATION"/folders - mkdir -p "$CONFIGLOCATION"/mounted_folders - fi + + # Adapt sync.conf + for FILE in "$ORIGINALLOCATION/sync.conf" "$CONFIGLOCATION/sync.conf" "/defaults/sync.conf"; do + if [ "$TYPE" = "config_location" ]; then + [ -f "$FILE" ] && sed "s|$(jq -r .storage_path "$FILE")|$CONFIGLOCATION/|g" "$FILE" + fi + if [ "$TYPE" = "data_location" ]; then + [ -f "$FILE" ] && sed "s|$(jq -r .directory_root "$FILE")|$CONFIGLOCATION/|g" "$FILE" + [ -f "$FILE" ] && sed "s|$(jq -r .files_default_path "$FILE")|$CONFIGLOCATION/downloads|g" "$FILE" + fi + done # Create folders - [ ! -d "$CONFIGLOCATION" ] && echo "Creating $CONFIGLOCATION" && mkdir -p "$CONFIGLOCATION" - - # Transfer files - [ -d "$,ORIGINALLOCATION" ] && echo "Moving files to $CONFIGLOCATION" && mv "$ORIGINALLOCATION"/* "$CONFIGLOCATION"/ && rmdir "$ORIGINALLOCATION" - + echo "Checking if folders exist" + for FOLDER in "$CONFIGSLOCATION" "$CONFIGSLOCATION"/folders "$CONFIGSLOCATION"/mounted_folders "$CONFIGSLOCATION"/downloads; do + [ ! -d "$FOLDER" ] && echo "Creating $FOLDER" && mkdir -p "$FOLDER" + done + # Set permissions - echo "Setting ownership to $PUID:$PGID" && chown -R "$PUID":"$PGID" "$CONFIGLOCATION" - + echo "Setting ownership to $PUID:$PGID" + chown -R "$PUID":"$PGID" "$CONFIGLOCATION" + + # Transfer files + if [ -d "$ORIGINALLOCATION" ]; then + echo "Files were existing in $ORIGINALLOCATION, they will be moved to $CONFIGLOCATION" + mv "$ORIGINALLOCATION"/* "$CONFIGLOCATION"/ + rmdir "$ORIGINALLOCATION" + fi } ######################## # Change data location # ######################## +# Adapt files change_folders "$(bashio::config 'config_location')" "/share/resiliosync_config" "config_location" change_folders "$(bashio::config 'data_location')" "/share/resiliosync" "data_location"