From 5f2b7dfa04c78d4679546784c56e0485b481a923 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Wed, 1 Feb 2023 23:46:35 +0100 Subject: [PATCH 01/54] removed "is set" check (#) unquoted "is set" check fails if var is not set and if-statement has a following check. Further the preceding "is empty" check is sufficient in this case. --- scripts/rfid_trigger_play.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index b1bc08ede..0b2700dee 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -348,10 +348,8 @@ if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "# Type of play \$VA # check if # - $FOLDER is not empty (! -z "$FOLDER") # - AND (-a) -# - $FOLDER is set (! -z ${FOLDER+x}) -# - AND (-a) # - and points to existing directory (-d "${AUDIOFOLDERSPATH}/${FOLDER}") -if [ ! -z "$FOLDER" -a ! -z ${FOLDER+x} -a -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then +if [ ! -z "$FOLDER" -a -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "\$FOLDER set, not empty and dir exists: ${AUDIOFOLDERSPATH}/${FOLDER}" >> $PATHDATA/../logs/debug.log; fi From 9c9e7c497c7a9692add76334514e275b94d62e67 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Fri, 3 Feb 2023 21:39:32 +0100 Subject: [PATCH 02/54] Sync fuer shortcuts und audiofile von lokalem Ordner (wenn Datei/Ordner nicht existent) --- scripts/rfid_trigger_play.sh | 393 ++++++++++++++++++++--------------- 1 file changed, 224 insertions(+), 169 deletions(-) diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 0b2700dee..c8ef3f1d5 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -311,8 +311,33 @@ if [ "$CARDID" ]; then # We checked if the card was a special command, seems it wasn't. # Now we expect it to be a trigger for one or more audio file(s). # Let's look at the ID, write a bit of log information and then try to play audio. - - # Look for human readable shortcut in folder 'shortcuts' + + # Sync shortcut from server if no text file is in folder 'shortcuts' + if [ ! -f $PATHDATA/../shared/shortcuts/$CARDID ] + then + if nc -z "test.schiller-dev.de" -w 1 22322 ; then + echo "Sync: Server is reachable" + SYNCREMOTEPATH="/home/pi/test/Phoniebox/" + SYNCSHORTCUTS="${SYNCREMOTEPATH}shortcuts/" + echo "Sync: Checking for shortcut: $CARDID in REMOTE: $SYNCSHORTCUTS" + if [ -f "${SYNCSHORTCUTS}${CARDID}" ]; then + echo "Sync: found ${SYNCSHORTCUTS}${CARDID}" + RSYNCSHORTCUTS=$(rsync -azi --no-o --no-g "${SYNCSHORTCUTS}${CARDID}" "$PATHDATA/../shared/shortcuts/") + echo "Sync: executed ${RSYNCSHORTCUTS}" + if [ $? -eq 0 -a -n "${RSYNCSHORTCUTS}" ]; then + echo "Sync: files copied" + else + echo "Sync: nothing changed" + fi + else + echo "Sync: $CARDID not found in REMOTE: $SYNCSHORTCUTS" + fi + else + echo "Sync: Server is NOT reachable" + fi + fi + + # Look for human readable shortcut in folder 'shortcuts' # check if CARDID has a text file by the same name - which would contain the human readable folder name if [ -f $PATHDATA/../shared/shortcuts/$CARDID ] then @@ -345,172 +370,202 @@ fi if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "# Attempting to play: $AUDIOFOLDERSPATH/$FOLDER" >> $PATHDATA/../logs/debug.log; fi if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "# Type of play \$VALUE: $VALUE" >> $PATHDATA/../logs/debug.log; fi -# check if -# - $FOLDER is not empty (! -z "$FOLDER") -# - AND (-a) -# - and points to existing directory (-d "${AUDIOFOLDERSPATH}/${FOLDER}") -if [ ! -z "$FOLDER" -a -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then - - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "\$FOLDER set, not empty and dir exists: ${AUDIOFOLDERSPATH}/${FOLDER}" >> $PATHDATA/../logs/debug.log; fi - - # if we play a folder the first time, add some sensible information to the folder.conf - if [ ! -f "${AUDIOFOLDERSPATH}/${FOLDER}/folder.conf" ]; then - # now we create a default folder.conf file by calling this script - # with the command param createDefaultFolderConf - # (see script for details) - # the $FOLDER would not need to be passed on, because it is already set in this script - # see inc.writeFolderConfig.sh for details - . $PATHDATA/inc.writeFolderConfig.sh -c=createDefaultFolderConf -d="${FOLDER}" - fi - - # get the name of the last folder played. As mpd doesn't store the name of the last - # playlist, we have to keep track of it via the Latest_Folder_Played file - LASTFOLDER=$(cat $PATHDATA/../settings/Latest_Folder_Played) - LASTPLAYLIST=$(cat $PATHDATA/../settings/Latest_Playlist_Played) - # this might need to go? resume not working... echo ${FOLDER} > $PATHDATA/../settings/Latest_Folder_Played - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTFOLDER: $LASTFOLDER" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: $LASTPLAYLIST" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Checking 'recursive' list? VAR \$VALUE: $VALUE" >> $PATHDATA/../logs/debug.log; fi - - if [ "$VALUE" == "recursive" ]; then - # set path to playlist - # replace subfolder slashes with " % " - PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }-%RCRSV%.m3u" - PLAYLISTNAME="${FOLDER//\//\ %\ }-%RCRSV%" - $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' > "${PLAYLISTPATH}" - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? YES" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" --list 'recursive' > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi - else - # set path to playlist - # replace subfolder slashes with " % " - PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }.m3u" - PLAYLISTNAME="${FOLDER//\//\ %\ }" - $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" > "${PLAYLISTPATH}" - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? NO" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi - fi - - # Second Swipe value - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$SECONDSWIPE: ${SECONDSWIPE}" >> $PATHDATA/../logs/debug.log; fi - # Playlist name - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$PLAYLISTNAME: ${PLAYLISTNAME}" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: ${LASTPLAYLIST}" >> $PATHDATA/../logs/debug.log; fi - - # Setting a VAR to start "play playlist from start" - # This will be changed in the following checks "if this is the second swipe" - PLAYPLAYLIST=yes - - # Check if the second swipe happened - # - The same playlist is cued up ("$LASTPLAYLIST" == "$PLAYLISTNAME") - if [ "$LASTPLAYLIST" == "$PLAYLISTNAME" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Second Swipe DID happen: \$LASTPLAYLIST == \$PLAYLISTNAME" >> $PATHDATA/../logs/debug.log; fi - - # check if - # - $SECONDSWIPE is set to toggle pause/play ("$SECONDSWIPE" == "PAUSE") - # - AND (-a) - # - check the length of the playlist, if =0 then it was cleared before, a state, which should only - # be possible after a reboot ($PLLENGTH -gt 0) - PLLENGTH=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=playlistlength: ).*') - if [ $PLLENGTH -eq 0 ] - then - # after a reboot we want to play the playlist once no matter what the setting is - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Take second wipe as first after fresh boot" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "PAUSE" -a $PLLENGTH -gt 0 ] - then - # The following involves NOT playing the playlist, so we set: - PLAYPLAYLIST=no - - STATE=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=state: ).*') - if [ $STATE == "play" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " MPD playing, pausing the player" >> $PATHDATA/../logs/debug.log; fi - sudo $PATHDATA/playout_controls.sh -c=playerpause &>/dev/null - else - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "MPD not playing, start playing" >> $PATHDATA/../logs/debug.log; fi - sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null - fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: toggle pause/play" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "PLAY" -a $PLLENGTH -gt 0 ] - then - # The following involves NOT playing the playlist, so we set: - PLAYPLAYLIST=no - sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: Resume playback" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "NOAUDIOPLAY" ] - then - # The following involves NOT playing the playlist, so we set: - PLAYPLAYLIST=no - # following needs testing (see https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/914) - # Special case for NOAUDIOPLAY because once the playlist has finished, - # it needs to be noted by the system that the second swipe is like a *first* swipe. - currentSong=`mpc current` - if [[ -z "$currentSong" ]]; then - #end of playlist (EOPL) reached. Ignore last played playlist - PLAYPLAYLIST=yes - fi - - # "$SECONDSWIPE" == "NOAUDIOPLAY" - # "$LASTPLAYLIST" == "$PLAYLISTNAME" => same playlist triggered again - # => do nothing - # echo "do nothing" > /dev/null 2>&1 - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: do nothing" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "SKIPNEXT" ] - then - # We will not play the playlist but skip to the next track: - PLAYPLAYLIST=skipnext - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: skip next track" >> $PATHDATA/../logs/debug.log; fi - fi - fi - # now we check if we are still on for playing what we got passed on: - if [ "$PLAYPLAYLIST" == "yes" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "We must play the playlist no matter what: \$PLAYPLAYLIST == yes" >> $PATHDATA/../logs/debug.log; fi - - # Above we already checked if the folder exists -d "$AUDIOFOLDERSPATH/$FOLDER" - # - # the process is as such - because of the recursive play option: - # - each folder can be played. - # - a single folder will create a playlist with the same name as the folder - # - because folders can live inside other folders, the relative path might contain - # slashes (e.g. audiobooks/Moby Dick/) - # - because slashes can not be in the playlist name, slashes are replaced with " % " - # - the "recursive" option means that the content of the folder AND all subfolders - # is being played - # - in this case, the playlist is related to the same folder name, which means we need - # to make a different name for "recursive" playout - # - a recursive playlist has the suffix " %RCRSV%" - keeping it cryptic to avoid clashes - # with a possible "real" name for a folder - # - with this new logic, there are no more SPECIALFORMAT playlists. Live streams and podcasts - # are now all unfolded into the playlist - # - creating the playlist is now done in the php script with parameters: - # $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' - - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi - - # save position of current playing list "stop" - $PATHDATA/playout_controls.sh -c=playerstop - # play playlist - # the variable passed on to play is the playlist name -v (NOT the folder name) - # because (see above) a folder can be played recursively (including subfolders) or flat (only containing files) - # load new playlist and play - $PATHDATA/playout_controls.sh -c=playlistaddplay -v="${PLAYLISTNAME}" -d="${FOLDER}" - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playlistaddplay -v=\"${PLAYLISTNAME}\" -d=\"${FOLDER}\"" >> $PATHDATA/../logs/debug.log; fi - # save latest playlist not to file - sudo echo ${PLAYLISTNAME} > $PATHDATA/../settings/Latest_Playlist_Played - sudo chown pi:www-data $PATHDATA/../settings/Latest_Playlist_Played - sudo chmod 777 $PATHDATA/../settings/Latest_Playlist_Played - fi - if [ "$PLAYPLAYLIST" == "skipnext" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Skip to the next track in the playlist: \$PLAYPLAYLIST == skipnext" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi - - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playernext" >> $PATHDATA/../logs/debug.log; fi - $PATHDATA/playout_controls.sh -c=playernext - fi +# check if $FOLDER is not empty +if [ ! -z "$FOLDER" ]; then + + echo "VAR FOLDER is set to $FOLDER" + if [ ! -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "\$FOLDER not empty, but dir does not exists: ${AUDIOFOLDERSPATH}/${FOLDER}" >> $PATHDATA/../logs/debug.log; fi + if nc -z "test.schiller-dev.de" -w 1 22322 ; then + echo "Sync: Server is reachable" + SYNCREMOTEPATH="/home/pi/test/Phoniebox/" + SYNCSAUDIOFILES="${SYNCREMOTEPATH}audiofolders/" + echo "Sync: Checking for audiofolders: $FOLDER in REMOTE: $SYNCSAUDIOFILES" + if [ -d "${SYNCSAUDIOFILES}${FOLDER}" ]; then + echo "Exists: ${SYNCSAUDIOFILES}${FOLDER}" + RSYNCSAUDIOFILES=$(rsync -azi --no-o --no-g "${SYNCSAUDIOFILES}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + echo "Sync: executed ${RSYNCSAUDIOFILES}" + if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then + echo "Sync: files copied" + echo "Sync: update database and restart mpd" + sudo mpc update > /dev/null 2>&1 + sudo service mpd restart > /dev/null 2>&1 + else + echo "Sync: nothing changed" + fi + else + echo "FOLDER: $FOLDER not found in REMOTE: $SYNCREMOTEPATH" + fi + else + echo "Sync: Server is NOT reachable" + fi + fi + + # check if $FOLDER points to existing directory + if [ -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "\$FOLDER not empty and dir exists: ${AUDIOFOLDERSPATH}/${FOLDER}" >> $PATHDATA/../logs/debug.log; fi + + # if we play a folder the first time, add some sensible information to the folder.conf + if [ ! -f "${AUDIOFOLDERSPATH}/${FOLDER}/folder.conf" ]; then + # now we create a default folder.conf file by calling this script + # with the command param createDefaultFolderConf + # (see script for details) + # the $FOLDER would not need to be passed on, because it is already set in this script + # see inc.writeFolderConfig.sh for details + . $PATHDATA/inc.writeFolderConfig.sh -c=createDefaultFolderConf -d="${FOLDER}" + fi + + # get the name of the last folder played. As mpd doesn't store the name of the last + # playlist, we have to keep track of it via the Latest_Folder_Played file + LASTFOLDER=$(cat $PATHDATA/../settings/Latest_Folder_Played) + LASTPLAYLIST=$(cat $PATHDATA/../settings/Latest_Playlist_Played) + # this might need to go? resume not working... echo ${FOLDER} > $PATHDATA/../settings/Latest_Folder_Played + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTFOLDER: $LASTFOLDER" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: $LASTPLAYLIST" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Checking 'recursive' list? VAR \$VALUE: $VALUE" >> $PATHDATA/../logs/debug.log; fi + + if [ "$VALUE" == "recursive" ]; then + # set path to playlist + # replace subfolder slashes with " % " + PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }-%RCRSV%.m3u" + PLAYLISTNAME="${FOLDER//\//\ %\ }-%RCRSV%" + $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' > "${PLAYLISTPATH}" + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? YES" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" --list 'recursive' > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi + else + # set path to playlist + # replace subfolder slashes with " % " + PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }.m3u" + PLAYLISTNAME="${FOLDER//\//\ %\ }" + $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" > "${PLAYLISTPATH}" + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? NO" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi + fi + + # Second Swipe value + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$SECONDSWIPE: ${SECONDSWIPE}" >> $PATHDATA/../logs/debug.log; fi + # Playlist name + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$PLAYLISTNAME: ${PLAYLISTNAME}" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: ${LASTPLAYLIST}" >> $PATHDATA/../logs/debug.log; fi + + # Setting a VAR to start "play playlist from start" + # This will be changed in the following checks "if this is the second swipe" + PLAYPLAYLIST=yes + + # Check if the second swipe happened + # - The same playlist is cued up ("$LASTPLAYLIST" == "$PLAYLISTNAME") + if [ "$LASTPLAYLIST" == "$PLAYLISTNAME" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Second Swipe DID happen: \$LASTPLAYLIST == \$PLAYLISTNAME" >> $PATHDATA/../logs/debug.log; fi + + # check if + # - $SECONDSWIPE is set to toggle pause/play ("$SECONDSWIPE" == "PAUSE") + # - AND (-a) + # - check the length of the playlist, if =0 then it was cleared before, a state, which should only + # be possible after a reboot ($PLLENGTH -gt 0) + PLLENGTH=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=playlistlength: ).*') + if [ $PLLENGTH -eq 0 ] + then + # after a reboot we want to play the playlist once no matter what the setting is + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Take second wipe as first after fresh boot" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "PAUSE" -a $PLLENGTH -gt 0 ] + then + # The following involves NOT playing the playlist, so we set: + PLAYPLAYLIST=no + + STATE=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=state: ).*') + if [ $STATE == "play" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " MPD playing, pausing the player" >> $PATHDATA/../logs/debug.log; fi + sudo $PATHDATA/playout_controls.sh -c=playerpause &>/dev/null + else + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "MPD not playing, start playing" >> $PATHDATA/../logs/debug.log; fi + sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null + fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: toggle pause/play" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "PLAY" -a $PLLENGTH -gt 0 ] + then + # The following involves NOT playing the playlist, so we set: + PLAYPLAYLIST=no + sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: Resume playback" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "NOAUDIOPLAY" ] + then + # The following involves NOT playing the playlist, so we set: + PLAYPLAYLIST=no + # following needs testing (see https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/914) + # Special case for NOAUDIOPLAY because once the playlist has finished, + # it needs to be noted by the system that the second swipe is like a *first* swipe. + currentSong=`mpc current` + if [[ -z "$currentSong" ]]; then + #end of playlist (EOPL) reached. Ignore last played playlist + PLAYPLAYLIST=yes + fi + + # "$SECONDSWIPE" == "NOAUDIOPLAY" + # "$LASTPLAYLIST" == "$PLAYLISTNAME" => same playlist triggered again + # => do nothing + # echo "do nothing" > /dev/null 2>&1 + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: do nothing" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "SKIPNEXT" ] + then + # We will not play the playlist but skip to the next track: + PLAYPLAYLIST=skipnext + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: skip next track" >> $PATHDATA/../logs/debug.log; fi + fi + fi + # now we check if we are still on for playing what we got passed on: + if [ "$PLAYPLAYLIST" == "yes" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "We must play the playlist no matter what: \$PLAYPLAYLIST == yes" >> $PATHDATA/../logs/debug.log; fi + + # Above we already checked if the folder exists -d "$AUDIOFOLDERSPATH/$FOLDER" + # + # the process is as such - because of the recursive play option: + # - each folder can be played. + # - a single folder will create a playlist with the same name as the folder + # - because folders can live inside other folders, the relative path might contain + # slashes (e.g. audiobooks/Moby Dick/) + # - because slashes can not be in the playlist name, slashes are replaced with " % " + # - the "recursive" option means that the content of the folder AND all subfolders + # is being played + # - in this case, the playlist is related to the same folder name, which means we need + # to make a different name for "recursive" playout + # - a recursive playlist has the suffix " %RCRSV%" - keeping it cryptic to avoid clashes + # with a possible "real" name for a folder + # - with this new logic, there are no more SPECIALFORMAT playlists. Live streams and podcasts + # are now all unfolded into the playlist + # - creating the playlist is now done in the php script with parameters: + # $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' + + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi + + # save position of current playing list "stop" + $PATHDATA/playout_controls.sh -c=playerstop + # play playlist + # the variable passed on to play is the playlist name -v (NOT the folder name) + # because (see above) a folder can be played recursively (including subfolders) or flat (only containing files) + # load new playlist and play + $PATHDATA/playout_controls.sh -c=playlistaddplay -v="${PLAYLISTNAME}" -d="${FOLDER}" + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playlistaddplay -v=\"${PLAYLISTNAME}\" -d=\"${FOLDER}\"" >> $PATHDATA/../logs/debug.log; fi + # save latest playlist not to file + sudo echo ${PLAYLISTNAME} > $PATHDATA/../settings/Latest_Playlist_Played + sudo chown pi:www-data $PATHDATA/../settings/Latest_Playlist_Played + sudo chmod 777 $PATHDATA/../settings/Latest_Playlist_Played + fi + if [ "$PLAYPLAYLIST" == "skipnext" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Skip to the next track in the playlist: \$PLAYPLAYLIST == skipnext" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi + + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playernext" >> $PATHDATA/../logs/debug.log; fi + $PATHDATA/playout_controls.sh -c=playernext + fi + else + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Path not found $AUDIOFOLDERSPATH/$FOLDER" >> $PATHDATA/../logs/debug.log; fi + fi else - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Path not found $AUDIOFOLDERSPATH/$FOLDER" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "var FOLDER empty" >> $PATHDATA/../logs/debug.log; fi fi From 80631a9b30917b078515527befe3c4539ebe2073 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 4 Feb 2023 00:45:29 +0100 Subject: [PATCH 03/54] chmod und chown korrigiert. update mpc angepasst --- scripts/rfid_trigger_play.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index c8ef3f1d5..6bc81738d 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -326,6 +326,8 @@ if [ "$CARDID" ]; then echo "Sync: executed ${RSYNCSHORTCUTS}" if [ $? -eq 0 -a -n "${RSYNCSHORTCUTS}" ]; then echo "Sync: files copied" + sudo chown pi:www-data "$PATHDATA/../shared/shortcuts/$CARDID" + sudo chmod -R 777 "$PATHDATA/../shared/shortcuts/$CARDID" else echo "Sync: nothing changed" fi @@ -387,9 +389,10 @@ if [ ! -z "$FOLDER" ]; then echo "Sync: executed ${RSYNCSAUDIOFILES}" if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then echo "Sync: files copied" - echo "Sync: update database and restart mpd" - sudo mpc update > /dev/null 2>&1 - sudo service mpd restart > /dev/null 2>&1 + echo "Sync: update database" + sudo chown pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo chmod -R 777 "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 else echo "Sync: nothing changed" fi From d8e1f2f70603990f5b5d4322828f4f02d23b10f6 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 4 Feb 2023 02:43:29 +0100 Subject: [PATCH 04/54] sync in eigenes Script ausgelagert --- scripts/rfid_trigger_play.sh | 58 +------------ scripts/sync_shared.sh | 134 ++++++++++++++++++++++++++++++ settings/debugLogging.conf.sample | 1 + 3 files changed, 139 insertions(+), 54 deletions(-) create mode 100755 scripts/sync_shared.sh diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 6bc81738d..18248665e 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -312,32 +312,8 @@ if [ "$CARDID" ]; then # Now we expect it to be a trigger for one or more audio file(s). # Let's look at the ID, write a bit of log information and then try to play audio. - # Sync shortcut from server if no text file is in folder 'shortcuts' - if [ ! -f $PATHDATA/../shared/shortcuts/$CARDID ] - then - if nc -z "test.schiller-dev.de" -w 1 22322 ; then - echo "Sync: Server is reachable" - SYNCREMOTEPATH="/home/pi/test/Phoniebox/" - SYNCSHORTCUTS="${SYNCREMOTEPATH}shortcuts/" - echo "Sync: Checking for shortcut: $CARDID in REMOTE: $SYNCSHORTCUTS" - if [ -f "${SYNCSHORTCUTS}${CARDID}" ]; then - echo "Sync: found ${SYNCSHORTCUTS}${CARDID}" - RSYNCSHORTCUTS=$(rsync -azi --no-o --no-g "${SYNCSHORTCUTS}${CARDID}" "$PATHDATA/../shared/shortcuts/") - echo "Sync: executed ${RSYNCSHORTCUTS}" - if [ $? -eq 0 -a -n "${RSYNCSHORTCUTS}" ]; then - echo "Sync: files copied" - sudo chown pi:www-data "$PATHDATA/../shared/shortcuts/$CARDID" - sudo chmod -R 777 "$PATHDATA/../shared/shortcuts/$CARDID" - else - echo "Sync: nothing changed" - fi - else - echo "Sync: $CARDID not found in REMOTE: $SYNCSHORTCUTS" - fi - else - echo "Sync: Server is NOT reachable" - fi - fi + # Sync shortcut $CARDID + $PATHDATA/sync_shared.sh -c=shortcuts -i=$CARDID # Look for human readable shortcut in folder 'shortcuts' # check if CARDID has a text file by the same name - which would contain the human readable folder name @@ -375,34 +351,8 @@ if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "# Type of play \$VA # check if $FOLDER is not empty if [ ! -z "$FOLDER" ]; then - echo "VAR FOLDER is set to $FOLDER" - if [ ! -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "\$FOLDER not empty, but dir does not exists: ${AUDIOFOLDERSPATH}/${FOLDER}" >> $PATHDATA/../logs/debug.log; fi - if nc -z "test.schiller-dev.de" -w 1 22322 ; then - echo "Sync: Server is reachable" - SYNCREMOTEPATH="/home/pi/test/Phoniebox/" - SYNCSAUDIOFILES="${SYNCREMOTEPATH}audiofolders/" - echo "Sync: Checking for audiofolders: $FOLDER in REMOTE: $SYNCSAUDIOFILES" - if [ -d "${SYNCSAUDIOFILES}${FOLDER}" ]; then - echo "Exists: ${SYNCSAUDIOFILES}${FOLDER}" - RSYNCSAUDIOFILES=$(rsync -azi --no-o --no-g "${SYNCSAUDIOFILES}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") - echo "Sync: executed ${RSYNCSAUDIOFILES}" - if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then - echo "Sync: files copied" - echo "Sync: update database" - sudo chown pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" - sudo chmod -R 777 "${AUDIOFOLDERSPATH}/${FOLDER}" - sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 - else - echo "Sync: nothing changed" - fi - else - echo "FOLDER: $FOLDER not found in REMOTE: $SYNCREMOTEPATH" - fi - else - echo "Sync: Server is NOT reachable" - fi - fi + # Sync audio folder $FOLDER + $PATHDATA/sync_shared.sh -c=audiofolders -d=$FOLDER # check if $FOLDER points to existing directory if [ -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then diff --git a/scripts/sync_shared.sh b/scripts/sync_shared.sh new file mode 100755 index 000000000..a89eb3546 --- /dev/null +++ b/scripts/sync_shared.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +# Description + +# Set the date and time of now +NOW=`date +%Y-%m-%d.%H:%M:%S` + +# USAGE EXAMPLES: +# +# syn shortcuts: +# ./sync_shared.sh -c=shortcuts -i=xxx +# +# syn audiofolders: +# ./sync_shared.sh -c=audiofolders -d=xxx +# +# +# VALID COMMANDS: +# shortcuts (with -i) +# audiofolders (with -d) + +# The absolute path to the folder which contains all the scripts. +# Unless you are working with symlinks, leave the following line untouched. +PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SHORTCUTSPATH="$PATHDATA/../shared/shortcuts" + +# Edit +REMOTESERVER="test.schiller-dev.de" +REMOTEPORT=22322 +#REMOTESYNCPATH="/home/pi/test/Phoniebox/" +REMOTESYNCPATH="/mnt/station-phoniebox/" + +# Common +SYNCSHORTCUTSPATH="${REMOTESYNCPATH}shortcuts/" +SYNCSAUDIOFILESPATH="${REMOTESYNCPATH}audiofolders/" + +############################################################# +# $DEBUG TRUE|FALSE +# Read debug logging configuration file +. ${PATHDATA}/../settings/debugLogging.conf + +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> ${PATHDATA}/../logs/debug.log; fi + +########################################################### +# Read global configuration file (and create if not exists) +# create the global configuration file from single files - if it does not exist +if [ ! -f ${PATHDATA}/../settings/global.conf ]; then + . ${PATHDATA}/inc.writeGlobalConfig.sh +fi +. ${PATHDATA}/../settings/global.conf +########################################################### + +############################################################# +# Get args from command line (see Usage above) +# Read the args passed on by the command line +# see following file for details: +. ${PATHDATA}/inc.readArgsFromCommandLine.sh + +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PATHDATA}/../logs/debug.log; fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PATHDATA}/../logs/debug.log; fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi + + +case $COMMAND in + shortcuts) + if [ ! -f "${SHORTCUTSPATH}/${CARDID}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID does not exist in $SHORTCUTSPATH -> syncing" >> $PATHDATA/../logs/debug.log; fi + + if nc -z $REMOTESERVER -w 1 $REMOTEPORT ; then + + if [ -f "${SYNCSHORTCUTSPATH}${CARDID}" ]; then + RSYNCSHORTCUTSCMD=$(rsync -azi --no-o --no-g "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}") + + if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PATHDATA}/../logs/debug.log; fi + + sudo chown pi:www-data "${SHORTCUTSPATH}/${CARDID}" + sudo chmod -R 777 "${SHORTCUTSPATH}/${CARDID}" + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PATHDATA}/../logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PATHDATA}/../logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PATHDATA}/../logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID does exist in $SHORTCUTSPATH -> not syncing" >> $PATHDATA/../logs/debug.log; fi + fi + ;; + audiofolders) + if [ ! -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER does not exist in $AUDIOFOLDERSPATH -> syncing" >> $PATHDATA/../logs/debug.log; fi + + if nc -z $REMOTESERVER -w 1 $REMOTEPORT ; then + + if [ -d "${SYNCSAUDIOFILESPATH}${FOLDER}" ]; then + RSYNCSAUDIOFILES=$(rsync -azi --no-o --no-g "${SYNCSAUDIOFILESPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + + if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PATHDATA}/../logs/debug.log; fi + + sudo chown pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo chmod -R 777 "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PATHDATA}/../logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCSAUDIOFILESPATH" >> ${PATHDATA}/../logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PATHDATA}/../logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER does exist in $AUDIOFOLDERSPATH -> not syncing" >> $PATHDATA/../logs/debug.log; fi + fi + ;; + *) + echo Unknown COMMAND $COMMAND + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi + ;; +esac diff --git a/settings/debugLogging.conf.sample b/settings/debugLogging.conf.sample index 9494224e3..1cece8131 100755 --- a/settings/debugLogging.conf.sample +++ b/settings/debugLogging.conf.sample @@ -10,3 +10,4 @@ DEBUG_resume_play_sh="FALSE" DEBUG_rfid_trigger_play_sh="FALSE" DEBUG_shuffle_play_sh="FALSE" DEBUG_single_play_sh="FALSE" +DEBUG_sync_shared_sh="FALSE" From 06604d3cb06cbc463d8e6a8912880a7570bc3087 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 5 Feb 2023 23:47:33 +0100 Subject: [PATCH 05/54] Settings in conf ausgelagert. Weitere Anpassungen im Abluaf Enabled Flag hinzugefuegt, mit fruehem ausstieg. rsync command ignoriert nun hinzufuegen der "folder.conf" als Aenderung. - hierdurch sync nicht nur bei erstem Scan sondern immer moeglich Ordner auf Remote werden initialisiert wenn nicht vorhanden. --- scripts/sync_shared.sh | 111 +++++++++++++++++-------------- settings/sync_shared.conf.sample | 4 ++ 2 files changed, 66 insertions(+), 49 deletions(-) create mode 100755 settings/sync_shared.conf.sample diff --git a/scripts/sync_shared.sh b/scripts/sync_shared.sh index a89eb3546..f36d4fddf 100755 --- a/scripts/sync_shared.sh +++ b/scripts/sync_shared.sh @@ -23,15 +23,6 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SHORTCUTSPATH="$PATHDATA/../shared/shortcuts" -# Edit -REMOTESERVER="test.schiller-dev.de" -REMOTEPORT=22322 -#REMOTESYNCPATH="/home/pi/test/Phoniebox/" -REMOTESYNCPATH="/mnt/station-phoniebox/" - -# Common -SYNCSHORTCUTSPATH="${REMOTESYNCPATH}shortcuts/" -SYNCSAUDIOFILESPATH="${REMOTESYNCPATH}audiofolders/" ############################################################# # $DEBUG TRUE|FALSE @@ -40,43 +31,69 @@ SYNCSAUDIOFILESPATH="${REMOTESYNCPATH}audiofolders/" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> ${PATHDATA}/../logs/debug.log; fi -########################################################### +############################################################# # Read global configuration file (and create if not exists) # create the global configuration file from single files - if it does not exist if [ ! -f ${PATHDATA}/../settings/global.conf ]; then . ${PATHDATA}/inc.writeGlobalConfig.sh fi . ${PATHDATA}/../settings/global.conf -########################################################### ############################################################# -# Get args from command line (see Usage above) -# Read the args passed on by the command line -# see following file for details: -. ${PATHDATA}/inc.readArgsFromCommandLine.sh +# Read configuration file +# create the configuration file from sample - if it does not exist +if [ ! -f ${PATHDATA}/../settings/sync_shared.conf ]; then + echo "sync_shared.conf not present" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Conf not present. Write from sample" >> ${PATHDATA}/../logs/debug.log; fi + cp ${PATHDATA}/../settings/sync_shared.conf.sample ${PATHDATA}/../settings/sync_shared.conf + # change the read/write so that later this might also be editable through the web app + sudo chown -R pi:www-data ${PATHDATA}/../settings/sync_shared.conf + sudo chmod -R 775 ${PATHDATA}/../settings/sync_shared.conf +fi + +. ${PATHDATA}/../settings/sync_shared.conf + + +if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> ${PATHDATA}/../logs/debug.log; fi + +else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> ${PATHDATA}/../logs/debug.log; fi + + # Set local vars + SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}shortcuts/" + SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}audiofolders/" -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PATHDATA}/../logs/debug.log; fi -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PATHDATA}/../logs/debug.log; fi -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi + ############################################################# + # Get args from command line (see Usage above) + # Read the args passed on by the command line + # see following file for details: + . ${PATHDATA}/inc.readArgsFromCommandLine.sh + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi -case $COMMAND in - shortcuts) - if [ ! -f "${SHORTCUTSPATH}/${CARDID}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID does not exist in $SHORTCUTSPATH -> syncing" >> $PATHDATA/../logs/debug.log; fi + + case $COMMAND in + shortcuts) + if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then - if nc -z $REMOTESERVER -w 1 $REMOTEPORT ; then + if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then + mkdir "${SYNCSHORTCUTSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PATHDATA}/../logs/debug.log; fi + fi if [ -f "${SYNCSHORTCUTSPATH}${CARDID}" ]; then - RSYNCSHORTCUTSCMD=$(rsync -azi --no-o --no-g "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}") + RSYNCSHORTCUTSCMD=$(rsync -azi --no-o --no-g --no-times "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}") if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PATHDATA}/../logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PATHDATA}/../logs/debug.log; fi sudo chown pi:www-data "${SHORTCUTSPATH}/${CARDID}" - sudo chmod -R 777 "${SHORTCUTSPATH}/${CARDID}" + sudo chmod -R 775 "${SHORTCUTSPATH}/${CARDID}" else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PATHDATA}/../logs/debug.log; fi @@ -89,26 +106,24 @@ case $COMMAND in else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PATHDATA}/../logs/debug.log; fi fi + ;; + audiofolders) + if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID does exist in $SHORTCUTSPATH -> not syncing" >> $PATHDATA/../logs/debug.log; fi - fi - ;; - audiofolders) - if [ ! -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER does not exist in $AUDIOFOLDERSPATH -> syncing" >> $PATHDATA/../logs/debug.log; fi - - if nc -z $REMOTESERVER -w 1 $REMOTEPORT ; then + if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then + mkdir "${SYNCAUDIOFOLDERSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PATHDATA}/../logs/debug.log; fi + fi - if [ -d "${SYNCSAUDIOFILESPATH}${FOLDER}" ]; then - RSYNCSAUDIOFILES=$(rsync -azi --no-o --no-g "${SYNCSAUDIOFILESPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + if [ -d "${SYNCAUDIOFOLDERSPATH}${FOLDER}" ]; then + RSYNCSAUDIOFILES=$(rsync -azi --no-o --no-g --no-times "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PATHDATA}/../logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PATHDATA}/../logs/debug.log; fi sudo chown pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" - sudo chmod -R 777 "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo chmod -R 775 "${AUDIOFOLDERSPATH}/${FOLDER}" sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 else @@ -116,19 +131,17 @@ case $COMMAND in fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCSAUDIOFILESPATH" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PATHDATA}/../logs/debug.log; fi fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PATHDATA}/../logs/debug.log; fi fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER does exist in $AUDIOFOLDERSPATH -> not syncing" >> $PATHDATA/../logs/debug.log; fi - fi - ;; - *) - echo Unknown COMMAND $COMMAND - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi - ;; -esac + ;; + *) + echo Unknown COMMAND $COMMAND + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi + ;; + esac + +fi diff --git a/settings/sync_shared.conf.sample b/settings/sync_shared.conf.sample new file mode 100755 index 000000000..616581199 --- /dev/null +++ b/settings/sync_shared.conf.sample @@ -0,0 +1,4 @@ +SYNCSHAREDENABLED="FALSE" +SYNCSHAREDREMOTESERVER="" +SYNCSHAREDREMOTEPORT="" +SYNCSHAREDREMOTEPATH="" \ No newline at end of file From 085b542f29567290138fb693f799ae76466a810e Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Mon, 6 Feb 2023 01:01:33 +0100 Subject: [PATCH 06/54] Synchronisierung korrigiert Uunveraenderte Dateien werden uebersprungen (--update). Permissions ignoriert (--np-perms). folder.conf als Aenderung ignoriert (--exclude). Nachtraegliches Setzen der Persmission korrigiert. --- scripts/sync_shared.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/sync_shared.sh b/scripts/sync_shared.sh index f36d4fddf..9d43c4866 100755 --- a/scripts/sync_shared.sh +++ b/scripts/sync_shared.sh @@ -86,7 +86,7 @@ else fi if [ -f "${SYNCSHORTCUTSPATH}${CARDID}" ]; then - RSYNCSHORTCUTSCMD=$(rsync -azi --no-o --no-g --no-times "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}") + RSYNCSHORTCUTSCMD=$(rsync -azui --no-o --no-g --no-times "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}") if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PATHDATA}/../logs/debug.log; fi @@ -116,13 +116,13 @@ else fi if [ -d "${SYNCAUDIOFOLDERSPATH}${FOLDER}" ]; then - RSYNCSAUDIOFILES=$(rsync -azi --no-o --no-g --no-times "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + RSYNCSAUDIOFILES=$(rsync -azui --no-o --no-g --no-perms --no-times --delete --exclude="folder.conf" "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PATHDATA}/../logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PATHDATA}/../logs/debug.log; fi - sudo chown pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo chown -R pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" sudo chmod -R 775 "${AUDIOFOLDERSPATH}/${FOLDER}" sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 From aba35eeadf3981e2aec3ba13b09eda3c2c775d92 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Mon, 6 Feb 2023 01:12:46 +0100 Subject: [PATCH 07/54] gitignore erweitert --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 04d9c5d32..fa3facbab 100755 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ settings/Playlists_Folders_Path settings/rfid_trigger_play.conf settings/Second_Swipe settings/ShowCover +settings/sync_shared.conf settings/version htdocs/config.php scripts/deviceName.txt From 9c18f6c6adabc93c29d8bf03095fd621a814bab6 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 9 Feb 2023 00:54:05 +0100 Subject: [PATCH 08/54] Sync Shared als Componente ausgelagert --- .gitignore | 1 + .../settings}/sync_shared.conf.sample | 1 - .../sync-shared-from-server}/sync_shared.sh | 80 +++++++++---------- scripts/inc.writeGlobalConfig.sh | 13 +++ scripts/rfid_trigger_play.sh | 12 ++- 5 files changed, 62 insertions(+), 45 deletions(-) rename {settings => components/synchronisation/sync-shared-from-server/settings}/sync_shared.conf.sample (73%) rename {scripts => components/synchronisation/sync-shared-from-server}/sync_shared.sh (66%) diff --git a/.gitignore b/.gitignore index fa3facbab..dea85e28b 100755 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ settings/rfid_trigger_play.conf settings/Second_Swipe settings/ShowCover settings/sync_shared.conf +settings/Sync_Shared_Enabled settings/version htdocs/config.php scripts/deviceName.txt diff --git a/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample similarity index 73% rename from settings/sync_shared.conf.sample rename to components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample index 616581199..00cfbbbb5 100755 --- a/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample @@ -1,4 +1,3 @@ -SYNCSHAREDENABLED="FALSE" SYNCSHAREDREMOTESERVER="" SYNCSHAREDREMOTEPORT="" SYNCSHAREDREMOTEPATH="" \ No newline at end of file diff --git a/scripts/sync_shared.sh b/components/synchronisation/sync-shared-from-server/sync_shared.sh similarity index 66% rename from scripts/sync_shared.sh rename to components/synchronisation/sync-shared-from-server/sync_shared.sh index 9d43c4866..73b63d1b0 100755 --- a/scripts/sync_shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync_shared.sh @@ -21,44 +21,44 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # The absolute path to the folder which contains all the scripts. # Unless you are working with symlinks, leave the following line untouched. PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SHORTCUTSPATH="$PATHDATA/../shared/shortcuts" - +PROJROOTPATH="$PATHDATA/../../.." +SHORTCUTSPATH="$PROJROOTPATH/shared/shortcuts" ############################################################# # $DEBUG TRUE|FALSE # Read debug logging configuration file -. ${PATHDATA}/../settings/debugLogging.conf +. ${PROJROOTPATH}/settings/debugLogging.conf -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> ${PATHDATA}/../logs/debug.log; fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> ${PROJROOTPATH}/logs/debug.log; fi ############################################################# # Read global configuration file (and create if not exists) # create the global configuration file from single files - if it does not exist -if [ ! -f ${PATHDATA}/../settings/global.conf ]; then +if [ ! -f ${PROJROOTPATH}/settings/global.conf ]; then . ${PATHDATA}/inc.writeGlobalConfig.sh fi -. ${PATHDATA}/../settings/global.conf - -############################################################# -# Read configuration file -# create the configuration file from sample - if it does not exist -if [ ! -f ${PATHDATA}/../settings/sync_shared.conf ]; then - echo "sync_shared.conf not present" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Conf not present. Write from sample" >> ${PATHDATA}/../logs/debug.log; fi - cp ${PATHDATA}/../settings/sync_shared.conf.sample ${PATHDATA}/../settings/sync_shared.conf - # change the read/write so that later this might also be editable through the web app - sudo chown -R pi:www-data ${PATHDATA}/../settings/sync_shared.conf - sudo chmod -R 775 ${PATHDATA}/../settings/sync_shared.conf -fi - -. ${PATHDATA}/../settings/sync_shared.conf - +. ${PROJROOTPATH}/settings/global.conf if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> ${PROJROOTPATH}/logs/debug.log; fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> ${PROJROOTPATH}/logs/debug.log; fi + + ############################################################# + # Read configuration file + # create the configuration file from sample - if it does not exist + if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then + echo "sync_shared.conf not present" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Conf not present. Write from sample" >> ${PROJROOTPATH}/logs/debug.log; fi + cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf + # change the read/write so that later this might also be editable through the web app + sudo chown -R pi:www-data ${PROJROOTPATH}/settings/sync_shared.conf + sudo chmod -R 775 ${PROJROOTPATH}/settings/sync_shared.conf + fi + + . ${PROJROOTPATH}/settings/sync_shared.conf + # Set local vars SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}shortcuts/" @@ -70,10 +70,10 @@ else # see following file for details: . ${PATHDATA}/inc.readArgsFromCommandLine.sh - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PATHDATA}/../logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PATHDATA}/../logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi case $COMMAND in @@ -82,29 +82,29 @@ else if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then mkdir "${SYNCSHORTCUTSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi fi if [ -f "${SYNCSHORTCUTSPATH}${CARDID}" ]; then RSYNCSHORTCUTSCMD=$(rsync -azui --no-o --no-g --no-times "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}") if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PATHDATA}/../logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PROJROOTPATH}/logs/debug.log; fi sudo chown pi:www-data "${SHORTCUTSPATH}/${CARDID}" sudo chmod -R 775 "${SHORTCUTSPATH}/${CARDID}" else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi fi ;; audiofolders) @@ -112,35 +112,35 @@ else if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then mkdir "${SYNCAUDIOFOLDERSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi fi if [ -d "${SYNCAUDIOFOLDERSPATH}${FOLDER}" ]; then RSYNCSAUDIOFILES=$(rsync -azui --no-o --no-g --no-perms --no-times --delete --exclude="folder.conf" "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PATHDATA}/../logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PROJROOTPATH}/logs/debug.log; fi sudo chown -R pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" sudo chmod -R 775 "${AUDIOFOLDERSPATH}/${FOLDER}" sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi fi ;; *) echo Unknown COMMAND $COMMAND - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi ;; esac diff --git a/scripts/inc.writeGlobalConfig.sh b/scripts/inc.writeGlobalConfig.sh index 856c54fb4..f15abf850 100755 --- a/scripts/inc.writeGlobalConfig.sh +++ b/scripts/inc.writeGlobalConfig.sh @@ -326,6 +326,17 @@ CMDREWIND=`grep 'CMDREWIND' $PATHDATA/../settings/rfid_trigger_play.conf|tail -1 CMDSEEKFORW=`grep 'CMDSEEKFORW' $PATHDATA/../settings/rfid_trigger_play.conf|tail -1|sed 's/CMDSEEKFORW=//g'|sed 's/"//g'|tr -d "\n"|grep -o '[0-9]*'` CMDSEEKBACK=`grep 'CMDSEEKBACK' $PATHDATA/../settings/rfid_trigger_play.conf|tail -1|sed 's/CMDSEEKBACK=//g'|sed 's/"//g'|tr -d "\n"|grep -o '[0-9]*'` +############################################## +# SYNCSHAREDENABLED +# Activation status of component sync-shared-from-server +# 1. create a default if file does not exist +if [ ! -f $PATHDATA/../settings/Sync_Shared_Enabled ]; then + echo "FALSE" > $PATHDATA/../settings/Sync_Shared_Enabled + chmod 777 $PATHDATA/../settings/Sync_Shared_Enabled +fi +# 2. then|or read value from file +SYNCSHAREDENABLED=`cat $PATHDATA/../settings/Sync_Shared_Enabled` + # AUDIOFOLDERSPATH # PLAYLISTSFOLDERPATH # SWIPEORPLACE @@ -359,6 +370,7 @@ CMDSEEKBACK=`grep 'CMDSEEKBACK' $PATHDATA/../settings/rfid_trigger_play.conf|tai # CMDREWIND # CMDSEEKFORW # CMDSEEKBACK +# SYNCSHAREDENABLED ######################################################### # WRITE CONFIG FILE @@ -394,6 +406,7 @@ echo "CMDPREV=\"${CMDPREV}\"" >> "${PATHDATA}/../settings/global.conf" echo "CMDREWIND=\"${CMDREWIND}\"" >> "${PATHDATA}/../settings/global.conf" echo "CMDSEEKFORW=\"${CMDSEEKFORW}\"" >> "${PATHDATA}/../settings/global.conf" echo "CMDSEEKBACK=\"${CMDSEEKBACK}\"" >> "${PATHDATA}/../settings/global.conf" +echo "SYNCSHAREDENABLED=\"${SYNCSHAREDENABLED}\"" >> "${PATHDATA}/../settings/global.conf" # Work in progress: #echo "MAILWLANIPYN=\"${MAILWLANIPYN}\"" >> "${PATHDATA}/../settings/global.conf" diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 18248665e..c2e84486d 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -312,8 +312,10 @@ if [ "$CARDID" ]; then # Now we expect it to be a trigger for one or more audio file(s). # Let's look at the ID, write a bit of log information and then try to play audio. - # Sync shortcut $CARDID - $PATHDATA/sync_shared.sh -c=shortcuts -i=$CARDID + # If enabled sync shortcut $CARDID + if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=shortcuts -i=$CARDID + fi # Look for human readable shortcut in folder 'shortcuts' # check if CARDID has a text file by the same name - which would contain the human readable folder name @@ -351,8 +353,10 @@ if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "# Type of play \$VA # check if $FOLDER is not empty if [ ! -z "$FOLDER" ]; then - # Sync audio folder $FOLDER - $PATHDATA/sync_shared.sh -c=audiofolders -d=$FOLDER + # If enabled sync audio folder $FOLDER + if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=audiofolders -d=$FOLDER + fi # check if $FOLDER points to existing directory if [ -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then From a7203d304b5dbd843ed236f7afd2a380b532f30d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 9 Feb 2023 01:33:56 +0100 Subject: [PATCH 09/54] Sync Shared Flag angepasst --- .../sync-shared-from-server/sync_shared.sh | 20 +++++++++++++------ scripts/inc.writeGlobalConfig.sh | 13 ------------ scripts/rfid_trigger_play.sh | 8 ++++++++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/sync_shared.sh b/components/synchronisation/sync-shared-from-server/sync_shared.sh index 73b63d1b0..40649534c 100755 --- a/components/synchronisation/sync-shared-from-server/sync_shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync_shared.sh @@ -31,13 +31,13 @@ SHORTCUTSPATH="$PROJROOTPATH/shared/shortcuts" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> ${PROJROOTPATH}/logs/debug.log; fi -############################################################# -# Read global configuration file (and create if not exists) -# create the global configuration file from single files - if it does not exist -if [ ! -f ${PROJROOTPATH}/settings/global.conf ]; then - . ${PATHDATA}/inc.writeGlobalConfig.sh +####################### +# Activation status of component sync-shared-from-server +SYNCSHAREDENABLED="FALSE" +if [ -f ${PROJROOTPATH}/settings/Sync_Shared_Enabled ]; then + SYNCSHAREDENABLED=`cat ${PROJROOTPATH}/settings/Sync_Shared_Enabled` fi -. ${PROJROOTPATH}/settings/global.conf + if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -45,6 +45,14 @@ if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> ${PROJROOTPATH}/logs/debug.log; fi + ############################################################# + # Read global configuration file (and create if not exists) + # create the global configuration file from single files - if it does not exist + if [ ! -f ${PROJROOTPATH}/settings/global.conf ]; then + . ${PATHDATA}/inc.writeGlobalConfig.sh + fi + . ${PROJROOTPATH}/settings/global.conf + ############################################################# # Read configuration file # create the configuration file from sample - if it does not exist diff --git a/scripts/inc.writeGlobalConfig.sh b/scripts/inc.writeGlobalConfig.sh index f15abf850..856c54fb4 100755 --- a/scripts/inc.writeGlobalConfig.sh +++ b/scripts/inc.writeGlobalConfig.sh @@ -326,17 +326,6 @@ CMDREWIND=`grep 'CMDREWIND' $PATHDATA/../settings/rfid_trigger_play.conf|tail -1 CMDSEEKFORW=`grep 'CMDSEEKFORW' $PATHDATA/../settings/rfid_trigger_play.conf|tail -1|sed 's/CMDSEEKFORW=//g'|sed 's/"//g'|tr -d "\n"|grep -o '[0-9]*'` CMDSEEKBACK=`grep 'CMDSEEKBACK' $PATHDATA/../settings/rfid_trigger_play.conf|tail -1|sed 's/CMDSEEKBACK=//g'|sed 's/"//g'|tr -d "\n"|grep -o '[0-9]*'` -############################################## -# SYNCSHAREDENABLED -# Activation status of component sync-shared-from-server -# 1. create a default if file does not exist -if [ ! -f $PATHDATA/../settings/Sync_Shared_Enabled ]; then - echo "FALSE" > $PATHDATA/../settings/Sync_Shared_Enabled - chmod 777 $PATHDATA/../settings/Sync_Shared_Enabled -fi -# 2. then|or read value from file -SYNCSHAREDENABLED=`cat $PATHDATA/../settings/Sync_Shared_Enabled` - # AUDIOFOLDERSPATH # PLAYLISTSFOLDERPATH # SWIPEORPLACE @@ -370,7 +359,6 @@ SYNCSHAREDENABLED=`cat $PATHDATA/../settings/Sync_Shared_Enabled` # CMDREWIND # CMDSEEKFORW # CMDSEEKBACK -# SYNCSHAREDENABLED ######################################################### # WRITE CONFIG FILE @@ -406,7 +394,6 @@ echo "CMDPREV=\"${CMDPREV}\"" >> "${PATHDATA}/../settings/global.conf" echo "CMDREWIND=\"${CMDREWIND}\"" >> "${PATHDATA}/../settings/global.conf" echo "CMDSEEKFORW=\"${CMDSEEKFORW}\"" >> "${PATHDATA}/../settings/global.conf" echo "CMDSEEKBACK=\"${CMDSEEKBACK}\"" >> "${PATHDATA}/../settings/global.conf" -echo "SYNCSHAREDENABLED=\"${SYNCSHAREDENABLED}\"" >> "${PATHDATA}/../settings/global.conf" # Work in progress: #echo "MAILWLANIPYN=\"${MAILWLANIPYN}\"" >> "${PATHDATA}/../settings/global.conf" diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index c2e84486d..f59dd6f28 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -63,6 +63,14 @@ fi # see following file for details: . $PATHDATA/inc.readArgsFromCommandLine.sh +####################### +# Activation status of component sync-shared-from-server +SYNCSHAREDENABLED="FALSE" +if [ -f ${PROJROOTPATH}/settings/Sync_Shared_Enabled ]; then + SYNCSHAREDENABLED=`cat ${PROJROOTPATH}/settings/Sync_Shared_Enabled` +fi +if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Sync: SYNCSHAREDENABLED=$SYNCSHAREDENABLED" >> ${PROJROOTPATH}/logs/debug.log; fi + ################################################################## # Check if we got the card ID or the audio folder from the prompt. # Sloppy error check, because we assume the best. From 6a5e3bb64adcc6c10e2beba0063ab883e72bb176 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 9 Feb 2023 02:34:56 +0100 Subject: [PATCH 10/54] Skripte Pfade und Aufrufe korrigiert --- .../sync-shared-from-server/sync_shared.sh | 5 +++-- scripts/rfid_trigger_play.sh | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/sync_shared.sh b/components/synchronisation/sync-shared-from-server/sync_shared.sh index 40649534c..30fdc4a63 100755 --- a/components/synchronisation/sync-shared-from-server/sync_shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync_shared.sh @@ -49,7 +49,7 @@ else # Read global configuration file (and create if not exists) # create the global configuration file from single files - if it does not exist if [ ! -f ${PROJROOTPATH}/settings/global.conf ]; then - . ${PATHDATA}/inc.writeGlobalConfig.sh + . ${PROJROOTPATH}/scripts/inc.writeGlobalConfig.sh fi . ${PROJROOTPATH}/settings/global.conf @@ -76,7 +76,7 @@ else # Get args from command line (see Usage above) # Read the args passed on by the command line # see following file for details: - . ${PATHDATA}/inc.readArgsFromCommandLine.sh + . ${PROJROOTPATH}/scripts/inc.readArgsFromCommandLine.sh if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -153,3 +153,4 @@ else esac fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ##" >> ${PROJROOTPATH}/logs/debug.log; fi \ No newline at end of file diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index f59dd6f28..f00c1c064 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -66,10 +66,10 @@ fi ####################### # Activation status of component sync-shared-from-server SYNCSHAREDENABLED="FALSE" -if [ -f ${PROJROOTPATH}/settings/Sync_Shared_Enabled ]; then - SYNCSHAREDENABLED=`cat ${PROJROOTPATH}/settings/Sync_Shared_Enabled` +if [ -f $PATHDATA/../settings/Sync_Shared_Enabled ]; then + SYNCSHAREDENABLED=`cat $PATHDATA/../settings/Sync_Shared_Enabled` fi -if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Sync: SYNCSHAREDENABLED=$SYNCSHAREDENABLED" >> ${PROJROOTPATH}/logs/debug.log; fi +if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Sync: SYNCSHAREDENABLED=$SYNCSHAREDENABLED" >> $PATHDATA/../logs/debug.log; fi ################################################################## # Check if we got the card ID or the audio folder from the prompt. @@ -322,7 +322,7 @@ if [ "$CARDID" ]; then # If enabled sync shortcut $CARDID if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=shortcuts -i=$CARDID + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=shortcuts -i="$CARDID" fi # Look for human readable shortcut in folder 'shortcuts' @@ -363,7 +363,7 @@ if [ ! -z "$FOLDER" ]; then # If enabled sync audio folder $FOLDER if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=audiofolders -d=$FOLDER + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=audiofolders -d="$FOLDER" fi # check if $FOLDER points to existing directory From a2dbfd669f3423496c7362fa3c08b6cf46e40f4d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 9 Feb 2023 02:41:40 +0100 Subject: [PATCH 11/54] Skript Name angepasst --- .../{sync_shared.sh => sync-shared.sh} | 0 scripts/rfid_trigger_play.sh | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename components/synchronisation/sync-shared-from-server/{sync_shared.sh => sync-shared.sh} (100%) diff --git a/components/synchronisation/sync-shared-from-server/sync_shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh similarity index 100% rename from components/synchronisation/sync-shared-from-server/sync_shared.sh rename to components/synchronisation/sync-shared-from-server/sync-shared.sh diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index f00c1c064..4509d9dda 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -322,7 +322,7 @@ if [ "$CARDID" ]; then # If enabled sync shortcut $CARDID if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=shortcuts -i="$CARDID" + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=shortcuts -i="$CARDID" fi # Look for human readable shortcut in folder 'shortcuts' @@ -363,7 +363,7 @@ if [ ! -z "$FOLDER" ]; then # If enabled sync audio folder $FOLDER if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync_shared.sh -c=audiofolders -d="$FOLDER" + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=audiofolders -d="$FOLDER" fi # check if $FOLDER points to existing directory From 4abeb47ded7e752d9ad59154e6555abe3f59f6f9 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 9 Feb 2023 03:09:42 +0100 Subject: [PATCH 12/54] Install Skript hinzugefuegt --- .../install-sync-shared.sh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 components/synchronisation/sync-shared-from-server/install-sync-shared.sh diff --git a/components/synchronisation/sync-shared-from-server/install-sync-shared.sh b/components/synchronisation/sync-shared-from-server/install-sync-shared.sh new file mode 100755 index 000000000..fab3f14c3 --- /dev/null +++ b/components/synchronisation/sync-shared-from-server/install-sync-shared.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROJROOTPATH="${PATHDATA}/../../.." + +# Ensure script is executable for everyone +sudo chmod ugo+rx "${PATHDATA}/sync-shared.sh" + +# Make sure required packages are installed +echo -e "\nChecking rsync packages" +sudo apt install rsync -y + +if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then + cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf + # change the read/write so that later this might also be editable through the web app + sudo chown -R pi:www-data ${PROJROOTPATH}/settings/sync_shared.conf + sudo chmod -R ugo+rw ${PROJROOTPATH}/settings/sync_shared.conf +fi + +# Let global controls know this feature is enabled +echo -e "\nLet global controls know this feature is enabled (Sync_Shared_Enabled -> TRUE)" +CONFFILE="${PROJROOTPATH}/settings/Sync_Shared_Enabled" +echo "TRUE" > ${CONFFILE} +chmod ugo+rw ${CONFFILE} + +# Final notes +echo -e "\n\n\nFINAL NOTE:\nPlease check README.md for further configuration" \ No newline at end of file From 8aeafb9a44989123f8efe13b0b051ff73062c9cc Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 9 Feb 2023 03:10:02 +0100 Subject: [PATCH 13/54] ReadMe hinzugefuegt --- components/synchronisation/sync-shared-from-server/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 components/synchronisation/sync-shared-from-server/README.md diff --git a/components/synchronisation/sync-shared-from-server/README.md b/components/synchronisation/sync-shared-from-server/README.md new file mode 100644 index 000000000..07ee931e3 --- /dev/null +++ b/components/synchronisation/sync-shared-from-server/README.md @@ -0,0 +1,3 @@ +## Synchronize shared files from a Server + +tbd \ No newline at end of file From 66ea56c985e5bd6cfcc5763bd3a525bd6c22f7af Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Fri, 10 Feb 2023 23:58:59 +0100 Subject: [PATCH 14/54] New feature 'full sync'. rsync options corrected Added full synchronisation on rfid scan. Changed rsync option to correctly sync files and ignore 'folder.conf' and 'placholder' file --- .../settings/sync_shared.conf.sample | 1 + .../sync-shared-from-server/sync-shared.sh | 129 ++++++++++++++---- scripts/rfid_trigger_play.sh | 6 + settings/rfid_trigger_play.conf.sample | 4 + 4 files changed, 111 insertions(+), 29 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample index 00cfbbbb5..7f0bc87ca 100755 --- a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample @@ -1,3 +1,4 @@ +SYNCSHAREDONRFIDSCAN="TRUE" SYNCSHAREDREMOTESERVER="" SYNCSHAREDREMOTEPORT="" SYNCSHAREDREMOTEPATH="" \ No newline at end of file diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index 30fdc4a63..bc63f5d6a 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -12,11 +12,15 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # # syn audiofolders: # ./sync_shared.sh -c=audiofolders -d=xxx +# +# syn full: +# ./sync_shared.sh -c=full # # # VALID COMMANDS: # shortcuts (with -i) # audiofolders (with -d) +# full # The absolute path to the folder which contains all the scripts. # Unless you are working with symlinks, leave the following line untouched. @@ -57,7 +61,6 @@ else # Read configuration file # create the configuration file from sample - if it does not exist if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then - echo "sync_shared.conf not present" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Conf not present. Write from sample" >> ${PROJROOTPATH}/logs/debug.log; fi cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf # change the read/write so that later this might also be editable through the web app @@ -66,7 +69,7 @@ else fi . ${PROJROOTPATH}/settings/sync_shared.conf - + # Set local vars SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}shortcuts/" @@ -83,63 +86,131 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi - + ############################################################# + # Sync all files for the specific command. + # Some special options are needed as the 'folder.conf' file will be generated on playback. + # Explanation for rsync options: + # "--itemize-changes" print a summary of copied files. Used for determination if files where changed (empty if no syncing performed). Useful for debug.log + # "--safe-links" ignore symlinks that point outside the tree + # "--times" preserve modification times from source. Recommended option to efficiently identify unchanged files + # "--omit-dir-times" ignore modification time on dirs (see --times). Needed to ignore the creation of 'folder.conf' which alters the modification time of dirs + # "--update" ignore newer files on destination. Lower traffic and runtime + # "--delete" delete files that no longer exist in source + # "--prune-empty-dirs" delete empty dirs (incl. subdirs) + # "--filter="-p folder.conf" exclude (option '-') 'folder.conf' file from syncing, especially deletion. Delete anyway if folder will be deleted (option 'p' (perishable)). + # "--exclude="placeholder" exclude 'placeholder' file from syncing, especially deletion case $COMMAND in shortcuts) + if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then + + if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then + mkdir "${SYNCSHORTCUTSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + + elif [ -f "${SYNCSHORTCUTSPATH}${CARDID}" ]; then + RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}/") + + if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PROJROOTPATH}/logs/debug.log; fi + + sudo chown pi:www-data "${SHORTCUTSPATH}/${CARDID}" + sudo chmod 775 "${SHORTCUTSPATH}/${CARDID}" + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + ;; + audiofolders) + if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then + + if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then + mkdir "${SYNCAUDIOFOLDERSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + + elif [ -d "${SYNCAUDIOFOLDERSPATH}${FOLDER}" ]; then + RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-p folder.conf" "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + + if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PROJROOTPATH}/logs/debug.log; fi + + sudo chown -R pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo chmod -R 775 "${AUDIOFOLDERSPATH}/${FOLDER}" + sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + ;; + full) if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then mkdir "${SYNCSHORTCUTSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - if [ -f "${SYNCSHORTCUTSPATH}${CARDID}" ]; then - RSYNCSHORTCUTSCMD=$(rsync -azui --no-o --no-g --no-times "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}") + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi + RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --exclude="placeholder" "${SYNCSHORTCUTSPATH}" "${SHORTCUTSPATH}/") if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PROJROOTPATH}/logs/debug.log; fi - sudo chown pi:www-data "${SHORTCUTSPATH}/${CARDID}" - sudo chmod -R 775 "${SHORTCUTSPATH}/${CARDID}" + sudo chown -R pi:www-data "${SHORTCUTSPATH}" + sudo chmod -R 775 "${SHORTCUTSPATH}" else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi + fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - ;; - audiofolders) - if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then - + if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then mkdir "${SYNCAUDIOFOLDERSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - if [ -d "${SYNCAUDIOFOLDERSPATH}${FOLDER}" ]; then - RSYNCSAUDIOFILES=$(rsync -azui --no-o --no-g --no-perms --no-times --delete --exclude="folder.conf" "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi + RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-p folder.conf" --exclude="placeholder" "${SYNCAUDIOFOLDERSPATH}" "${AUDIOFOLDERSPATH}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PROJROOTPATH}/logs/debug.log; fi - sudo chown -R pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" - sudo chmod -R 775 "${AUDIOFOLDERSPATH}/${FOLDER}" - sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 + sudo chown -R pi:www-data "${AUDIOFOLDERSPATH}" + sudo chmod -R 775 "${AUDIOFOLDERSPATH}" + sudo mpc update --wait "${AUDIOFOLDERSPATH}" > /dev/null 2>&1 else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi fi - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi fi else diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 4509d9dda..61e175377 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -314,6 +314,12 @@ if [ "$CARDID" ]; then $CMDBLUETOOTHTOGGLE) $PATHDATA/playout_controls.sh -c=bluetoothtoggle -v=toggle ;; + $SYNCSHAREDFULL) + # If enabled sync full $CARDID + if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=full + fi + ;; *) # We checked if the card was a special command, seems it wasn't. diff --git a/settings/rfid_trigger_play.conf.sample b/settings/rfid_trigger_play.conf.sample index 9b99fa7a2..907eb9874 100755 --- a/settings/rfid_trigger_play.conf.sample +++ b/settings/rfid_trigger_play.conf.sample @@ -157,3 +157,7 @@ RECORDSTART600="%RECORDSTART600%" RECORDSTOP="%RECORDSTOP%" ### Replay latest recording RECORDPLAYBACKLATEST="%RECORDPLAYBACKLATEST%" + +## Synchronisation +### Synchronise all shared files +SYNCSHAREDFULL=%SYNCSHAREDFULL% \ No newline at end of file From a59b8f00a2c2a411d642425275da3d2130a7b7b3 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 11 Feb 2023 00:23:50 +0100 Subject: [PATCH 15/54] Added DEBUG_sync_shared_sh to WebUi --- htdocs/inc.header.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/inc.header.php b/htdocs/inc.header.php index 2b101cf69..858e17aac 100755 --- a/htdocs/inc.header.php +++ b/htdocs/inc.header.php @@ -75,6 +75,7 @@ "DEBUG_rfid_trigger_play_sh", "DEBUG_shuffle_play_sh", "DEBUG_single_play_sh", +"DEBUG_sync_shared_sh", ); $debugOptions = array("TRUE", "FALSE"); From 54c8975020634c6ce142fc739788d462b4b4e03d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 11 Feb 2023 01:36:05 +0100 Subject: [PATCH 16/54] Added new Feature Command for changing acticvation of 'cync on rfid scan' --- .../sync-shared-from-server/sync-shared.sh | 48 +++++++++++++++++-- scripts/rfid_trigger_play.sh | 6 +++ settings/rfid_trigger_play.conf.sample | 4 +- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index bc63f5d6a..510a88f3e 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -7,20 +7,25 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # USAGE EXAMPLES: # -# syn shortcuts: +# sync shortcuts: # ./sync_shared.sh -c=shortcuts -i=xxx # -# syn audiofolders: +# sync audiofolders: # ./sync_shared.sh -c=audiofolders -d=xxx # -# syn full: +# sync full: # ./sync_shared.sh -c=full +# +# sync toggle SyncOnRfidScan: +# ./sync_shared.sh -c=onRfidScan -v=toggle + # # # VALID COMMANDS: # shortcuts (with -i) # audiofolders (with -d) # full +# onRfidScan (with -v=on | off | toogle) # The absolute path to the folder which contains all the scripts. # Unless you are working with symlinks, leave the following line untouched. @@ -49,6 +54,17 @@ if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> ${PROJROOTPATH}/logs/debug.log; fi + ############################################################# + # Functions + function set_setting_syncsharedonrfidscan { + local OLD="$1" + local NEW="$2" + + sed -i "s/SYNCSHAREDONRFIDSCAN=\"$OLD\"/SYNCSHAREDONRFIDSCAN=\"$NEW\"/g" ${PROJROOTPATH}/settings/sync_shared.conf + } + ############################################################# + + ############################################################# # Read global configuration file (and create if not exists) # create the global configuration file from single files - if it does not exist @@ -217,6 +233,32 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi fi ;; + onRfidScan) + case $VALUE in + on) + SYNCSHAREDONRFIDSCAN_NEW="TRUE" + ;; + off) + SYNCSHAREDONRFIDSCAN_NEW="FALSE" + ;; + toggle) + if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + SYNCSHAREDONRFIDSCAN_NEW="FALSE" + else + SYNCSHAREDONRFIDSCAN_NEW="TRUE" + fi + ;; + *) + echo "Unknown VALUE $VALUE for COMMAND $COMMAND" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE $VALUE for COMMAND $COMMAND" >> ${PROJROOTPATH}/logs/debug.log; fi + ;; + esac + + if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $VALUE" >> ${PROJROOTPATH}/logs/debug.log; fi + set_setting_syncsharedonrfidscan $SYNCSHAREDONRFIDSCAN $SYNCSHAREDONRFIDSCAN_NEW + fi + ;; *) echo Unknown COMMAND $COMMAND if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 61e175377..7c9366994 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -320,6 +320,12 @@ if [ "$CARDID" ]; then $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=full fi ;; + $SYNCSHAREDONRFIDSCANTOGGLE) + # If enabled sync full $CARDID + if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=onRfidScan -v=toggle + fi + ;; *) # We checked if the card was a special command, seems it wasn't. diff --git a/settings/rfid_trigger_play.conf.sample b/settings/rfid_trigger_play.conf.sample index 907eb9874..d60ac7ee0 100755 --- a/settings/rfid_trigger_play.conf.sample +++ b/settings/rfid_trigger_play.conf.sample @@ -160,4 +160,6 @@ RECORDPLAYBACKLATEST="%RECORDPLAYBACKLATEST%" ## Synchronisation ### Synchronise all shared files -SYNCSHAREDFULL=%SYNCSHAREDFULL% \ No newline at end of file +SYNCSHAREDFULL=%SYNCSHAREDFULL% +### Toogle activation of 'sync on RFID scan' +SYNCSHAREDONRFIDSCANTOGGLE=%SYNCSHAREDONRFIDSCANTOGGLE% \ No newline at end of file From 2984e70e3dda5706653acf8f5e47c20424157341 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 11 Feb 2023 01:37:37 +0100 Subject: [PATCH 17/54] corrected description of new Command --- settings/rfid_trigger_play.conf.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/rfid_trigger_play.conf.sample b/settings/rfid_trigger_play.conf.sample index d60ac7ee0..756aabed0 100755 --- a/settings/rfid_trigger_play.conf.sample +++ b/settings/rfid_trigger_play.conf.sample @@ -161,5 +161,5 @@ RECORDPLAYBACKLATEST="%RECORDPLAYBACKLATEST%" ## Synchronisation ### Synchronise all shared files SYNCSHAREDFULL=%SYNCSHAREDFULL% -### Toogle activation of 'sync on RFID scan' +### Toggle activation of 'sync on RFID scan' SYNCSHAREDONRFIDSCANTOGGLE=%SYNCSHAREDONRFIDSCANTOGGLE% \ No newline at end of file From d11f81be5c9fd8362a0f4dcc1a72bbcad6e8b562 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 11 Feb 2023 01:47:32 +0100 Subject: [PATCH 18/54] Timeout for server check added to settings --- .../settings/sync_shared.conf.sample | 3 ++- .../synchronisation/sync-shared-from-server/sync-shared.sh | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample index 7f0bc87ca..9acb3724c 100755 --- a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample @@ -1,4 +1,5 @@ SYNCSHAREDONRFIDSCAN="TRUE" SYNCSHAREDREMOTESERVER="" SYNCSHAREDREMOTEPORT="" -SYNCSHAREDREMOTEPATH="" \ No newline at end of file +SYNCSHAREDREMOTEPATH="" +SYNCSHAREDREMOTETIMOUT="1" \ No newline at end of file diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index 510a88f3e..da30d91e3 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -118,7 +118,7 @@ else case $COMMAND in shortcuts) if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then - if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then + if nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT ; then if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then mkdir "${SYNCSHORTCUTSPATH}" @@ -152,7 +152,7 @@ else ;; audiofolders) if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then - if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then + if nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT ; then if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then mkdir "${SYNCAUDIOFOLDERSPATH}" @@ -186,7 +186,7 @@ else fi ;; full) - if nc -z $SYNCSHAREDREMOTESERVER -w 1 $SYNCSHAREDREMOTEPORT ; then + if nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT ; then if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then mkdir "${SYNCSHORTCUTSPATH}" From 40b9882c64d66e30c40a671c7ea40be43e7a6f80 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 16 Feb 2023 01:49:50 +0100 Subject: [PATCH 19/54] Added script for configuration. Improved installation --- .../change_configuration.sh | 119 ++++++++++++++++++ .../install-sync-shared.sh | 29 +++-- 2 files changed, 133 insertions(+), 15 deletions(-) create mode 100755 components/synchronisation/sync-shared-from-server/change_configuration.sh diff --git a/components/synchronisation/sync-shared-from-server/change_configuration.sh b/components/synchronisation/sync-shared-from-server/change_configuration.sh new file mode 100755 index 000000000..ec293ba9b --- /dev/null +++ b/components/synchronisation/sync-shared-from-server/change_configuration.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROJROOTPATH="${PATHDATA}/../../.." +CONFFILE="${PROJROOTPATH}/settings/Sync_Shared_Enabled" +SKIP_INITIAL_CHECK="$1" + + +############################################################# +# Functions + +function set_activation { + local SETTINGVALUE="$1" + + local SETTINGSTATE="activated" + if [ "$SETTINGVALUE" != "TRUE" ]; then + SETTINGSTATE="deactivated" + fi + + # Let global controls know this feature is enabled + echo -e "\nLet global controls know this feature is $SETTINGSTATE. (Sync_Shared_Enabled -> $SETTINGVALUE)" + + echo "$SETTINGVALUE" > ${CONFFILE} + chmod ugo+rw ${CONFFILE} +} + +function init_settings { + # Init config from sample if not present + if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then + cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf + # change the read/write so that later this might also be editable through the web app + sudo chown -R pi:www-data ${PROJROOTPATH}/settings/sync_shared.conf + sudo chmod -R ugo+rw ${PROJROOTPATH}/settings/sync_shared.conf + fi + . ${PROJROOTPATH}/settings/sync_shared.conf +} + +function set_setting { + local SETTINGNAME="$1" + local SETTINGVALUE="$2" + + if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then + sed -i "s;^$SETTINGNAME=.*;$SETTINGNAME=\"$SETTINGVALUE\";" ${PROJROOTPATH}/settings/sync_shared.conf + echo "New value: \"$SETTINGVALUE\"" + fi +} + +function read_setting { + local SETTINGNAME="$1" + local TEXT="$2" + local SKIP_LEAVE_BLANK="$3" + + local READ_PROMPT=$'\n'"$TEXT" + if [ -z "$SKIP_LEAVE_BLANK" ]; then + READ_PROMPT="$READ_PROMPT Leave blank for no change." + fi + READ_PROMPT="$READ_PROMPT"$'\n'"Current value = \"$SETTINGNAME\""$'\n' + + read -rp "$READ_PROMPT" response +} + +function read_all_settings { + read_setting "$SYNCSHAREDREMOTESERVER" "Please enter your servers adresse (IP/Hostname)." + set_setting "SYNCSHAREDREMOTESERVER" "$response" + + read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." + set_setting "SYNCSHAREDREMOTEPORT" "$response" + + read_setting "$SYNCSHAREDREMOTEPATH" "Please enter your servers folder name or path." + set_setting "SYNCSHAREDREMOTEPATH" "$response" + + read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." + set_setting "SYNCSHAREDREMOTETIMOUT" "$response" + + read_setting "$SYNCSHAREDONRFIDSCAN" "Do you want to activate the syncronisation on RFID scan (y/N)." + case "$response" in + [yY][eE][sS]|[yY]) + response="TRUE" + ;; + [nN][oO]|[nN]) + response="FALSE" + ;; + *) + ;; + esac + set_setting "SYNCSHAREDONRFIDSCAN" "$response" +} + +############################################################# + +# If intial check is skipped, asume the component shall be activated +if [ -z "$SKIP_INITIAL_CHECK" ]; then + read -rp "Do you want to activate the sync-shared component? [Y/n] " response +else + response="yes" +fi + +case "$response" in + [nN][oO]|[nN]) + set_activation "FALSE" + ;; + *) + set_activation "TRUE" + + # Ensure start was intended + read -rp "Do you want to change the configuration? [Y/n] " response + case "$response" in + [nN][oO]|[nN]) + exit + ;; + *) + ;; + esac + init_settings + read_all_settings + ;; +esac + +echo -e "\nConfiguration finished" \ No newline at end of file diff --git a/components/synchronisation/sync-shared-from-server/install-sync-shared.sh b/components/synchronisation/sync-shared-from-server/install-sync-shared.sh index fab3f14c3..e19049587 100755 --- a/components/synchronisation/sync-shared-from-server/install-sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/install-sync-shared.sh @@ -1,5 +1,16 @@ #!/bin/bash +# Ensure start was intended +read -rp "Start installation? [Y/n] " response +case "$response" in + [nN][oO]|[nN]) + echo "Installation aborted..." + exit + ;; + *) + ;; +esac + PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJROOTPATH="${PATHDATA}/../../.." @@ -7,21 +18,9 @@ PROJROOTPATH="${PATHDATA}/../../.." sudo chmod ugo+rx "${PATHDATA}/sync-shared.sh" # Make sure required packages are installed -echo -e "\nChecking rsync packages" +echo -e "\nChecking rsync package" sudo apt install rsync -y -if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then - cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf - # change the read/write so that later this might also be editable through the web app - sudo chown -R pi:www-data ${PROJROOTPATH}/settings/sync_shared.conf - sudo chmod -R ugo+rw ${PROJROOTPATH}/settings/sync_shared.conf -fi - -# Let global controls know this feature is enabled -echo -e "\nLet global controls know this feature is enabled (Sync_Shared_Enabled -> TRUE)" -CONFFILE="${PROJROOTPATH}/settings/Sync_Shared_Enabled" -echo "TRUE" > ${CONFFILE} -chmod ugo+rw ${CONFFILE} +"${PATHDATA}"/change_configuration.sh "SkipInitialCheck" -# Final notes -echo -e "\n\n\nFINAL NOTE:\nPlease check README.md for further configuration" \ No newline at end of file +echo -e "\n\nFINAL NOTE:\nPlease check README.md for further configuration" From a8dd815dbf75850b7a890471e1b2221205735fc3 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 16 Feb 2023 02:44:04 +0100 Subject: [PATCH 20/54] Adjusted sync rules for folder.conf Sync folder.conf from server, but dont delete it if only present on phoniebox (except folder will be deleted) --- .../synchronisation/sync-shared-from-server/sync-shared.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index da30d91e3..a23018656 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -113,7 +113,7 @@ else # "--update" ignore newer files on destination. Lower traffic and runtime # "--delete" delete files that no longer exist in source # "--prune-empty-dirs" delete empty dirs (incl. subdirs) - # "--filter="-p folder.conf" exclude (option '-') 'folder.conf' file from syncing, especially deletion. Delete anyway if folder will be deleted (option 'p' (perishable)). + # "--filter="-rp folder.conf" exclude (option '-') 'folder.conf' file from deletion on receiving side (option 'r'). Delete anyway if folder will be deleted (option 'p' (perishable)). # "--exclude="placeholder" exclude 'placeholder' file from syncing, especially deletion case $COMMAND in shortcuts) @@ -159,7 +159,7 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi elif [ -d "${SYNCAUDIOFOLDERSPATH}${FOLDER}" ]; then - RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-p folder.conf" "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -213,7 +213,7 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi - RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-p folder.conf" --exclude="placeholder" "${SYNCAUDIOFOLDERSPATH}" "${AUDIOFOLDERSPATH}/") + RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" --exclude="placeholder" "${SYNCAUDIOFOLDERSPATH}" "${AUDIOFOLDERSPATH}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi From 546ba5760ebaa52b23dbc48782fa1ba8d54701b2 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 16 Feb 2023 03:17:35 +0100 Subject: [PATCH 21/54] Added Readme --- .../sync-shared-from-server/README.md | 54 ++++++++++++++++++- .../change_configuration.sh | 2 +- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/README.md b/components/synchronisation/sync-shared-from-server/README.md index 07ee931e3..bd45870c0 100644 --- a/components/synchronisation/sync-shared-from-server/README.md +++ b/components/synchronisation/sync-shared-from-server/README.md @@ -1,3 +1,53 @@ -## Synchronize shared files from a Server +# Synchronize shared files from a Server -tbd \ No newline at end of file +This component activates a synchronisation from a server to the Phoniebox for the shared folders 'shortcuts' and 'audiofolders'. +This can be done with a full-sync as a special RFID command and optionally on every RFID scan for the particular CardID. + +For the full-sync bind a CardId to the command "SYNCSHAREDFULL". +For the "RFID scan sync" feature activate the option in the configuration. There is also a command to toggle the activation the RFID scan sync feature via CardId (bind to "SYNCSHAREDONRFIDSCANTOGGLE"). + +## Snynchronisation + +The synchronisation will be only FROM the server TO the Phoniebox, overriding existing files and settings. So configuration of audiofiles / -folders and CardIds made via WebUi will be lost after sync. +If you want to make the initial setup via WebUi copy the files and use it as a base for the server. +The "folder.conf" files will be synced if present on the server, but not delete if not (they are automatically generated on playback). + +If the feature "RFID scan sync" is activated, there will be a check on every RFID scan against the server if a matching shortcut and audiofolder is found and the changes will be transfered (and overriden on the Phoniebox). +If the server is not reachable the check will be aborted after the timeout. So an unreachable server will cause a delay (see command "SYNCSHAREDONRFIDSCANTOGGLE" to toggle activation state). +Further will the playback be delayed for the time the data are transfered (see "SYNCSHAREDFULL" to use a full-sync if a lot of new files have been added). + + +## Installation + +Run the 'install-sync-shared.sh' script. This will install all required packages and rights. +Please configure all settings according to your setup. + + +## Configuration + +If your configuration has changed, run the script 'change_configuration.sh' to update the settings. This lets you also deactivate this feature. +You may also change the settings in "INSTALLATION_ROOT/settings/sync_shared.conf" direclty. + +###Settings: + +**INSTALLATION_ROOT/settings/Sync_Shared_Enabled** + +Hold the activation state of this feature. Values are "TRUE" or "FALSE" + + +**INSTALLATION_ROOT/settings/sync_shared.conf** + +SYNCSHAREDONRFIDSCAN +If the optional feature "RFID scan sync" is activated. Values are "TRUE" or "FALSE" + +SYNCSHAREDREMOTESERVER +The IP or hostname of the server (used to check connectivity). e.g. "192.168.0.2" or "myhomeserver.local" + +SYNCSHAREDREMOTEPORT="22322" +The port of the server (used to check connectivity). e.g. "22" or "80" + +SYNCSHAREDREMOTEPATH="/mnt/station-phoniebox/" +The path on the server to sync. + +SYNCSHAREDREMOTETIMOUT="1" +The timeout to reach the server (in seconds) (used to check connectivity). e.g. 1 \ No newline at end of file diff --git a/components/synchronisation/sync-shared-from-server/change_configuration.sh b/components/synchronisation/sync-shared-from-server/change_configuration.sh index ec293ba9b..1bcccaa05 100755 --- a/components/synchronisation/sync-shared-from-server/change_configuration.sh +++ b/components/synchronisation/sync-shared-from-server/change_configuration.sh @@ -66,7 +66,7 @@ function read_all_settings { read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." set_setting "SYNCSHAREDREMOTEPORT" "$response" - read_setting "$SYNCSHAREDREMOTEPATH" "Please enter your servers folder name or path." + read_setting "$SYNCSHAREDREMOTEPATH" "Please enter your servers path." set_setting "SYNCSHAREDREMOTEPATH" "$response" read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." From 81aed4c3ee6abed11c2567242ef7e26989e6ab8d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 16 Feb 2023 03:23:49 +0100 Subject: [PATCH 22/54] Readme adjusted --- components/synchronisation/sync-shared-from-server/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/README.md b/components/synchronisation/sync-shared-from-server/README.md index bd45870c0..77ec3d5ba 100644 --- a/components/synchronisation/sync-shared-from-server/README.md +++ b/components/synchronisation/sync-shared-from-server/README.md @@ -26,9 +26,9 @@ Please configure all settings according to your setup. ## Configuration If your configuration has changed, run the script 'change_configuration.sh' to update the settings. This lets you also deactivate this feature. -You may also change the settings in "INSTALLATION_ROOT/settings/sync_shared.conf" direclty. +You may also change the settings in the according files directly. -###Settings: +### Settings: **INSTALLATION_ROOT/settings/Sync_Shared_Enabled** From 0c7b7902e176298db28bb449424e9e3532e87b9b Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 16 Feb 2023 03:30:22 +0100 Subject: [PATCH 23/54] Readme adjusted --- .../sync-shared-from-server/README.md | 16 ++++++---------- .../change_configuration.sh | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/README.md b/components/synchronisation/sync-shared-from-server/README.md index 77ec3d5ba..8df946951 100644 --- a/components/synchronisation/sync-shared-from-server/README.md +++ b/components/synchronisation/sync-shared-from-server/README.md @@ -16,6 +16,7 @@ If the feature "RFID scan sync" is activated, there will be a check on every RFI If the server is not reachable the check will be aborted after the timeout. So an unreachable server will cause a delay (see command "SYNCSHAREDONRFIDSCANTOGGLE" to toggle activation state). Further will the playback be delayed for the time the data are transfered (see "SYNCSHAREDFULL" to use a full-sync if a lot of new files have been added). +Currently only synchronisation via a mounted share ist supported. ## Installation @@ -37,17 +38,12 @@ Hold the activation state of this feature. Values are "TRUE" or "FALSE" **INSTALLATION_ROOT/settings/sync_shared.conf** -SYNCSHAREDONRFIDSCAN -If the optional feature "RFID scan sync" is activated. Values are "TRUE" or "FALSE" +SYNCSHAREDONRFIDSCAN: If the optional feature "RFID scan sync" is activated. Values are "TRUE" or "FALSE" -SYNCSHAREDREMOTESERVER -The IP or hostname of the server (used to check connectivity). e.g. "192.168.0.2" or "myhomeserver.local" +SYNCSHAREDREMOTESERVER: The IP or hostname of the server (used to check connectivity). e.g. "192.168.0.2" or "myhomeserver.local" -SYNCSHAREDREMOTEPORT="22322" -The port of the server (used to check connectivity). e.g. "22" or "80" +SYNCSHAREDREMOTEPORT: The port of the server (used to check connectivity). e.g. "80" or "22" -SYNCSHAREDREMOTEPATH="/mnt/station-phoniebox/" -The path on the server to sync. +SYNCSHAREDREMOTEPATH: The path to the shared files to sync. e.g. "/mnt/Phoniebox" -SYNCSHAREDREMOTETIMOUT="1" -The timeout to reach the server (in seconds) (used to check connectivity). e.g. 1 \ No newline at end of file +SYNCSHAREDREMOTETIMOUT: The timeout to reach the server (in seconds) (used to check connectivity). e.g. 1 \ No newline at end of file diff --git a/components/synchronisation/sync-shared-from-server/change_configuration.sh b/components/synchronisation/sync-shared-from-server/change_configuration.sh index 1bcccaa05..17d7226f6 100755 --- a/components/synchronisation/sync-shared-from-server/change_configuration.sh +++ b/components/synchronisation/sync-shared-from-server/change_configuration.sh @@ -66,7 +66,7 @@ function read_all_settings { read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." set_setting "SYNCSHAREDREMOTEPORT" "$response" - read_setting "$SYNCSHAREDREMOTEPATH" "Please enter your servers path." + read_setting "$SYNCSHAREDREMOTEPATH" "Please enter the path to the shared files to sync." set_setting "SYNCSHAREDREMOTEPATH" "$response" read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." From fc29a712eab0f1c65f7e9fbec0e21328feae8cfc Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:13:25 +0100 Subject: [PATCH 24/54] refactored sync script. --- .../sync-shared-from-server/sync-shared.sh | 104 +++++++++--------- scripts/rfid_trigger_play.sh | 6 +- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index a23018656..1511598cf 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -17,7 +17,7 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # ./sync_shared.sh -c=full # # sync toggle SyncOnRfidScan: -# ./sync_shared.sh -c=onRfidScan -v=toggle +# ./sync_shared.sh -c=changeOnRfidScan -v=toggle # # @@ -25,7 +25,7 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # shortcuts (with -i) # audiofolders (with -d) # full -# onRfidScan (with -v=on | off | toogle) +# changeOnRfidScan(with -v=on | off | toogle) # The absolute path to the folder which contains all the scripts. # Unless you are working with symlinks, leave the following line untouched. @@ -53,55 +53,74 @@ if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> ${PROJROOTPATH}/logs/debug.log; fi - - ############################################################# - # Functions - function set_setting_syncsharedonrfidscan { - local OLD="$1" - local NEW="$2" - - sed -i "s/SYNCSHAREDONRFIDSCAN=\"$OLD\"/SYNCSHAREDONRFIDSCAN=\"$NEW\"/g" ${PROJROOTPATH}/settings/sync_shared.conf - } - ############################################################# - - + ############################################################# # Read global configuration file (and create if not exists) - # create the global configuration file from single files - if it does not exist if [ ! -f ${PROJROOTPATH}/settings/global.conf ]; then - . ${PROJROOTPATH}/scripts/inc.writeGlobalConfig.sh + echo "Global settingsfile does not exist. Please call the script from an defined entrypoint" + exit fi . ${PROJROOTPATH}/settings/global.conf ############################################################# # Read configuration file - # create the configuration file from sample - if it does not exist if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Conf not present. Write from sample" >> ${PROJROOTPATH}/logs/debug.log; fi - cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf - # change the read/write so that later this might also be editable through the web app - sudo chown -R pi:www-data ${PROJROOTPATH}/settings/sync_shared.conf - sudo chmod -R 775 ${PROJROOTPATH}/settings/sync_shared.conf + echo "Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" + exit fi - . ${PROJROOTPATH}/settings/sync_shared.conf - - # Set local vars - SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}shortcuts/" - SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}audiofolders/" - ############################################################# # Get args from command line (see Usage above) # Read the args passed on by the command line # see following file for details: . ${PROJROOTPATH}/scripts/inc.readArgsFromCommandLine.sh - + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi + + ############################################################# + # Set local vars after sync_shared.conf is read + SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}shortcuts/" + SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}audiofolders/" + + + ############################################################# + ############################################################# + # Functions + function handle_changeOnRfidScan { + case $VALUE in + on) + SYNCSHAREDONRFIDSCAN_NEW="TRUE" + ;; + off) + SYNCSHAREDONRFIDSCAN_NEW="FALSE" + ;; + toggle) + if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + SYNCSHAREDONRFIDSCAN_NEW="FALSE" + else + SYNCSHAREDONRFIDSCAN_NEW="TRUE" + fi + ;; + *) + echo "Unknown VALUE $VALUE for COMMAND $COMMAND" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE $VALUE for COMMAND $COMMAND" >> ${PROJROOTPATH}/logs/debug.log; fi + ;; + esac + if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $VALUE" >> ${PROJROOTPATH}/logs/debug.log; fi + sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"$SYNCSHAREDONRFIDSCAN_NEW\"|g" ${PROJROOTPATH}/settings/sync_shared.conf + fi + + } + + ############################################################# + ############################################################# + ############################################################# # Sync all files for the specific command. # Some special options are needed as the 'folder.conf' file will be generated on playback. @@ -233,31 +252,8 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi fi ;; - onRfidScan) - case $VALUE in - on) - SYNCSHAREDONRFIDSCAN_NEW="TRUE" - ;; - off) - SYNCSHAREDONRFIDSCAN_NEW="FALSE" - ;; - toggle) - if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then - SYNCSHAREDONRFIDSCAN_NEW="FALSE" - else - SYNCSHAREDONRFIDSCAN_NEW="TRUE" - fi - ;; - *) - echo "Unknown VALUE $VALUE for COMMAND $COMMAND" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE $VALUE for COMMAND $COMMAND" >> ${PROJROOTPATH}/logs/debug.log; fi - ;; - esac - - if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $VALUE" >> ${PROJROOTPATH}/logs/debug.log; fi - set_setting_syncsharedonrfidscan $SYNCSHAREDONRFIDSCAN $SYNCSHAREDONRFIDSCAN_NEW - fi + changeOnRfidScan) + handle_changeOnRfidScan ;; *) echo Unknown COMMAND $COMMAND diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 7c9366994..3649f8b49 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -315,15 +315,15 @@ if [ "$CARDID" ]; then $PATHDATA/playout_controls.sh -c=bluetoothtoggle -v=toggle ;; $SYNCSHAREDFULL) - # If enabled sync full $CARDID + # If enabled sync full if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=full fi ;; $SYNCSHAREDONRFIDSCANTOGGLE) - # If enabled sync full $CARDID + # If enabled change sync setting if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=onRfidScan -v=toggle + $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=changeOnRfidScan -v=toggle fi ;; *) From d32e65df73913c38427c26dd3b7a89348a91533b Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:14:04 +0100 Subject: [PATCH 25/54] changed definition of owner and rights in setup conf --- .../sync-shared-from-server/change_configuration.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/change_configuration.sh b/components/synchronisation/sync-shared-from-server/change_configuration.sh index 17d7226f6..0e27a55f7 100755 --- a/components/synchronisation/sync-shared-from-server/change_configuration.sh +++ b/components/synchronisation/sync-shared-from-server/change_configuration.sh @@ -21,7 +21,8 @@ function set_activation { echo -e "\nLet global controls know this feature is $SETTINGSTATE. (Sync_Shared_Enabled -> $SETTINGVALUE)" echo "$SETTINGVALUE" > ${CONFFILE} - chmod ugo+rw ${CONFFILE} + sudo chgrp www-data ${CONFFILE} + sudo chmod 775 ${CONFFILE} } function init_settings { @@ -29,8 +30,8 @@ function init_settings { if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf # change the read/write so that later this might also be editable through the web app - sudo chown -R pi:www-data ${PROJROOTPATH}/settings/sync_shared.conf - sudo chmod -R ugo+rw ${PROJROOTPATH}/settings/sync_shared.conf + sudo chgrp www-data ${PROJROOTPATH}/settings/sync_shared.conf + sudo chmod 775 ${PROJROOTPATH}/settings/sync_shared.conf fi . ${PROJROOTPATH}/settings/sync_shared.conf } @@ -40,7 +41,7 @@ function set_setting { local SETTINGVALUE="$2" if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then - sed -i "s;^$SETTINGNAME=.*;$SETTINGNAME=\"$SETTINGVALUE\";" ${PROJROOTPATH}/settings/sync_shared.conf + sed -i "s|^$SETTINGNAME=.*|$SETTINGNAME=\"$SETTINGVALUE\"|g" ${PROJROOTPATH}/settings/sync_shared.conf echo "New value: \"$SETTINGVALUE\"" fi } From c6419940fc918a49fc785a6de3f094c5ad5c9f2c Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:40:20 +0100 Subject: [PATCH 26/54] refactored sync script added function for changing access of files/folder changed definition of SYNC*PATH variables --- .../sync-shared-from-server/sync-shared.sh | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index 1511598cf..9ba801a3d 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -83,8 +83,8 @@ else ############################################################# # Set local vars after sync_shared.conf is read - SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}shortcuts/" - SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}audiofolders/" + SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}/shortcuts" + SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}/audiofolders" ############################################################# @@ -115,7 +115,15 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $VALUE" >> ${PROJROOTPATH}/logs/debug.log; fi sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"$SYNCSHAREDONRFIDSCAN_NEW\"|g" ${PROJROOTPATH}/settings/sync_shared.conf fi + } + + function change_access { + local file_or_dir="$1" + local group="$2" + local mod="$3" + sudo chgrp -R "${group}" "${file_or_dir}" + sudo chmod -R "${mod}" "${file_or_dir}" } ############################################################# @@ -143,15 +151,14 @@ else mkdir "${SYNCSHORTCUTSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - elif [ -f "${SYNCSHORTCUTSPATH}${CARDID}" ]; then - RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times "${SYNCSHORTCUTSPATH}${CARDID}" "${SHORTCUTSPATH}/") + elif [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ]; then + RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times "${SYNCSHORTCUTSPATH}/${CARDID}" "${SHORTCUTSPATH}/") if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PROJROOTPATH}/logs/debug.log; fi - sudo chown pi:www-data "${SHORTCUTSPATH}/${CARDID}" - sudo chmod 775 "${SHORTCUTSPATH}/${CARDID}" + change_access "${SHORTCUTSPATH}/${CARDID}" "www-data" "775" else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -177,15 +184,14 @@ else mkdir "${SYNCAUDIOFOLDERSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - elif [ -d "${SYNCAUDIOFOLDERSPATH}${FOLDER}" ]; then - RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" "${SYNCAUDIOFOLDERSPATH}${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") + elif [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ]; then + RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PROJROOTPATH}/logs/debug.log; fi - sudo chown -R pi:www-data "${AUDIOFOLDERSPATH}/${FOLDER}" - sudo chmod -R 775 "${AUDIOFOLDERSPATH}/${FOLDER}" + change_access "${AUDIOFOLDERSPATH}/${FOLDER}" "www-data" "775" sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 else @@ -212,14 +218,13 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi - RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --exclude="placeholder" "${SYNCSHORTCUTSPATH}" "${SHORTCUTSPATH}/") + RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --exclude="placeholder" "${SYNCSHORTCUTSPATH}/" "${SHORTCUTSPATH}/") if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PROJROOTPATH}/logs/debug.log; fi - sudo chown -R pi:www-data "${SHORTCUTSPATH}" - sudo chmod -R 775 "${SHORTCUTSPATH}" + change_access "${SHORTCUTSPATH}" "www-data" "775" else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -232,14 +237,13 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi - RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" --exclude="placeholder" "${SYNCAUDIOFOLDERSPATH}" "${AUDIOFOLDERSPATH}/") + RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" --exclude="placeholder" "${SYNCAUDIOFOLDERSPATH}/" "${AUDIOFOLDERSPATH}/") if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PROJROOTPATH}/logs/debug.log; fi - sudo chown -R pi:www-data "${AUDIOFOLDERSPATH}" - sudo chmod -R 775 "${AUDIOFOLDERSPATH}" + change_access "${AUDIOFOLDERSPATH}" "www-data" "775" sudo mpc update --wait "${AUDIOFOLDERSPATH}" > /dev/null 2>&1 else From f9aacba6d11c98a92d2ff5aa4180e7b46ec5ce77 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 19 Feb 2023 03:57:08 +0100 Subject: [PATCH 27/54] refactoring and path handling Make sure the path variables are alike and dont have a trailing slash moved command handling to funtions moved rsync to single function moved server check to funtion --- .../change_configuration.sh | 7 +- .../sync-shared-from-server/sync-shared.sh | 254 +++++++++--------- 2 files changed, 135 insertions(+), 126 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/change_configuration.sh b/components/synchronisation/sync-shared-from-server/change_configuration.sh index 0e27a55f7..7ea7cc0d0 100755 --- a/components/synchronisation/sync-shared-from-server/change_configuration.sh +++ b/components/synchronisation/sync-shared-from-server/change_configuration.sh @@ -67,8 +67,9 @@ function read_all_settings { read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." set_setting "SYNCSHAREDREMOTEPORT" "$response" - read_setting "$SYNCSHAREDREMOTEPATH" "Please enter the path to the shared files to sync." - set_setting "SYNCSHAREDREMOTEPATH" "$response" + read_setting "$SYNCSHAREDREMOTEPATH" "Please enter the path to the shared files to sync (without trailing slash)." + # Make sure paths dont have a trailing slash ({VAR%/}) + set_setting "SYNCSHAREDREMOTEPATH" "${response%/}" read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." set_setting "SYNCSHAREDREMOTETIMOUT" "$response" @@ -117,4 +118,4 @@ case "$response" in ;; esac -echo -e "\nConfiguration finished" \ No newline at end of file +echo -e "\nConfiguration finished" diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index 9ba801a3d..fdeafe92b 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -31,7 +31,6 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # Unless you are working with symlinks, leave the following line untouched. PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJROOTPATH="$PATHDATA/../../.." -SHORTCUTSPATH="$PROJROOTPATH/shared/shortcuts" ############################################################# # $DEBUG TRUE|FALSE @@ -57,7 +56,8 @@ else ############################################################# # Read global configuration file (and create if not exists) if [ ! -f ${PROJROOTPATH}/settings/global.conf ]; then - echo "Global settingsfile does not exist. Please call the script from an defined entrypoint" + echo "Global settingsfile does not exist. Please call the script from a defined entrypoint" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Global settingsfile does not exist. Please call the script from a defined entrypoint" >> ${PROJROOTPATH}/logs/debug.log; fi exit fi . ${PROJROOTPATH}/settings/global.conf @@ -66,6 +66,7 @@ else # Read configuration file if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then echo "Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" >> ${PROJROOTPATH}/logs/debug.log; fi exit fi . ${PROJROOTPATH}/settings/sync_shared.conf @@ -82,14 +83,136 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi ############################################################# - # Set local vars after sync_shared.conf is read + # Set local vars after confs are read + # Make sure paths dont have a trailing slash ({VAR%/}) + SYNCSHAREDREMOTEPATH="${SYNCSHAREDREMOTEPATH%/}" SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}/shortcuts" SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}/audiofolders" + LOCAL_SHORTCUTSPATH="$PROJROOTPATH/shared/shortcuts" + LOCAL_AUDIOFOLDERSPATH="${AUDIOFOLDERSPATH%/}" ############################################################# ############################################################# # Functions + + # Check if server is reachable on port + function is_server_reachable { + return `nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT` + } + + # Sync all files from source to destination + # Some special options are needed as the 'folder.conf' file will be generated on playback. + # Explanation for rsync options: + # "--itemize-changes" print a summary of copied files. Used for determination if files where changed (empty if no syncing performed). Useful for debug.log + # "--safe-links" ignore symlinks that point outside the tree + # "--times" preserve modification times from source. Recommended option to efficiently identify unchanged files + # "--omit-dir-times" ignore modification time on dirs (see --times). Needed to ignore the creation of 'folder.conf' which alters the modification time of dirs + # "--delete" delete files that no longer exist in source + # "--prune-empty-dirs" delete empty dirs (incl. subdirs) + # "--filter="-rp folder.conf" exclude (option '-') 'folder.conf' file from deletion on receiving side (option 'r'). Delete anyway if folder will be deleted (option 'p' (perishable)). + # "--exclude="placeholder" exclude 'placeholder' file from syncing, especially deletion + function sync_from_server { + local src_path="$1" + local dst_path="$2" + local update_mpc="$3" + + rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' $rsync_add_options "${src_path}" "${dst_path}") + + if [ $? -eq 0 -a -n "${rsync_changes}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> ${PROJROOTPATH}/logs/debug.log; fi + + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. change access of files" >> ${PROJROOTPATH}/logs/debug.log; fi + change_access "${dst_path}" "www-data" "775" + + if [ ! -z "${update_mpc}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: update database" >> ${PROJROOTPATH}/logs/debug.log; fi + sudo mpc update --wait "${dst_path}" > /dev/null 2>&1 + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + } + + # Sync shortcut CARDID + function handle_shortcuts { + if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + if is_server_reachable ; then + + if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then + mkdir "${SYNCSHORTCUTSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + + elif [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ]; then + sync_from_server "${SYNCSHORTCUTSPATH}/${CARDID}" "${LOCAL_SHORTCUTSPATH}/${CARDID}" + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + } + + # Sync audiofolder FOLDER + function handle_audiofolders { + if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + if is_server_reachable ; then + + if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then + mkdir "${SYNCAUDIOFOLDERSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + + elif [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ]; then + sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "true" + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + } + + # Sync full (shortcuts and audiofolders) + function handle_full { + if is_server_reachable ; then + + if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then + mkdir "${SYNCSHORTCUTSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi + sync_from_server "${SYNCSHORTCUTSPATH}/" "${LOCAL_SHORTCUTSPATH}/" + + fi + + if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then + mkdir "${SYNCAUDIOFOLDERSPATH}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi + sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "true" + + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + fi + } + + # Change setting for Sync on RFID scan function handle_changeOnRfidScan { case $VALUE in on) @@ -112,11 +235,12 @@ else esac if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $VALUE" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $SYNCSHAREDONRFIDSCAN_NEW" >> ${PROJROOTPATH}/logs/debug.log; fi sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"$SYNCSHAREDONRFIDSCAN_NEW\"|g" ${PROJROOTPATH}/settings/sync_shared.conf fi } + # Change access of file or dir function change_access { local file_or_dir="$1" local group="$2" @@ -130,131 +254,15 @@ else ############################################################# ############################################################# - # Sync all files for the specific command. - # Some special options are needed as the 'folder.conf' file will be generated on playback. - # Explanation for rsync options: - # "--itemize-changes" print a summary of copied files. Used for determination if files where changed (empty if no syncing performed). Useful for debug.log - # "--safe-links" ignore symlinks that point outside the tree - # "--times" preserve modification times from source. Recommended option to efficiently identify unchanged files - # "--omit-dir-times" ignore modification time on dirs (see --times). Needed to ignore the creation of 'folder.conf' which alters the modification time of dirs - # "--update" ignore newer files on destination. Lower traffic and runtime - # "--delete" delete files that no longer exist in source - # "--prune-empty-dirs" delete empty dirs (incl. subdirs) - # "--filter="-rp folder.conf" exclude (option '-') 'folder.conf' file from deletion on receiving side (option 'r'). Delete anyway if folder will be deleted (option 'p' (perishable)). - # "--exclude="placeholder" exclude 'placeholder' file from syncing, especially deletion case $COMMAND in shortcuts) - if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then - if nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT ; then - - if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then - mkdir "${SYNCSHORTCUTSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - - elif [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ]; then - RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times "${SYNCSHORTCUTSPATH}/${CARDID}" "${SHORTCUTSPATH}/") - - if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PROJROOTPATH}/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PROJROOTPATH}/logs/debug.log; fi - - change_access "${SHORTCUTSPATH}/${CARDID}" "www-data" "775" - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi - fi + handle_shortcuts ;; audiofolders) - if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then - if nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT ; then - - if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then - mkdir "${SYNCAUDIOFOLDERSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - - elif [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ]; then - RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${AUDIOFOLDERSPATH}/${FOLDER}/") - - if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PROJROOTPATH}/logs/debug.log; fi - - change_access "${AUDIOFOLDERSPATH}/${FOLDER}" "www-data" "775" - sudo mpc update --wait "${AUDIOFOLDERSPATH}/${FOLDER}" > /dev/null 2>&1 - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi - fi + handle_audiofolders ;; full) - if nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT ; then - - if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then - mkdir "${SYNCSHORTCUTSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi - RSYNCSHORTCUTSCMD=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --exclude="placeholder" "${SYNCSHORTCUTSPATH}/" "${SHORTCUTSPATH}/") - - if [ $? -eq 0 -a -n "${RSYNCSHORTCUTSCMD}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSHORTCUTSCMD}" >> ${PROJROOTPATH}/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights" >> ${PROJROOTPATH}/logs/debug.log; fi - - change_access "${SHORTCUTSPATH}" "www-data" "775" - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - fi - - if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then - mkdir "${SYNCAUDIOFOLDERSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi - RSYNCSAUDIOFILES=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --update --delete --prune-empty-dirs --filter="-rp folder.conf" --exclude="placeholder" "${SYNCAUDIOFOLDERSPATH}/" "${AUDIOFOLDERSPATH}/") - - if [ $? -eq 0 -a -n "${RSYNCSAUDIOFILES}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: executed rsync ${RSYNCSAUDIOFILES}" >> ${PROJROOTPATH}/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. setting rights and update database" >> ${PROJROOTPATH}/logs/debug.log; fi - - change_access "${AUDIOFOLDERSPATH}" "www-data" "775" - sudo mpc update --wait "${AUDIOFOLDERSPATH}" > /dev/null 2>&1 - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi - fi - - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi - fi + handle_full ;; changeOnRfidScan) handle_changeOnRfidScan From 7d81a0d48aa4d721f1de51d9a564d7781e97cf54 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 19 Feb 2023 04:01:49 +0100 Subject: [PATCH 28/54] removed leftover var --- .../synchronisation/sync-shared-from-server/sync-shared.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index fdeafe92b..1dfe88b5a 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -117,7 +117,7 @@ else local dst_path="$2" local update_mpc="$3" - rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' $rsync_add_options "${src_path}" "${dst_path}") + rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' "${src_path}" "${dst_path}") if [ $? -eq 0 -a -n "${rsync_changes}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> ${PROJROOTPATH}/logs/debug.log; fi From b1d5f5d0f573f7fa1778983af9fbf5327c6ec47b Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 19 Feb 2023 23:35:04 +0100 Subject: [PATCH 29/54] new rfid commands harmonised --- settings/rfid_trigger_play.conf.sample | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings/rfid_trigger_play.conf.sample b/settings/rfid_trigger_play.conf.sample index 756aabed0..fefc523f8 100755 --- a/settings/rfid_trigger_play.conf.sample +++ b/settings/rfid_trigger_play.conf.sample @@ -160,6 +160,6 @@ RECORDPLAYBACKLATEST="%RECORDPLAYBACKLATEST%" ## Synchronisation ### Synchronise all shared files -SYNCSHAREDFULL=%SYNCSHAREDFULL% +SYNCSHAREDFULL="%SYNCSHAREDFULL%" ### Toggle activation of 'sync on RFID scan' -SYNCSHAREDONRFIDSCANTOGGLE=%SYNCSHAREDONRFIDSCANTOGGLE% \ No newline at end of file +SYNCSHAREDONRFIDSCANTOGGLE="%SYNCSHAREDONRFIDSCANTOGGLE%" \ No newline at end of file From 77b2983353b063f3882ff2e5ba55f0c550d8a699 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 19 Feb 2023 23:40:41 +0100 Subject: [PATCH 30/54] minor corrections --- .../sync-shared-from-server/settings/sync_shared.conf.sample | 2 +- settings/rfid_trigger_play.conf.sample | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample index 9acb3724c..cbdddbc7f 100755 --- a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample @@ -1,4 +1,4 @@ -SYNCSHAREDONRFIDSCAN="TRUE" +SYNCSHAREDONRFIDSCAN="FALSE" SYNCSHAREDREMOTESERVER="" SYNCSHAREDREMOTEPORT="" SYNCSHAREDREMOTEPATH="" diff --git a/settings/rfid_trigger_play.conf.sample b/settings/rfid_trigger_play.conf.sample index fefc523f8..6bb7451b0 100755 --- a/settings/rfid_trigger_play.conf.sample +++ b/settings/rfid_trigger_play.conf.sample @@ -162,4 +162,4 @@ RECORDPLAYBACKLATEST="%RECORDPLAYBACKLATEST%" ### Synchronise all shared files SYNCSHAREDFULL="%SYNCSHAREDFULL%" ### Toggle activation of 'sync on RFID scan' -SYNCSHAREDONRFIDSCANTOGGLE="%SYNCSHAREDONRFIDSCANTOGGLE%" \ No newline at end of file +SYNCSHAREDONRFIDSCANTOGGLE="%SYNCSHAREDONRFIDSCANTOGGLE%" From f1126a0bcc8e7a2fb2a63ef84f240690e716d2c8 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Mon, 20 Feb 2023 03:28:36 +0100 Subject: [PATCH 31/54] Added synchronisation mode SSH config updated for new settings --- .../change_configuration.sh | 36 ++++++++++--- .../settings/sync_shared.conf.sample | 5 +- .../sync-shared-from-server/sync-shared.sh | 54 +++++++++++++------ 3 files changed, 70 insertions(+), 25 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/change_configuration.sh b/components/synchronisation/sync-shared-from-server/change_configuration.sh index 7ea7cc0d0..9b3be3b77 100755 --- a/components/synchronisation/sync-shared-from-server/change_configuration.sh +++ b/components/synchronisation/sync-shared-from-server/change_configuration.sh @@ -61,10 +61,24 @@ function read_setting { } function read_all_settings { + + read_setting "$SYNCSHAREDONRFIDSCAN" "Do you want to activate the syncronisation on RFID scan (y[es]/n[o])." + case "$response" in + [yY][eE][sS]|[yY]) + response="TRUE" + ;; + [nN][oO]|[nN]) + response="FALSE" + ;; + *) + ;; + esac + set_setting "SYNCSHAREDONRFIDSCAN" "$response" + read_setting "$SYNCSHAREDREMOTESERVER" "Please enter your servers adresse (IP/Hostname)." set_setting "SYNCSHAREDREMOTESERVER" "$response" - read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." + read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port (also used for SSH)." set_setting "SYNCSHAREDREMOTEPORT" "$response" read_setting "$SYNCSHAREDREMOTEPATH" "Please enter the path to the shared files to sync (without trailing slash)." @@ -73,19 +87,25 @@ function read_all_settings { read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." set_setting "SYNCSHAREDREMOTETIMOUT" "$response" - - read_setting "$SYNCSHAREDONRFIDSCAN" "Do you want to activate the syncronisation on RFID scan (y/N)." + + read_setting "$SYNCSHAREDMODE" "Choose synchronisation mode to access the server (m[ount]/s[sh])." case "$response" in - [yY][eE][sS]|[yY]) - response="TRUE" + [mM][oO][uU][nN][tT]|[mM][nN][tT]|[mM]) + response="MOUNT" ;; - [nN][oO]|[nN]) - response="FALSE" + [sS][sS][hH]|[sS]) + response="SSH" ;; *) ;; esac - set_setting "SYNCSHAREDONRFIDSCAN" "$response" + set_setting "SYNCSHAREDMODE" "$response" + + if [ "$response" == "SSH" ]; then + read_setting "$SYNCSHAREDREMOTESSHUSER" "Please enter SSH user." + set_setting "SYNCSHAREDREMOTESSHUSER" "$response" + fi + } ############################################################# diff --git a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample index cbdddbc7f..5ae76057a 100755 --- a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample @@ -2,4 +2,7 @@ SYNCSHAREDONRFIDSCAN="FALSE" SYNCSHAREDREMOTESERVER="" SYNCSHAREDREMOTEPORT="" SYNCSHAREDREMOTEPATH="" -SYNCSHAREDREMOTETIMOUT="1" \ No newline at end of file +SYNCSHAREDREMOTETIMOUT="1" +#SSH or MNT +SYNCSHAREDMODE="MNT" +SYNCSHAREDREMOTESSHUSER="" \ No newline at end of file diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index 1dfe88b5a..28e33f931 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -96,9 +96,25 @@ else ############################################################# # Functions + # Check if the sync mode is SSH + function is_mode_ssh { + [ "$SYNCSHAREDMODE" == "SSH" ] + } + + # Executes the command check for the current mode + function exec_for_mode { + if is_mode_ssh ; then + # Executes remote via SSH + ssh ${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER} -p ${SYNCSHAREDREMOTEPORT} $1 + else + # Executes local on mount + $1 # must not be escaped, otherwise string value will be tested + fi + } + # Check if server is reachable on port function is_server_reachable { - return `nc -z $SYNCSHAREDREMOTESERVER -w $SYNCSHAREDREMOTETIMOUT $SYNCSHAREDREMOTEPORT` + return `nc -z "$SYNCSHAREDREMOTESERVER" -w "$SYNCSHAREDREMOTETIMOUT" "$SYNCSHAREDREMOTEPORT"` } # Sync all files from source to destination @@ -117,7 +133,12 @@ else local dst_path="$2" local update_mpc="$3" - rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' "${src_path}" "${dst_path}") + if is_mode_ssh ; then + local ssh_port=(-e "ssh -p ${SYNCSHAREDREMOTEPORT}") + local ssh_conn="${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER}:" + fi + + rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") if [ $? -eq 0 -a -n "${rsync_changes}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -139,12 +160,12 @@ else function handle_shortcuts { if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then if is_server_reachable ; then - - if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then - mkdir "${SYNCSHORTCUTSPATH}" + + if exec_for_mode "[ ! -d "${SYNCSHORTCUTSPATH}" ]" ; then + exec_for_mode "mkdir ${SYNCSHORTCUTSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - elif [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ]; then + elif exec_for_mode "[ -f ${SYNCSHORTCUTSPATH}/${CARDID} ]" ; then sync_from_server "${SYNCSHORTCUTSPATH}/${CARDID}" "${LOCAL_SHORTCUTSPATH}/${CARDID}" else @@ -165,11 +186,11 @@ else if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then if is_server_reachable ; then - if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then - mkdir "${SYNCAUDIOFOLDERSPATH}" + if exec_for_mode "[ ! -d ${SYNCAUDIOFOLDERSPATH} ]" ; then + exec_for_mode "mkdir ${SYNCAUDIOFOLDERSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - elif [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ]; then + elif exec_for_mode "[ -d ${SYNCAUDIOFOLDERSPATH}/${FOLDER} ]" ; then sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "true" else @@ -189,8 +210,8 @@ else function handle_full { if is_server_reachable ; then - if [ ! -d "${SYNCSHORTCUTSPATH}" ]; then - mkdir "${SYNCSHORTCUTSPATH}" + if exec_for_mode "[ ! -d ${SYNCSHORTCUTSPATH} ]" ; then + exec_for_mode "mkdir ${SYNCSHORTCUTSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -198,8 +219,8 @@ else fi - if [ ! -d "${SYNCAUDIOFOLDERSPATH}" ]; then - mkdir "${SYNCAUDIOFOLDERSPATH}" + if exec_for_mode "[ ! -d ${SYNCAUDIOFOLDERSPATH} ]" ; then + exec_for_mode "mkdir ${SYNCAUDIOFOLDERSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -214,7 +235,7 @@ else # Change setting for Sync on RFID scan function handle_changeOnRfidScan { - case $VALUE in + case "$VALUE" in on) SYNCSHAREDONRFIDSCAN_NEW="TRUE" ;; @@ -254,7 +275,8 @@ else ############################################################# ############################################################# - case $COMMAND in + + case "$COMMAND" in shortcuts) handle_shortcuts ;; @@ -268,7 +290,7 @@ else handle_changeOnRfidScan ;; *) - echo Unknown COMMAND $COMMAND + echo Unknown COMMAND "$COMMAND" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi ;; esac From 0435e6f580e68cb477cb5e34a1ca13b5b460813e Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Mon, 20 Feb 2023 03:30:58 +0100 Subject: [PATCH 32/54] Settings sample updated --- .../settings/sync_shared.conf.sample | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample index 5ae76057a..8dd6e00a9 100755 --- a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample @@ -3,6 +3,6 @@ SYNCSHAREDREMOTESERVER="" SYNCSHAREDREMOTEPORT="" SYNCSHAREDREMOTEPATH="" SYNCSHAREDREMOTETIMOUT="1" -#SSH or MNT -SYNCSHAREDMODE="MNT" -SYNCSHAREDREMOTESSHUSER="" \ No newline at end of file +#SSH or MOUNT +SYNCSHAREDMODE="MOUNT" +SYNCSHAREDREMOTESSHUSER="" From f9418437412763d7bc00acc3a9d531441b56268d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 23 Feb 2023 00:21:14 +0100 Subject: [PATCH 33/54] Exclude special folders from syncing --- .../sync-shared-from-server/sync-shared.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared-from-server/sync-shared.sh index 28e33f931..c8d33da34 100755 --- a/components/synchronisation/sync-shared-from-server/sync-shared.sh +++ b/components/synchronisation/sync-shared-from-server/sync-shared.sh @@ -126,8 +126,10 @@ else # "--omit-dir-times" ignore modification time on dirs (see --times). Needed to ignore the creation of 'folder.conf' which alters the modification time of dirs # "--delete" delete files that no longer exist in source # "--prune-empty-dirs" delete empty dirs (incl. subdirs) - # "--filter="-rp folder.conf" exclude (option '-') 'folder.conf' file from deletion on receiving side (option 'r'). Delete anyway if folder will be deleted (option 'p' (perishable)). - # "--exclude="placeholder" exclude 'placeholder' file from syncing, especially deletion + # "--filter='-rp folder.conf' exclude (option '-') 'folder.conf' file from deletion on receiving side (option 'r'). Delete anyway if folder will be deleted (option 'p' (perishable)). + # "--exclude='placeholder' exclude 'placeholder' file from syncing, especially deletion + # "--exclude='.*/' exclude special 'hidden' folders from syncing + # "--exclude='@*/' exclude special folders from syncing function sync_from_server { local src_path="$1" local dst_path="$2" @@ -138,7 +140,7 @@ else local ssh_conn="${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER}:" fi - rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") + rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' --exclude='.*/' --exclude='@*/' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") if [ $? -eq 0 -a -n "${rsync_changes}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -296,4 +298,4 @@ else esac fi -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ##" >> ${PROJROOTPATH}/logs/debug.log; fi \ No newline at end of file +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ##" >> ${PROJROOTPATH}/logs/debug.log; fi From 40cdb537fdb848c12a8e0d8f292824f0abe80e19 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 23 Feb 2023 00:35:00 +0100 Subject: [PATCH 34/54] renamed folder sync-shared-from-server to sync-shared Updated README.md --- .../README.md | 14 +++++++++----- .../change_configuration.sh | 0 .../install-sync-shared.sh | 0 .../settings/sync_shared.conf.sample | 0 .../sync-shared.sh | 0 scripts/rfid_trigger_play.sh | 8 ++++---- 6 files changed, 13 insertions(+), 9 deletions(-) rename components/synchronisation/{sync-shared-from-server => sync-shared}/README.md (75%) rename components/synchronisation/{sync-shared-from-server => sync-shared}/change_configuration.sh (100%) rename components/synchronisation/{sync-shared-from-server => sync-shared}/install-sync-shared.sh (100%) rename components/synchronisation/{sync-shared-from-server => sync-shared}/settings/sync_shared.conf.sample (100%) rename components/synchronisation/{sync-shared-from-server => sync-shared}/sync-shared.sh (100%) diff --git a/components/synchronisation/sync-shared-from-server/README.md b/components/synchronisation/sync-shared/README.md similarity index 75% rename from components/synchronisation/sync-shared-from-server/README.md rename to components/synchronisation/sync-shared/README.md index 8df946951..11dfc1661 100644 --- a/components/synchronisation/sync-shared-from-server/README.md +++ b/components/synchronisation/sync-shared/README.md @@ -4,19 +4,19 @@ This component activates a synchronisation from a server to the Phoniebox for th This can be done with a full-sync as a special RFID command and optionally on every RFID scan for the particular CardID. For the full-sync bind a CardId to the command "SYNCSHAREDFULL". -For the "RFID scan sync" feature activate the option in the configuration. There is also a command to toggle the activation the RFID scan sync feature via CardId (bind to "SYNCSHAREDONRFIDSCANTOGGLE"). +For the "RFID scan sync" feature, activate the option in the configuration. There is also a command to toggle the activation the RFID scan sync feature via CardId (bind to "SYNCSHAREDONRFIDSCANTOGGLE"). ## Snynchronisation -The synchronisation will be only FROM the server TO the Phoniebox, overriding existing files and settings. So configuration of audiofiles / -folders and CardIds made via WebUi will be lost after sync. +The synchronisation will be FROM the server TO the Phoniebox, overriding existing files and settings. So configuration of audiofiles / -folders and CardIds made via WebUi will be lost after sync. If you want to make the initial setup via WebUi copy the files and use it as a base for the server. The "folder.conf" files will be synced if present on the server, but not delete if not (they are automatically generated on playback). -If the feature "RFID scan sync" is activated, there will be a check on every RFID scan against the server if a matching shortcut and audiofolder is found and the changes will be transfered (and overriden on the Phoniebox). +If the feature "RFID scan sync" is activated, there will be a check on every RFID scan against the server if a matching shortcut and audiofolder is found and the changes will be transfered. If the server is not reachable the check will be aborted after the timeout. So an unreachable server will cause a delay (see command "SYNCSHAREDONRFIDSCANTOGGLE" to toggle activation state). Further will the playback be delayed for the time the data are transfered (see "SYNCSHAREDFULL" to use a full-sync if a lot of new files have been added). -Currently only synchronisation via a mounted share ist supported. +To access the files on the server two modes are supported: SSH or MOUNT ## Installation @@ -46,4 +46,8 @@ SYNCSHAREDREMOTEPORT: The port of the server (used to check connectivity). e.g. SYNCSHAREDREMOTEPATH: The path to the shared files to sync. e.g. "/mnt/Phoniebox" -SYNCSHAREDREMOTETIMOUT: The timeout to reach the server (in seconds) (used to check connectivity). e.g. 1 \ No newline at end of file +SYNCSHAREDREMOTETIMOUT: The timeout to reach the server (in seconds) (used to check connectivity). e.g. 1 + +SYNCSHAREDMODE: The mode to access the server files. SSH or MOUNT + +SYNCSHAREDREMOTESSHUSER: The username if SSH mode is used. \ No newline at end of file diff --git a/components/synchronisation/sync-shared-from-server/change_configuration.sh b/components/synchronisation/sync-shared/change_configuration.sh similarity index 100% rename from components/synchronisation/sync-shared-from-server/change_configuration.sh rename to components/synchronisation/sync-shared/change_configuration.sh diff --git a/components/synchronisation/sync-shared-from-server/install-sync-shared.sh b/components/synchronisation/sync-shared/install-sync-shared.sh similarity index 100% rename from components/synchronisation/sync-shared-from-server/install-sync-shared.sh rename to components/synchronisation/sync-shared/install-sync-shared.sh diff --git a/components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared/settings/sync_shared.conf.sample similarity index 100% rename from components/synchronisation/sync-shared-from-server/settings/sync_shared.conf.sample rename to components/synchronisation/sync-shared/settings/sync_shared.conf.sample diff --git a/components/synchronisation/sync-shared-from-server/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh similarity index 100% rename from components/synchronisation/sync-shared-from-server/sync-shared.sh rename to components/synchronisation/sync-shared/sync-shared.sh diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 3649f8b49..c6993e459 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -317,13 +317,13 @@ if [ "$CARDID" ]; then $SYNCSHAREDFULL) # If enabled sync full if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=full + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=full fi ;; $SYNCSHAREDONRFIDSCANTOGGLE) # If enabled change sync setting if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=changeOnRfidScan -v=toggle + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=changeOnRfidScan -v=toggle fi ;; *) @@ -334,7 +334,7 @@ if [ "$CARDID" ]; then # If enabled sync shortcut $CARDID if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=shortcuts -i="$CARDID" + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=shortcuts -i="$CARDID" fi # Look for human readable shortcut in folder 'shortcuts' @@ -375,7 +375,7 @@ if [ ! -z "$FOLDER" ]; then # If enabled sync audio folder $FOLDER if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared-from-server/sync-shared.sh -c=audiofolders -d="$FOLDER" + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=audiofolders -d="$FOLDER" fi # check if $FOLDER points to existing directory From 524f34f37b64778c4f27865c5f3901e5425cf8eb Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Fri, 24 Feb 2023 21:09:46 +0100 Subject: [PATCH 35/54] refactored commands to playout_control.sh fullsync and changeOnRfidScan refactored to playout_controls.sh --- scripts/playout_controls.sh | 8 ++++++++ scripts/rfid_trigger_play.sh | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/playout_controls.sh b/scripts/playout_controls.sh index 0bc6a3a67..320331f59 100755 --- a/scripts/playout_controls.sh +++ b/scripts/playout_controls.sh @@ -73,6 +73,8 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # readwifiipoverspeaker # bluetoothtoggle # switchaudioiface +# sharedsyncfull +# sharedsyncchangeonrfidscan # The absolute path to the folder which contains all the scripts. # Unless you are working with symlinks, leave the following line untouched. @@ -1136,6 +1138,12 @@ case $COMMAND in dbg "Command requires \"amixer\" as volume manager." fi ;; + sharedsyncfull) + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=full + ;; + sharedsyncchangeonrfidscan) + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=changeOnRfidScan -v="$VALUE" + ;; *) echo Unknown COMMAND $COMMAND VALUE $VALUE if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} VALUE ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index c6993e459..0d773b49a 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -315,16 +315,10 @@ if [ "$CARDID" ]; then $PATHDATA/playout_controls.sh -c=bluetoothtoggle -v=toggle ;; $SYNCSHAREDFULL) - # If enabled sync full - if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=full - fi + $PATHDATA/playout_controls.sh -c=sharedsyncfull ;; $SYNCSHAREDONRFIDSCANTOGGLE) - # If enabled change sync setting - if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=changeOnRfidScan -v=toggle - fi + $PATHDATA/playout_controls.sh -c=sharedsyncchangeonrfidscan -v=toggle ;; *) From f3f38be555b49e09b407ae314f86d22e2f20c9ad Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Fri, 24 Feb 2023 21:21:43 +0100 Subject: [PATCH 36/54] fixed exec_for_mode for paths with whitespaces --- .../sync-shared/sync-shared.sh | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index c8d33da34..a4fa5833f 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -101,14 +101,21 @@ else [ "$SYNCSHAREDMODE" == "SSH" ] } - # Executes the command check for the current mode + # Executes the command for the current mode function exec_for_mode { if is_mode_ssh ; then - # Executes remote via SSH - ssh ${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER} -p ${SYNCSHAREDREMOTEPORT} $1 + # Quote every param to deal with whitespaces in paths + local quotedparams + for var in "$@" + do + quotedparams="$quotedparams \"$var\"" + done + + # Execute remote via SSH + ssh "$SYNCSHAREDREMOTESSHUSER"@"$SYNCSHAREDREMOTESERVER" -p "$SYNCSHAREDREMOTEPORT" "$quotedparams" else - # Executes local on mount - $1 # must not be escaped, otherwise string value will be tested + # Execute local on mount + "$@" fi } @@ -163,11 +170,11 @@ else if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then if is_server_reachable ; then - if exec_for_mode "[ ! -d "${SYNCSHORTCUTSPATH}" ]" ; then - exec_for_mode "mkdir ${SYNCSHORTCUTSPATH}" + if exec_for_mode [ ! -d "${SYNCSHORTCUTSPATH}" ] ; then + exec_for_mode mkdir "${SYNCSHORTCUTSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - elif exec_for_mode "[ -f ${SYNCSHORTCUTSPATH}/${CARDID} ]" ; then + elif exec_for_mode [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ] ; then sync_from_server "${SYNCSHORTCUTSPATH}/${CARDID}" "${LOCAL_SHORTCUTSPATH}/${CARDID}" else @@ -188,11 +195,11 @@ else if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then if is_server_reachable ; then - if exec_for_mode "[ ! -d ${SYNCAUDIOFOLDERSPATH} ]" ; then - exec_for_mode "mkdir ${SYNCAUDIOFOLDERSPATH}" + if exec_for_mode [ ! -d "${SYNCAUDIOFOLDERSPATH}" ] ; then + exec_for_mode mkdir "${SYNCAUDIOFOLDERSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi - elif exec_for_mode "[ -d ${SYNCAUDIOFOLDERSPATH}/${FOLDER} ]" ; then + elif exec_for_mode [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ] ; then sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "true" else @@ -212,8 +219,8 @@ else function handle_full { if is_server_reachable ; then - if exec_for_mode "[ ! -d ${SYNCSHORTCUTSPATH} ]" ; then - exec_for_mode "mkdir ${SYNCSHORTCUTSPATH}" + if exec_for_mode [ ! -d "${SYNCSHORTCUTSPATH}" ] ; then + exec_for_mode mkdir "${SYNCSHORTCUTSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi @@ -221,8 +228,8 @@ else fi - if exec_for_mode "[ ! -d ${SYNCAUDIOFOLDERSPATH} ]" ; then - exec_for_mode "mkdir ${SYNCAUDIOFOLDERSPATH}" + if exec_for_mode [ ! -d "${SYNCAUDIOFOLDERSPATH}" ] ; then + exec_for_mode mkdir "${SYNCAUDIOFOLDERSPATH}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi From d6ecd0e7d0236560639a8c959d0fceb4b91b55fb Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:15:31 +0100 Subject: [PATCH 37/54] use consinstent quotation --- .../sync-shared/change_configuration.sh | 18 ++--- .../sync-shared/sync-shared.sh | 80 +++++++++---------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/components/synchronisation/sync-shared/change_configuration.sh b/components/synchronisation/sync-shared/change_configuration.sh index 9b3be3b77..b9acbb4d9 100755 --- a/components/synchronisation/sync-shared/change_configuration.sh +++ b/components/synchronisation/sync-shared/change_configuration.sh @@ -20,20 +20,20 @@ function set_activation { # Let global controls know this feature is enabled echo -e "\nLet global controls know this feature is $SETTINGSTATE. (Sync_Shared_Enabled -> $SETTINGVALUE)" - echo "$SETTINGVALUE" > ${CONFFILE} - sudo chgrp www-data ${CONFFILE} - sudo chmod 775 ${CONFFILE} + echo "$SETTINGVALUE" > "${CONFFILE}" + sudo chgrp www-data "${CONFFILE}" + sudo chmod 775 "${CONFFILE}" } function init_settings { # Init config from sample if not present - if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then - cp ${PATHDATA}/settings/sync_shared.conf.sample ${PROJROOTPATH}/settings/sync_shared.conf + if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then + cp "${PATHDATA}/settings/sync_shared.conf.sample" "${PROJROOTPATH}/settings/sync_shared.conf" # change the read/write so that later this might also be editable through the web app - sudo chgrp www-data ${PROJROOTPATH}/settings/sync_shared.conf - sudo chmod 775 ${PROJROOTPATH}/settings/sync_shared.conf + sudo chgrp www-data "${PROJROOTPATH}/settings/sync_shared.conf" + sudo chmod 775 "${PROJROOTPATH}/settings/sync_shared.conf" fi - . ${PROJROOTPATH}/settings/sync_shared.conf + . "${PROJROOTPATH}"/settings/sync_shared.conf } function set_setting { @@ -41,7 +41,7 @@ function set_setting { local SETTINGVALUE="$2" if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then - sed -i "s|^$SETTINGNAME=.*|$SETTINGNAME=\"$SETTINGVALUE\"|g" ${PROJROOTPATH}/settings/sync_shared.conf + sed -i "s|^$SETTINGNAME=.*|$SETTINGNAME=\"$SETTINGVALUE\"|g" "${PROJROOTPATH}/settings/sync_shared.conf" echo "New value: \"$SETTINGVALUE\"" fi } diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index a4fa5833f..d742d756b 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -35,52 +35,52 @@ PROJROOTPATH="$PATHDATA/../../.." ############################################################# # $DEBUG TRUE|FALSE # Read debug logging configuration file -. ${PROJROOTPATH}/settings/debugLogging.conf +. "${PROJROOTPATH}"/settings/debugLogging.conf -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> ${PROJROOTPATH}/logs/debug.log; fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> "${PROJROOTPATH}"/logs/debug.log; fi ####################### # Activation status of component sync-shared-from-server SYNCSHAREDENABLED="FALSE" -if [ -f ${PROJROOTPATH}/settings/Sync_Shared_Enabled ]; then - SYNCSHAREDENABLED=`cat ${PROJROOTPATH}/settings/Sync_Shared_Enabled` +if [ -f "${PROJROOTPATH}/settings/Sync_Shared_Enabled" ]; then + SYNCSHAREDENABLED=`cat "${PROJROOTPATH}/settings/Sync_Shared_Enabled"` fi if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> "${PROJROOTPATH}"/logs/debug.log; fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> "${PROJROOTPATH}"/logs/debug.log; fi ############################################################# # Read global configuration file (and create if not exists) - if [ ! -f ${PROJROOTPATH}/settings/global.conf ]; then + if [ ! -f "${PROJROOTPATH}/settings/global.conf" ]; then echo "Global settingsfile does not exist. Please call the script from a defined entrypoint" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Global settingsfile does not exist. Please call the script from a defined entrypoint" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Global settingsfile does not exist. Please call the script from a defined entrypoint" >> "${PROJROOTPATH}"/logs/debug.log; fi exit fi - . ${PROJROOTPATH}/settings/global.conf + . "${PROJROOTPATH}"/settings/global.conf ############################################################# # Read configuration file - if [ ! -f ${PROJROOTPATH}/settings/sync_shared.conf ]; then + if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then echo "Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" >> "${PROJROOTPATH}"/logs/debug.log; fi exit fi - . ${PROJROOTPATH}/settings/sync_shared.conf + . "${PROJROOTPATH}"/settings/sync_shared.conf ############################################################# # Get args from command line (see Usage above) # Read the args passed on by the command line # see following file for details: - . ${PROJROOTPATH}/scripts/inc.readArgsFromCommandLine.sh + . "${PROJROOTPATH}"/scripts/inc.readArgsFromCommandLine.sh - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> ${PROJROOTPATH}/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> ${PROJROOTPATH}/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> ${PROJROOTPATH}/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> "${PROJROOTPATH}"/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> "${PROJROOTPATH}"/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> "${PROJROOTPATH}"/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> "${PROJROOTPATH}"/logs/debug.log; fi ############################################################# # Set local vars after confs are read @@ -89,7 +89,7 @@ else SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}/shortcuts" SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}/audiofolders" - LOCAL_SHORTCUTSPATH="$PROJROOTPATH/shared/shortcuts" + LOCAL_SHORTCUTSPATH="${PROJROOTPATH}/shared/shortcuts" LOCAL_AUDIOFOLDERSPATH="${AUDIOFOLDERSPATH%/}" ############################################################# @@ -150,18 +150,18 @@ else rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' --exclude='.*/' --exclude='@*/' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") if [ $? -eq 0 -a -n "${rsync_changes}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> "${PROJROOTPATH}"/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. change access of files" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. change access of files" >> "${PROJROOTPATH}"/logs/debug.log; fi change_access "${dst_path}" "www-data" "775" if [ ! -z "${update_mpc}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: update database" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: update database" >> "${PROJROOTPATH}"/logs/debug.log; fi sudo mpc update --wait "${dst_path}" > /dev/null 2>&1 fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> "${PROJROOTPATH}"/logs/debug.log; fi fi } @@ -172,21 +172,21 @@ else if exec_for_mode [ ! -d "${SYNCSHORTCUTSPATH}" ] ; then exec_for_mode mkdir "${SYNCSHORTCUTSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi elif exec_for_mode [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ] ; then sync_from_server "${SYNCSHORTCUTSPATH}/${CARDID}" "${LOCAL_SHORTCUTSPATH}/${CARDID}" else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> "${PROJROOTPATH}"/logs/debug.log; fi fi } @@ -197,21 +197,21 @@ else if exec_for_mode [ ! -d "${SYNCAUDIOFOLDERSPATH}" ] ; then exec_for_mode mkdir "${SYNCAUDIOFOLDERSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi elif exec_for_mode [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ] ; then sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "true" else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> "${PROJROOTPATH}"/logs/debug.log; fi fi } @@ -221,24 +221,24 @@ else if exec_for_mode [ ! -d "${SYNCSHORTCUTSPATH}" ] ; then exec_for_mode mkdir "${SYNCSHORTCUTSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi sync_from_server "${SYNCSHORTCUTSPATH}/" "${LOCAL_SHORTCUTSPATH}/" fi if exec_for_mode [ ! -d "${SYNCAUDIOFOLDERSPATH}" ] ; then exec_for_mode mkdir "${SYNCAUDIOFOLDERSPATH}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "true" fi else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi fi } @@ -260,13 +260,13 @@ else ;; *) echo "Unknown VALUE $VALUE for COMMAND $COMMAND" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE $VALUE for COMMAND $COMMAND" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE $VALUE for COMMAND $COMMAND" >> "${PROJROOTPATH}"/logs/debug.log; fi ;; esac if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $SYNCSHAREDONRFIDSCAN_NEW" >> ${PROJROOTPATH}/logs/debug.log; fi - sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"$SYNCSHAREDONRFIDSCAN_NEW\"|g" ${PROJROOTPATH}/settings/sync_shared.conf + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $SYNCSHAREDONRFIDSCAN_NEW" >> "${PROJROOTPATH}"/logs/debug.log; fi + sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"$SYNCSHAREDONRFIDSCAN_NEW\"|g" "${PROJROOTPATH}"/settings/sync_shared.conf fi } @@ -300,9 +300,9 @@ else ;; *) echo Unknown COMMAND "$COMMAND" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> ${PROJROOTPATH}/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> "${PROJROOTPATH}"/logs/debug.log; fi ;; esac fi -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ##" >> ${PROJROOTPATH}/logs/debug.log; fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ##" >> "${PROJROOTPATH}"/logs/debug.log; fi From c3534edcb6f947688e97a53dbc31c475182abe37 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:43:05 +0100 Subject: [PATCH 38/54] use consistent var access --- .../sync-shared/change_configuration.sh | 19 ++++--- .../sync-shared/sync-shared.sh | 56 +++++++++---------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/components/synchronisation/sync-shared/change_configuration.sh b/components/synchronisation/sync-shared/change_configuration.sh index b9acbb4d9..9bc988822 100755 --- a/components/synchronisation/sync-shared/change_configuration.sh +++ b/components/synchronisation/sync-shared/change_configuration.sh @@ -18,11 +18,11 @@ function set_activation { fi # Let global controls know this feature is enabled - echo -e "\nLet global controls know this feature is $SETTINGSTATE. (Sync_Shared_Enabled -> $SETTINGVALUE)" + echo -e "\nLet global controls know this feature is ${SETTINGSTATE}. (Sync_Shared_Enabled -> ${SETTINGVALUE})" - echo "$SETTINGVALUE" > "${CONFFILE}" - sudo chgrp www-data "${CONFFILE}" - sudo chmod 775 "${CONFFILE}" + echo "$SETTINGVALUE" > "$CONFFILE" + sudo chgrp www-data "$CONFFILE" + sudo chmod 775 "$CONFFILE" } function init_settings { @@ -40,9 +40,10 @@ function set_setting { local SETTINGNAME="$1" local SETTINGVALUE="$2" + # check if value is set and not equal to the current settings value if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then - sed -i "s|^$SETTINGNAME=.*|$SETTINGNAME=\"$SETTINGVALUE\"|g" "${PROJROOTPATH}/settings/sync_shared.conf" - echo "New value: \"$SETTINGVALUE\"" + sed -i "s|^${SETTINGNAME}=.*|${SETTINGNAME}=\"${SETTINGVALUE}\"|g" "${PROJROOTPATH}/settings/sync_shared.conf" + echo "New value: \"${SETTINGVALUE}\"" fi } @@ -51,11 +52,11 @@ function read_setting { local TEXT="$2" local SKIP_LEAVE_BLANK="$3" - local READ_PROMPT=$'\n'"$TEXT" + local READ_PROMPT=$'\n'"${TEXT}" if [ -z "$SKIP_LEAVE_BLANK" ]; then - READ_PROMPT="$READ_PROMPT Leave blank for no change." + READ_PROMPT="${READ_PROMPT} Leave blank for no change." fi - READ_PROMPT="$READ_PROMPT"$'\n'"Current value = \"$SETTINGNAME\""$'\n' + READ_PROMPT="${READ_PROMPT}"$'\n'"Current value = \"${SETTINGNAME}\""$'\n' read -rp "$READ_PROMPT" response } diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index d742d756b..ed6daaa42 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -30,14 +30,14 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # The absolute path to the folder which contains all the scripts. # Unless you are working with symlinks, leave the following line untouched. PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJROOTPATH="$PATHDATA/../../.." +PROJROOTPATH="${PATHDATA}/../../.." ############################################################# # $DEBUG TRUE|FALSE # Read debug logging configuration file . "${PROJROOTPATH}"/settings/debugLogging.conf -if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ($NOW) ##" >> "${PROJROOTPATH}"/logs/debug.log; fi +if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh (${NOW}) ##" >> "${PROJROOTPATH}"/logs/debug.log; fi ####################### # Activation status of component sync-shared-from-server @@ -47,7 +47,7 @@ if [ -f "${PROJROOTPATH}/settings/Sync_Shared_Enabled" ]; then fi -if [ "${SYNCSHAREDENABLED}" != "TRUE" ]; then +if [ "$SYNCSHAREDENABLED" != "TRUE" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> "${PROJROOTPATH}"/logs/debug.log; fi else @@ -108,7 +108,7 @@ else local quotedparams for var in "$@" do - quotedparams="$quotedparams \"$var\"" + quotedparams="${quotedparams} \"${var}\"" done # Execute remote via SSH @@ -149,15 +149,15 @@ else rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' --exclude='.*/' --exclude='@*/' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") - if [ $? -eq 0 -a -n "${rsync_changes}" ]; then + if [ $? -eq 0 -a -n "$rsync_changes" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> "${PROJROOTPATH}"/logs/debug.log; fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. change access of files" >> "${PROJROOTPATH}"/logs/debug.log; fi - change_access "${dst_path}" "www-data" "775" + change_access "$dst_path" "www-data" "775" - if [ ! -z "${update_mpc}" ]; then + if [ ! -z "$update_mpc" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: update database" >> "${PROJROOTPATH}"/logs/debug.log; fi - sudo mpc update --wait "${dst_path}" > /dev/null 2>&1 + sudo mpc update --wait "$dst_path" > /dev/null 2>&1 fi else @@ -167,11 +167,11 @@ else # Sync shortcut CARDID function handle_shortcuts { - if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then if is_server_reachable ; then - if exec_for_mode [ ! -d "${SYNCSHORTCUTSPATH}" ] ; then - exec_for_mode mkdir "${SYNCSHORTCUTSPATH}" + if exec_for_mode [ ! -d "$SYNCSHORTCUTSPATH" ] ; then + exec_for_mode mkdir "$SYNCSHORTCUTSPATH" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi elif exec_for_mode [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ] ; then @@ -192,15 +192,15 @@ else # Sync audiofolder FOLDER function handle_audiofolders { - if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then if is_server_reachable ; then - if exec_for_mode [ ! -d "${SYNCAUDIOFOLDERSPATH}" ] ; then - exec_for_mode mkdir "${SYNCAUDIOFOLDERSPATH}" + if exec_for_mode [ ! -d "$SYNCAUDIOFOLDERSPATH" ] ; then + exec_for_mode mkdir "$SYNCAUDIOFOLDERSPATH" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi elif exec_for_mode [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ] ; then - sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "true" + sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "UpdateMPC" else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi @@ -219,8 +219,8 @@ else function handle_full { if is_server_reachable ; then - if exec_for_mode [ ! -d "${SYNCSHORTCUTSPATH}" ] ; then - exec_for_mode mkdir "${SYNCSHORTCUTSPATH}" + if exec_for_mode [ ! -d "$SYNCSHORTCUTSPATH" ] ; then + exec_for_mode mkdir "$SYNCSHORTCUTSPATH" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi @@ -228,12 +228,12 @@ else fi - if exec_for_mode [ ! -d "${SYNCAUDIOFOLDERSPATH}" ] ; then - exec_for_mode mkdir "${SYNCAUDIOFOLDERSPATH}" + if exec_for_mode [ ! -d "$SYNCAUDIOFOLDERSPATH" ] ; then + exec_for_mode mkdir "$SYNCAUDIOFOLDERSPATH" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi - sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "true" + sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "UpdateMPC" fi @@ -252,21 +252,21 @@ else SYNCSHAREDONRFIDSCAN_NEW="FALSE" ;; toggle) - if [ "${SYNCSHAREDONRFIDSCAN}" == "TRUE" ]; then + if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then SYNCSHAREDONRFIDSCAN_NEW="FALSE" else SYNCSHAREDONRFIDSCAN_NEW="TRUE" fi ;; *) - echo "Unknown VALUE $VALUE for COMMAND $COMMAND" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE $VALUE for COMMAND $COMMAND" >> "${PROJROOTPATH}"/logs/debug.log; fi + echo "Unknown VALUE ${VALUE} for COMMAND ${COMMAND}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE ${VALUE} for COMMAND ${COMMAND}" >> "${PROJROOTPATH}"/logs/debug.log; fi ;; esac if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to $SYNCSHAREDONRFIDSCAN_NEW" >> "${PROJROOTPATH}"/logs/debug.log; fi - sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"$SYNCSHAREDONRFIDSCAN_NEW\"|g" "${PROJROOTPATH}"/settings/sync_shared.conf + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to ${SYNCSHAREDONRFIDSCAN_NEW}" >> "${PROJROOTPATH}"/logs/debug.log; fi + sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"${SYNCSHAREDONRFIDSCAN_NEW}\"|g" "${PROJROOTPATH}"/settings/sync_shared.conf fi } @@ -276,8 +276,8 @@ else local group="$2" local mod="$3" - sudo chgrp -R "${group}" "${file_or_dir}" - sudo chmod -R "${mod}" "${file_or_dir}" + sudo chgrp -R "$group" "$file_or_dir" + sudo chmod -R "$mod" "$file_or_dir" } ############################################################# @@ -299,7 +299,7 @@ else handle_changeOnRfidScan ;; *) - echo Unknown COMMAND "$COMMAND" + echo "Unknown COMMAND {$COMMAND}" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> "${PROJROOTPATH}"/logs/debug.log; fi ;; esac From e939f3bcb2bd19d272f78acb8b8dc4dbf7ee283c Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:51:13 +0100 Subject: [PATCH 39/54] removed unused logic --- .../synchronisation/sync-shared/change_configuration.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/synchronisation/sync-shared/change_configuration.sh b/components/synchronisation/sync-shared/change_configuration.sh index 9bc988822..5913b48e0 100755 --- a/components/synchronisation/sync-shared/change_configuration.sh +++ b/components/synchronisation/sync-shared/change_configuration.sh @@ -50,12 +50,8 @@ function set_setting { function read_setting { local SETTINGNAME="$1" local TEXT="$2" - local SKIP_LEAVE_BLANK="$3" - local READ_PROMPT=$'\n'"${TEXT}" - if [ -z "$SKIP_LEAVE_BLANK" ]; then - READ_PROMPT="${READ_PROMPT} Leave blank for no change." - fi + local READ_PROMPT=$'\n'"${TEXT} Leave blank for no change." READ_PROMPT="${READ_PROMPT}"$'\n'"Current value = \"${SETTINGNAME}\""$'\n' read -rp "$READ_PROMPT" response From 7c38da14709e9f5530b4636e387b90991baa6182 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:51:56 +0100 Subject: [PATCH 40/54] added documentation comments to conf file --- .../sync-shared/settings/sync_shared.conf.sample | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/synchronisation/sync-shared/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared/settings/sync_shared.conf.sample index 8dd6e00a9..9f2fa95cd 100755 --- a/components/synchronisation/sync-shared/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared/settings/sync_shared.conf.sample @@ -1,8 +1,14 @@ +# activationstate for syncronisation on RFID scan SYNCSHAREDONRFIDSCAN="FALSE" +# server adresse (IP/Hostname) SYNCSHAREDREMOTESERVER="" +# server port (also used for SSH) SYNCSHAREDREMOTEPORT="" +# path to the shared files to sync (without trailing slash) SYNCSHAREDREMOTEPATH="" +# timeout to try to reach the server (in seconds) SYNCSHAREDREMOTETIMOUT="1" -#SSH or MOUNT +# synchronisation mode to access the server (SSH or MOUNT) SYNCSHAREDMODE="MOUNT" +# SSH user SYNCSHAREDREMOTESSHUSER="" From 765c21ae9020c83a96492128392358be65b0cee8 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 25 Feb 2023 21:18:43 +0100 Subject: [PATCH 41/54] reordered conf and updated README --- .../synchronisation/sync-shared/README.md | 18 ++++---- .../sync-shared/change_configuration.sh | 44 +++++++++---------- .../settings/sync_shared.conf.sample | 22 +++++----- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/components/synchronisation/sync-shared/README.md b/components/synchronisation/sync-shared/README.md index 11dfc1661..3e22f955c 100644 --- a/components/synchronisation/sync-shared/README.md +++ b/components/synchronisation/sync-shared/README.md @@ -31,23 +31,23 @@ You may also change the settings in the according files directly. ### Settings: -**INSTALLATION_ROOT/settings/Sync_Shared_Enabled** +**{INSTALLATION_ROOT}/settings/Sync_Shared_Enabled** -Hold the activation state of this feature. Values are "TRUE" or "FALSE" +Holds the activation state of this feature. Values are "TRUE" or "FALSE" -**INSTALLATION_ROOT/settings/sync_shared.conf** +**{INSTALLATION_ROOT}/settings/sync_shared.conf** -SYNCSHAREDONRFIDSCAN: If the optional feature "RFID scan sync" is activated. Values are "TRUE" or "FALSE" +SYNCSHAREDMODE: The mode to access the server files. SSH or MOUNT -SYNCSHAREDREMOTESERVER: The IP or hostname of the server (used to check connectivity). e.g. "192.168.0.2" or "myhomeserver.local" +SYNCSHAREDREMOTESSHUSER: The username if SSH mode is used. -SYNCSHAREDREMOTEPORT: The port of the server (used to check connectivity). e.g. "80" or "22" +SYNCSHAREDREMOTESERVER: The IP or hostname of the server (used to check connectivity and SSH mode). e.g. "192.168.0.2" or "myhomeserver.local" -SYNCSHAREDREMOTEPATH: The path to the shared files to sync. e.g. "/mnt/Phoniebox" +SYNCSHAREDREMOTEPORT: The port of the server (used to check connectivity and SSH mode). e.g. "80" or "22" SYNCSHAREDREMOTETIMOUT: The timeout to reach the server (in seconds) (used to check connectivity). e.g. 1 -SYNCSHAREDMODE: The mode to access the server files. SSH or MOUNT +SYNCSHAREDREMOTEPATH: The path to the shared files to sync (without trailing slash) (remote path for SSH mode or local path for MOUNT mode). e.g. "/mnt/Phoniebox" -SYNCSHAREDREMOTESSHUSER: The username if SSH mode is used. \ No newline at end of file +SYNCSHAREDONRFIDSCAN: Holds the activation state of the optional feature "RFID scan sync". Values are "TRUE" or "FALSE" diff --git a/components/synchronisation/sync-shared/change_configuration.sh b/components/synchronisation/sync-shared/change_configuration.sh index 5913b48e0..862437cc3 100755 --- a/components/synchronisation/sync-shared/change_configuration.sh +++ b/components/synchronisation/sync-shared/change_configuration.sh @@ -59,50 +59,50 @@ function read_setting { function read_all_settings { - read_setting "$SYNCSHAREDONRFIDSCAN" "Do you want to activate the syncronisation on RFID scan (y[es]/n[o])." + read_setting "$SYNCSHAREDMODE" "Choose synchronisation mode to access the server (m[ount]/s[sh])." case "$response" in - [yY][eE][sS]|[yY]) - response="TRUE" + [mM][oO][uU][nN][tT]|[mM][nN][tT]|[mM]) + response="MOUNT" ;; - [nN][oO]|[nN]) - response="FALSE" + [sS][sS][hH]|[sS]) + response="SSH" ;; *) + # no change ;; esac - set_setting "SYNCSHAREDONRFIDSCAN" "$response" + set_setting "SYNCSHAREDMODE" "$response" + + if [ "$response" == "SSH" ]; then + read_setting "$SYNCSHAREDREMOTESSHUSER" "Please enter SSH user." + set_setting "SYNCSHAREDREMOTESSHUSER" "$response" + fi read_setting "$SYNCSHAREDREMOTESERVER" "Please enter your servers adresse (IP/Hostname)." set_setting "SYNCSHAREDREMOTESERVER" "$response" - read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port (also used for SSH)." + read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." set_setting "SYNCSHAREDREMOTEPORT" "$response" + read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." + set_setting "SYNCSHAREDREMOTETIMOUT" "$response" + read_setting "$SYNCSHAREDREMOTEPATH" "Please enter the path to the shared files to sync (without trailing slash)." # Make sure paths dont have a trailing slash ({VAR%/}) set_setting "SYNCSHAREDREMOTEPATH" "${response%/}" - read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." - set_setting "SYNCSHAREDREMOTETIMOUT" "$response" - - read_setting "$SYNCSHAREDMODE" "Choose synchronisation mode to access the server (m[ount]/s[sh])." + read_setting "$SYNCSHAREDONRFIDSCAN" "Do you want to activate the syncronisation on RFID scan (y[es]/n[o])." case "$response" in - [mM][oO][uU][nN][tT]|[mM][nN][tT]|[mM]) - response="MOUNT" + [yY][eE][sS]|[yY]) + response="TRUE" ;; - [sS][sS][hH]|[sS]) - response="SSH" + [nN][oO]|[nN]) + response="FALSE" ;; *) ;; esac - set_setting "SYNCSHAREDMODE" "$response" - - if [ "$response" == "SSH" ]; then - read_setting "$SYNCSHAREDREMOTESSHUSER" "Please enter SSH user." - set_setting "SYNCSHAREDREMOTESSHUSER" "$response" - fi - + set_setting "SYNCSHAREDONRFIDSCAN" "$response" } ############################################################# diff --git a/components/synchronisation/sync-shared/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared/settings/sync_shared.conf.sample index 9f2fa95cd..f77ad8289 100755 --- a/components/synchronisation/sync-shared/settings/sync_shared.conf.sample +++ b/components/synchronisation/sync-shared/settings/sync_shared.conf.sample @@ -1,14 +1,14 @@ -# activationstate for syncronisation on RFID scan -SYNCSHAREDONRFIDSCAN="FALSE" -# server adresse (IP/Hostname) +# The mode to access the server files. SSH or MOUNT +SYNCSHAREDMODE="MOUNT" +# The username if SSH mode is used +SYNCSHAREDREMOTESSHUSER="" +# The IP or hostname of the server (used to check connectivity and SSH mode) SYNCSHAREDREMOTESERVER="" -# server port (also used for SSH) +# The port of the server (used to check connectivity and SSH mode) SYNCSHAREDREMOTEPORT="" -# path to the shared files to sync (without trailing slash) -SYNCSHAREDREMOTEPATH="" -# timeout to try to reach the server (in seconds) +# The timeout to reach the server (in seconds) (used to check connectivity) SYNCSHAREDREMOTETIMOUT="1" -# synchronisation mode to access the server (SSH or MOUNT) -SYNCSHAREDMODE="MOUNT" -# SSH user -SYNCSHAREDREMOTESSHUSER="" +# The path to the shared files to sync (without trailing slash) (remote path for SSH mode or local path for MOUNT mode) +SYNCSHAREDREMOTEPATH="" +# Holds the activation state of the optional feature "RFID scan sync" +SYNCSHAREDONRFIDSCAN="FALSE" From ebadc11bbad126b11f3da10c60b9d935c034b822 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 25 Feb 2023 21:29:19 +0100 Subject: [PATCH 42/54] updated README --- components/synchronisation/sync-shared/README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/components/synchronisation/sync-shared/README.md b/components/synchronisation/sync-shared/README.md index 3e22f955c..dcb05489f 100644 --- a/components/synchronisation/sync-shared/README.md +++ b/components/synchronisation/sync-shared/README.md @@ -1,22 +1,24 @@ -# Synchronize shared files from a Server +# Synchronize shared files from a server This component activates a synchronisation from a server to the Phoniebox for the shared folders 'shortcuts' and 'audiofolders'. -This can be done with a full-sync as a special RFID command and optionally on every RFID scan for the particular CardID. +This can be initiated as a full-sync command and optionally on every RFID scan for the particular CardID (and corresponding audiofolder). For the full-sync bind a CardId to the command "SYNCSHAREDFULL". -For the "RFID scan sync" feature, activate the option in the configuration. There is also a command to toggle the activation the RFID scan sync feature via CardId (bind to "SYNCSHAREDONRFIDSCANTOGGLE"). +For the "RFID scan sync" feature, activate the option in the configuration. There is also a command to toggle the activation of the "RFID scan sync" feature via CardId (bind to command "SYNCSHAREDONRFIDSCANTOGGLE"). -## Snynchronisation +## Synchronisation -The synchronisation will be FROM the server TO the Phoniebox, overriding existing files and settings. So configuration of audiofiles / -folders and CardIds made via WebUi will be lost after sync. +The synchronisation will be FROM a server TO the Phoniebox, overriding (or deleting) existing files. So configuration of audiofiles / -folders and CardIds made via WebUi will be lost after sync. If you want to make the initial setup via WebUi copy the files and use it as a base for the server. The "folder.conf" files will be synced if present on the server, but not delete if not (they are automatically generated on playback). If the feature "RFID scan sync" is activated, there will be a check on every RFID scan against the server if a matching shortcut and audiofolder is found and the changes will be transfered. +The playback will be delayed for the time the data are transfered (see "SYNCSHAREDFULL" to use a full-sync if a lot of new files have been added). If the server is not reachable the check will be aborted after the timeout. So an unreachable server will cause a delay (see command "SYNCSHAREDONRFIDSCANTOGGLE" to toggle activation state). -Further will the playback be delayed for the time the data are transfered (see "SYNCSHAREDFULL" to use a full-sync if a lot of new files have been added). -To access the files on the server two modes are supported: SSH or MOUNT +To access the files on the server two modes are supported: SSH or MOUNT. +Please make sure you have the correct access rights for the source and use key-based authentication for SSH. + ## Installation From 7182caac748533c1f759c41cc1b12e86e9633345 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 26 Feb 2023 00:42:55 +0100 Subject: [PATCH 43/54] refactored function definition --- .../sync-shared/change_configuration.sh | 10 +++++----- .../synchronisation/sync-shared/sync-shared.sh | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/components/synchronisation/sync-shared/change_configuration.sh b/components/synchronisation/sync-shared/change_configuration.sh index 862437cc3..735416f61 100755 --- a/components/synchronisation/sync-shared/change_configuration.sh +++ b/components/synchronisation/sync-shared/change_configuration.sh @@ -9,7 +9,7 @@ SKIP_INITIAL_CHECK="$1" ############################################################# # Functions -function set_activation { +set_activation() { local SETTINGVALUE="$1" local SETTINGSTATE="activated" @@ -25,7 +25,7 @@ function set_activation { sudo chmod 775 "$CONFFILE" } -function init_settings { +init_settings() { # Init config from sample if not present if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then cp "${PATHDATA}/settings/sync_shared.conf.sample" "${PROJROOTPATH}/settings/sync_shared.conf" @@ -36,7 +36,7 @@ function init_settings { . "${PROJROOTPATH}"/settings/sync_shared.conf } -function set_setting { +set_setting() { local SETTINGNAME="$1" local SETTINGVALUE="$2" @@ -47,7 +47,7 @@ function set_setting { fi } -function read_setting { +read_setting() { local SETTINGNAME="$1" local TEXT="$2" @@ -57,7 +57,7 @@ function read_setting { read -rp "$READ_PROMPT" response } -function read_all_settings { +read_all_settings() { read_setting "$SYNCSHAREDMODE" "Choose synchronisation mode to access the server (m[ount]/s[sh])." case "$response" in diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index ed6daaa42..75035fcf3 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -97,12 +97,12 @@ else # Functions # Check if the sync mode is SSH - function is_mode_ssh { + is_mode_ssh() { [ "$SYNCSHAREDMODE" == "SSH" ] } # Executes the command for the current mode - function exec_for_mode { + exec_for_mode() { if is_mode_ssh ; then # Quote every param to deal with whitespaces in paths local quotedparams @@ -120,7 +120,7 @@ else } # Check if server is reachable on port - function is_server_reachable { + is_server_reachable() { return `nc -z "$SYNCSHAREDREMOTESERVER" -w "$SYNCSHAREDREMOTETIMOUT" "$SYNCSHAREDREMOTEPORT"` } @@ -137,7 +137,7 @@ else # "--exclude='placeholder' exclude 'placeholder' file from syncing, especially deletion # "--exclude='.*/' exclude special 'hidden' folders from syncing # "--exclude='@*/' exclude special folders from syncing - function sync_from_server { + sync_from_server() { local src_path="$1" local dst_path="$2" local update_mpc="$3" @@ -166,7 +166,7 @@ else } # Sync shortcut CARDID - function handle_shortcuts { + handle_shortcuts() { if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then if is_server_reachable ; then @@ -191,7 +191,7 @@ else } # Sync audiofolder FOLDER - function handle_audiofolders { + handle_audiofolders() { if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then if is_server_reachable ; then @@ -216,7 +216,7 @@ else } # Sync full (shortcuts and audiofolders) - function handle_full { + handle_full() { if is_server_reachable ; then if exec_for_mode [ ! -d "$SYNCSHORTCUTSPATH" ] ; then @@ -243,7 +243,7 @@ else } # Change setting for Sync on RFID scan - function handle_changeOnRfidScan { + handle_changeOnRfidScan() { case "$VALUE" in on) SYNCSHAREDONRFIDSCAN_NEW="TRUE" @@ -271,7 +271,7 @@ else } # Change access of file or dir - function change_access { + change_access() { local file_or_dir="$1" local group="$2" local mod="$3" From 11e8cc2b9ceb531740d9fd2e40651fc15479ea5e Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 26 Feb 2023 01:36:43 +0100 Subject: [PATCH 44/54] fixed sync_from_server for paths with whitespaces --- components/synchronisation/sync-shared/sync-shared.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index 75035fcf3..74905954e 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -108,7 +108,7 @@ else local quotedparams for var in "$@" do - quotedparams="${quotedparams} \"${var}\"" + quotedparams="${quotedparams} '${var}'" done # Execute remote via SSH @@ -143,10 +143,13 @@ else local update_mpc="$3" if is_mode_ssh ; then + # Quote source path to deal with whitespaces in paths + src_path="'${src_path}'" + local ssh_port=(-e "ssh -p ${SYNCSHAREDREMOTEPORT}") local ssh_conn="${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER}:" fi - + rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' --exclude='.*/' --exclude='@*/' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") if [ $? -eq 0 -a -n "$rsync_changes" ]; then From 26d9462e85e76a48ed22776b633168901810b924 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:12:23 +0100 Subject: [PATCH 45/54] applied editorconfig --- .../sync-shared/change_configuration.sh | 200 +++---- .../sync-shared/install-sync-shared.sh | 12 +- .../sync-shared/sync-shared.sh | 518 +++++++++--------- scripts/playout_controls.sh | 14 +- scripts/rfid_trigger_play.sh | 354 ++++++------ settings/rfid_trigger_play.conf.sample | 4 +- 6 files changed, 551 insertions(+), 551 deletions(-) diff --git a/components/synchronisation/sync-shared/change_configuration.sh b/components/synchronisation/sync-shared/change_configuration.sh index 735416f61..baa570342 100755 --- a/components/synchronisation/sync-shared/change_configuration.sh +++ b/components/synchronisation/sync-shared/change_configuration.sh @@ -10,129 +10,129 @@ SKIP_INITIAL_CHECK="$1" # Functions set_activation() { - local SETTINGVALUE="$1" - - local SETTINGSTATE="activated" - if [ "$SETTINGVALUE" != "TRUE" ]; then - SETTINGSTATE="deactivated" - fi - - # Let global controls know this feature is enabled - echo -e "\nLet global controls know this feature is ${SETTINGSTATE}. (Sync_Shared_Enabled -> ${SETTINGVALUE})" - - echo "$SETTINGVALUE" > "$CONFFILE" - sudo chgrp www-data "$CONFFILE" - sudo chmod 775 "$CONFFILE" + local SETTINGVALUE="$1" + + local SETTINGSTATE="activated" + if [ "$SETTINGVALUE" != "TRUE" ]; then + SETTINGSTATE="deactivated" + fi + + # Let global controls know this feature is enabled + echo -e "\nLet global controls know this feature is ${SETTINGSTATE}. (Sync_Shared_Enabled -> ${SETTINGVALUE})" + + echo "$SETTINGVALUE" > "$CONFFILE" + sudo chgrp www-data "$CONFFILE" + sudo chmod 775 "$CONFFILE" } init_settings() { - # Init config from sample if not present - if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then - cp "${PATHDATA}/settings/sync_shared.conf.sample" "${PROJROOTPATH}/settings/sync_shared.conf" - # change the read/write so that later this might also be editable through the web app - sudo chgrp www-data "${PROJROOTPATH}/settings/sync_shared.conf" - sudo chmod 775 "${PROJROOTPATH}/settings/sync_shared.conf" - fi - . "${PROJROOTPATH}"/settings/sync_shared.conf + # Init config from sample if not present + if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then + cp "${PATHDATA}/settings/sync_shared.conf.sample" "${PROJROOTPATH}/settings/sync_shared.conf" + # change the read/write so that later this might also be editable through the web app + sudo chgrp www-data "${PROJROOTPATH}/settings/sync_shared.conf" + sudo chmod 775 "${PROJROOTPATH}/settings/sync_shared.conf" + fi + . "${PROJROOTPATH}"/settings/sync_shared.conf } set_setting() { - local SETTINGNAME="$1" - local SETTINGVALUE="$2" - - # check if value is set and not equal to the current settings value - if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then - sed -i "s|^${SETTINGNAME}=.*|${SETTINGNAME}=\"${SETTINGVALUE}\"|g" "${PROJROOTPATH}/settings/sync_shared.conf" - echo "New value: \"${SETTINGVALUE}\"" - fi + local SETTINGNAME="$1" + local SETTINGVALUE="$2" + + # check if value is set and not equal to the current settings value + if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then + sed -i "s|^${SETTINGNAME}=.*|${SETTINGNAME}=\"${SETTINGVALUE}\"|g" "${PROJROOTPATH}/settings/sync_shared.conf" + echo "New value: \"${SETTINGVALUE}\"" + fi } read_setting() { - local SETTINGNAME="$1" - local TEXT="$2" - - local READ_PROMPT=$'\n'"${TEXT} Leave blank for no change." - READ_PROMPT="${READ_PROMPT}"$'\n'"Current value = \"${SETTINGNAME}\""$'\n' + local SETTINGNAME="$1" + local TEXT="$2" + + local READ_PROMPT=$'\n'"${TEXT} Leave blank for no change." + READ_PROMPT="${READ_PROMPT}"$'\n'"Current value = \"${SETTINGNAME}\""$'\n' - read -rp "$READ_PROMPT" response + read -rp "$READ_PROMPT" response } read_all_settings() { - read_setting "$SYNCSHAREDMODE" "Choose synchronisation mode to access the server (m[ount]/s[sh])." - case "$response" in - [mM][oO][uU][nN][tT]|[mM][nN][tT]|[mM]) - response="MOUNT" - ;; - [sS][sS][hH]|[sS]) - response="SSH" - ;; - *) - # no change - ;; - esac - set_setting "SYNCSHAREDMODE" "$response" - - if [ "$response" == "SSH" ]; then - read_setting "$SYNCSHAREDREMOTESSHUSER" "Please enter SSH user." - set_setting "SYNCSHAREDREMOTESSHUSER" "$response" - fi - - read_setting "$SYNCSHAREDREMOTESERVER" "Please enter your servers adresse (IP/Hostname)." - set_setting "SYNCSHAREDREMOTESERVER" "$response" - - read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." - set_setting "SYNCSHAREDREMOTEPORT" "$response" - - read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." - set_setting "SYNCSHAREDREMOTETIMOUT" "$response" - - read_setting "$SYNCSHAREDREMOTEPATH" "Please enter the path to the shared files to sync (without trailing slash)." - # Make sure paths dont have a trailing slash ({VAR%/}) - set_setting "SYNCSHAREDREMOTEPATH" "${response%/}" - - read_setting "$SYNCSHAREDONRFIDSCAN" "Do you want to activate the syncronisation on RFID scan (y[es]/n[o])." - case "$response" in - [yY][eE][sS]|[yY]) - response="TRUE" - ;; - [nN][oO]|[nN]) - response="FALSE" - ;; - *) - ;; - esac - set_setting "SYNCSHAREDONRFIDSCAN" "$response" + read_setting "$SYNCSHAREDMODE" "Choose synchronisation mode to access the server (m[ount]/s[sh])." + case "$response" in + [mM][oO][uU][nN][tT]|[mM][nN][tT]|[mM]) + response="MOUNT" + ;; + [sS][sS][hH]|[sS]) + response="SSH" + ;; + *) + # no change + ;; + esac + set_setting "SYNCSHAREDMODE" "$response" + + if [ "$response" == "SSH" ]; then + read_setting "$SYNCSHAREDREMOTESSHUSER" "Please enter SSH user." + set_setting "SYNCSHAREDREMOTESSHUSER" "$response" + fi + + read_setting "$SYNCSHAREDREMOTESERVER" "Please enter your servers adresse (IP/Hostname)." + set_setting "SYNCSHAREDREMOTESERVER" "$response" + + read_setting "$SYNCSHAREDREMOTEPORT" "Please enter your servers port." + set_setting "SYNCSHAREDREMOTEPORT" "$response" + + read_setting "$SYNCSHAREDREMOTETIMOUT" "Please enter the timeout to try to reach the server (in seconds)." + set_setting "SYNCSHAREDREMOTETIMOUT" "$response" + + read_setting "$SYNCSHAREDREMOTEPATH" "Please enter the path to the shared files to sync (without trailing slash)." + # Make sure paths dont have a trailing slash ({VAR%/}) + set_setting "SYNCSHAREDREMOTEPATH" "${response%/}" + + read_setting "$SYNCSHAREDONRFIDSCAN" "Do you want to activate the syncronisation on RFID scan (y[es]/n[o])." + case "$response" in + [yY][eE][sS]|[yY]) + response="TRUE" + ;; + [nN][oO]|[nN]) + response="FALSE" + ;; + *) + ;; + esac + set_setting "SYNCSHAREDONRFIDSCAN" "$response" } ############################################################# # If intial check is skipped, asume the component shall be activated if [ -z "$SKIP_INITIAL_CHECK" ]; then - read -rp "Do you want to activate the sync-shared component? [Y/n] " response -else - response="yes" + read -rp "Do you want to activate the sync-shared component? [Y/n] " response +else + response="yes" fi case "$response" in - [nN][oO]|[nN]) - set_activation "FALSE" - ;; - *) - set_activation "TRUE" - - # Ensure start was intended - read -rp "Do you want to change the configuration? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - exit - ;; - *) - ;; - esac - init_settings - read_all_settings - ;; + [nN][oO]|[nN]) + set_activation "FALSE" + ;; + *) + set_activation "TRUE" + + # Ensure start was intended + read -rp "Do you want to change the configuration? [Y/n] " response + case "$response" in + [nN][oO]|[nN]) + exit + ;; + *) + ;; + esac + init_settings + read_all_settings + ;; esac echo -e "\nConfiguration finished" diff --git a/components/synchronisation/sync-shared/install-sync-shared.sh b/components/synchronisation/sync-shared/install-sync-shared.sh index e19049587..a9e225157 100755 --- a/components/synchronisation/sync-shared/install-sync-shared.sh +++ b/components/synchronisation/sync-shared/install-sync-shared.sh @@ -3,12 +3,12 @@ # Ensure start was intended read -rp "Start installation? [Y/n] " response case "$response" in - [nN][oO]|[nN]) - echo "Installation aborted..." - exit - ;; - *) - ;; + [nN][oO]|[nN]) + echo "Installation aborted..." + exit + ;; + *) + ;; esac PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index 74905954e..c7c20e886 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -12,10 +12,10 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # # sync audiofolders: # ./sync_shared.sh -c=audiofolders -d=xxx -# +# # sync full: # ./sync_shared.sh -c=full -# +# # sync toggle SyncOnRfidScan: # ./sync_shared.sh -c=changeOnRfidScan -v=toggle @@ -48,264 +48,264 @@ fi if [ "$SYNCSHAREDENABLED" != "TRUE" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> "${PROJROOTPATH}"/logs/debug.log; fi - + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: disabled" >> "${PROJROOTPATH}"/logs/debug.log; fi + else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> "${PROJROOTPATH}"/logs/debug.log; fi - - ############################################################# - # Read global configuration file (and create if not exists) - if [ ! -f "${PROJROOTPATH}/settings/global.conf" ]; then - echo "Global settingsfile does not exist. Please call the script from a defined entrypoint" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Global settingsfile does not exist. Please call the script from a defined entrypoint" >> "${PROJROOTPATH}"/logs/debug.log; fi - exit - fi - . "${PROJROOTPATH}"/settings/global.conf - - ############################################################# - # Read configuration file - if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then - echo "Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" >> "${PROJROOTPATH}"/logs/debug.log; fi - exit - fi - . "${PROJROOTPATH}"/settings/sync_shared.conf - - ############################################################# - # Get args from command line (see Usage above) - # Read the args passed on by the command line - # see following file for details: - . "${PROJROOTPATH}"/scripts/inc.readArgsFromCommandLine.sh - - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> "${PROJROOTPATH}"/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> "${PROJROOTPATH}"/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> "${PROJROOTPATH}"/logs/debug.log; fi - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> "${PROJROOTPATH}"/logs/debug.log; fi - - ############################################################# - # Set local vars after confs are read - # Make sure paths dont have a trailing slash ({VAR%/}) - SYNCSHAREDREMOTEPATH="${SYNCSHAREDREMOTEPATH%/}" - SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}/shortcuts" - SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}/audiofolders" - - LOCAL_SHORTCUTSPATH="${PROJROOTPATH}/shared/shortcuts" - LOCAL_AUDIOFOLDERSPATH="${AUDIOFOLDERSPATH%/}" - - ############################################################# - ############################################################# - # Functions - - # Check if the sync mode is SSH - is_mode_ssh() { - [ "$SYNCSHAREDMODE" == "SSH" ] - } - - # Executes the command for the current mode - exec_for_mode() { - if is_mode_ssh ; then - # Quote every param to deal with whitespaces in paths - local quotedparams - for var in "$@" - do - quotedparams="${quotedparams} '${var}'" - done - - # Execute remote via SSH - ssh "$SYNCSHAREDREMOTESSHUSER"@"$SYNCSHAREDREMOTESERVER" -p "$SYNCSHAREDREMOTEPORT" "$quotedparams" - else - # Execute local on mount - "$@" - fi - } - - # Check if server is reachable on port - is_server_reachable() { - return `nc -z "$SYNCSHAREDREMOTESERVER" -w "$SYNCSHAREDREMOTETIMOUT" "$SYNCSHAREDREMOTEPORT"` - } - - # Sync all files from source to destination - # Some special options are needed as the 'folder.conf' file will be generated on playback. - # Explanation for rsync options: - # "--itemize-changes" print a summary of copied files. Used for determination if files where changed (empty if no syncing performed). Useful for debug.log - # "--safe-links" ignore symlinks that point outside the tree - # "--times" preserve modification times from source. Recommended option to efficiently identify unchanged files - # "--omit-dir-times" ignore modification time on dirs (see --times). Needed to ignore the creation of 'folder.conf' which alters the modification time of dirs - # "--delete" delete files that no longer exist in source - # "--prune-empty-dirs" delete empty dirs (incl. subdirs) - # "--filter='-rp folder.conf' exclude (option '-') 'folder.conf' file from deletion on receiving side (option 'r'). Delete anyway if folder will be deleted (option 'p' (perishable)). - # "--exclude='placeholder' exclude 'placeholder' file from syncing, especially deletion - # "--exclude='.*/' exclude special 'hidden' folders from syncing - # "--exclude='@*/' exclude special folders from syncing - sync_from_server() { - local src_path="$1" - local dst_path="$2" - local update_mpc="$3" - - if is_mode_ssh ; then - # Quote source path to deal with whitespaces in paths - src_path="'${src_path}'" - - local ssh_port=(-e "ssh -p ${SYNCSHAREDREMOTEPORT}") - local ssh_conn="${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER}:" - fi - - rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' --exclude='.*/' --exclude='@*/' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") - - if [ $? -eq 0 -a -n "$rsync_changes" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> "${PROJROOTPATH}"/logs/debug.log; fi - - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. change access of files" >> "${PROJROOTPATH}"/logs/debug.log; fi - change_access "$dst_path" "www-data" "775" - - if [ ! -z "$update_mpc" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: update database" >> "${PROJROOTPATH}"/logs/debug.log; fi - sudo mpc update --wait "$dst_path" > /dev/null 2>&1 - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - } - - # Sync shortcut CARDID - handle_shortcuts() { - if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then - if is_server_reachable ; then - - if exec_for_mode [ ! -d "$SYNCSHORTCUTSPATH" ] ; then - exec_for_mode mkdir "$SYNCSHORTCUTSPATH" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi - - elif exec_for_mode [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ] ; then - sync_from_server "${SYNCSHORTCUTSPATH}/${CARDID}" "${LOCAL_SHORTCUTSPATH}/${CARDID}" - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - } - - # Sync audiofolder FOLDER - handle_audiofolders() { - if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then - if is_server_reachable ; then - - if exec_for_mode [ ! -d "$SYNCAUDIOFOLDERSPATH" ] ; then - exec_for_mode mkdir "$SYNCAUDIOFOLDERSPATH" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi - - elif exec_for_mode [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ] ; then - sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "UpdateMPC" - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - } - - # Sync full (shortcuts and audiofolders) - handle_full() { - if is_server_reachable ; then - - if exec_for_mode [ ! -d "$SYNCSHORTCUTSPATH" ] ; then - exec_for_mode mkdir "$SYNCSHORTCUTSPATH" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi - sync_from_server "${SYNCSHORTCUTSPATH}/" "${LOCAL_SHORTCUTSPATH}/" - - fi - - if exec_for_mode [ ! -d "$SYNCAUDIOFOLDERSPATH" ] ; then - exec_for_mode mkdir "$SYNCAUDIOFOLDERSPATH" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi - sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "UpdateMPC" - - fi - - else - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi - fi - } - - # Change setting for Sync on RFID scan - handle_changeOnRfidScan() { - case "$VALUE" in - on) - SYNCSHAREDONRFIDSCAN_NEW="TRUE" - ;; - off) - SYNCSHAREDONRFIDSCAN_NEW="FALSE" - ;; - toggle) - if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then - SYNCSHAREDONRFIDSCAN_NEW="FALSE" - else - SYNCSHAREDONRFIDSCAN_NEW="TRUE" - fi - ;; - *) - echo "Unknown VALUE ${VALUE} for COMMAND ${COMMAND}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE ${VALUE} for COMMAND ${COMMAND}" >> "${PROJROOTPATH}"/logs/debug.log; fi - ;; - esac - - if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to ${SYNCSHAREDONRFIDSCAN_NEW}" >> "${PROJROOTPATH}"/logs/debug.log; fi - sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"${SYNCSHAREDONRFIDSCAN_NEW}\"|g" "${PROJROOTPATH}"/settings/sync_shared.conf - fi - } - - # Change access of file or dir - change_access() { - local file_or_dir="$1" - local group="$2" - local mod="$3" - - sudo chgrp -R "$group" "$file_or_dir" - sudo chmod -R "$mod" "$file_or_dir" - } - - ############################################################# - ############################################################# - - ############################################################# - - case "$COMMAND" in - shortcuts) - handle_shortcuts - ;; - audiofolders) - handle_audiofolders - ;; - full) - handle_full - ;; - changeOnRfidScan) - handle_changeOnRfidScan - ;; - *) - echo "Unknown COMMAND {$COMMAND}" - if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> "${PROJROOTPATH}"/logs/debug.log; fi - ;; - esac + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> "${PROJROOTPATH}"/logs/debug.log; fi + + ############################################################# + # Read global configuration file (and create if not exists) + if [ ! -f "${PROJROOTPATH}/settings/global.conf" ]; then + echo "Global settingsfile does not exist. Please call the script from a defined entrypoint" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Global settingsfile does not exist. Please call the script from a defined entrypoint" >> "${PROJROOTPATH}"/logs/debug.log; fi + exit + fi + . "${PROJROOTPATH}"/settings/global.conf + + ############################################################# + # Read configuration file + if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then + echo "Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" >> "${PROJROOTPATH}"/logs/debug.log; fi + exit + fi + . "${PROJROOTPATH}"/settings/sync_shared.conf + + ############################################################# + # Get args from command line (see Usage above) + # Read the args passed on by the command line + # see following file for details: + . "${PROJROOTPATH}"/scripts/inc.readArgsFromCommandLine.sh + + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR COMMAND: ${COMMAND}" >> "${PROJROOTPATH}"/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR CARDID: ${CARDID}" >> "${PROJROOTPATH}"/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR FOLDER: ${FOLDER}" >> "${PROJROOTPATH}"/logs/debug.log; fi + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" >> "${PROJROOTPATH}"/logs/debug.log; fi + + ############################################################# + # Set local vars after confs are read + # Make sure paths dont have a trailing slash ({VAR%/}) + SYNCSHAREDREMOTEPATH="${SYNCSHAREDREMOTEPATH%/}" + SYNCSHORTCUTSPATH="${SYNCSHAREDREMOTEPATH}/shortcuts" + SYNCAUDIOFOLDERSPATH="${SYNCSHAREDREMOTEPATH}/audiofolders" + + LOCAL_SHORTCUTSPATH="${PROJROOTPATH}/shared/shortcuts" + LOCAL_AUDIOFOLDERSPATH="${AUDIOFOLDERSPATH%/}" + + ############################################################# + ############################################################# + # Functions + + # Check if the sync mode is SSH + is_mode_ssh() { + [ "$SYNCSHAREDMODE" == "SSH" ] + } + + # Executes the command for the current mode + exec_for_mode() { + if is_mode_ssh ; then + # Quote every param to deal with whitespaces in paths + local quotedparams + for var in "$@" + do + quotedparams="${quotedparams} '${var}'" + done + + # Execute remote via SSH + ssh "$SYNCSHAREDREMOTESSHUSER"@"$SYNCSHAREDREMOTESERVER" -p "$SYNCSHAREDREMOTEPORT" "$quotedparams" + else + # Execute local on mount + "$@" + fi + } + + # Check if server is reachable on port + is_server_reachable() { + return `nc -z "$SYNCSHAREDREMOTESERVER" -w "$SYNCSHAREDREMOTETIMOUT" "$SYNCSHAREDREMOTEPORT"` + } + + # Sync all files from source to destination + # Some special options are needed as the 'folder.conf' file will be generated on playback. + # Explanation for rsync options: + # "--itemize-changes" print a summary of copied files. Used for determination if files where changed (empty if no syncing performed). Useful for debug.log + # "--safe-links" ignore symlinks that point outside the tree + # "--times" preserve modification times from source. Recommended option to efficiently identify unchanged files + # "--omit-dir-times" ignore modification time on dirs (see --times). Needed to ignore the creation of 'folder.conf' which alters the modification time of dirs + # "--delete" delete files that no longer exist in source + # "--prune-empty-dirs" delete empty dirs (incl. subdirs) + # "--filter='-rp folder.conf' exclude (option '-') 'folder.conf' file from deletion on receiving side (option 'r'). Delete anyway if folder will be deleted (option 'p' (perishable)). + # "--exclude='placeholder' exclude 'placeholder' file from syncing, especially deletion + # "--exclude='.*/' exclude special 'hidden' folders from syncing + # "--exclude='@*/' exclude special folders from syncing + sync_from_server() { + local src_path="$1" + local dst_path="$2" + local update_mpc="$3" + + if is_mode_ssh ; then + # Quote source path to deal with whitespaces in paths + src_path="'${src_path}'" + + local ssh_port=(-e "ssh -p ${SYNCSHAREDREMOTEPORT}") + local ssh_conn="${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER}:" + fi + + rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' --exclude='.*/' --exclude='@*/' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") + + if [ $? -eq 0 -a -n "$rsync_changes" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo -e "Sync: executed rsync \n${rsync_changes}" >> "${PROJROOTPATH}"/logs/debug.log; fi + + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. change access of files" >> "${PROJROOTPATH}"/logs/debug.log; fi + change_access "$dst_path" "www-data" "775" + + if [ ! -z "$update_mpc" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: update database" >> "${PROJROOTPATH}"/logs/debug.log; fi + sudo mpc update --wait "$dst_path" > /dev/null 2>&1 + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: nothing changed" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + } + + # Sync shortcut CARDID + handle_shortcuts() { + if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then + if is_server_reachable ; then + + if exec_for_mode [ ! -d "$SYNCSHORTCUTSPATH" ] ; then + exec_for_mode mkdir "$SYNCSHORTCUTSPATH" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi + + elif exec_for_mode [ -f "${SYNCSHORTCUTSPATH}/${CARDID}" ] ; then + sync_from_server "${SYNCSHORTCUTSPATH}/${CARDID}" "${LOCAL_SHORTCUTSPATH}/${CARDID}" + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Shortcut for $CARDID not found in REMOTE $SYNCSHORTCUTSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + } + + # Sync audiofolder FOLDER + handle_audiofolders() { + if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then + if is_server_reachable ; then + + if exec_for_mode [ ! -d "$SYNCAUDIOFOLDERSPATH" ] ; then + exec_for_mode mkdir "$SYNCAUDIOFOLDERSPATH" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi + + elif exec_for_mode [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ] ; then + sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "UpdateMPC" + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Sync on RFID scan deactivated" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + } + + # Sync full (shortcuts and audiofolders) + handle_full() { + if is_server_reachable ; then + + if exec_for_mode [ ! -d "$SYNCSHORTCUTSPATH" ] ; then + exec_for_mode mkdir "$SYNCSHORTCUTSPATH" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCSHORTCUTSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi + sync_from_server "${SYNCSHORTCUTSPATH}/" "${LOCAL_SHORTCUTSPATH}/" + + fi + + if exec_for_mode [ ! -d "$SYNCAUDIOFOLDERSPATH" ] ; then + exec_for_mode mkdir "$SYNCAUDIOFOLDERSPATH" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi + sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "UpdateMPC" + + fi + + else + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Server is NOT reachable" >> "${PROJROOTPATH}"/logs/debug.log; fi + fi + } + + # Change setting for Sync on RFID scan + handle_changeOnRfidScan() { + case "$VALUE" in + on) + SYNCSHAREDONRFIDSCAN_NEW="TRUE" + ;; + off) + SYNCSHAREDONRFIDSCAN_NEW="FALSE" + ;; + toggle) + if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then + SYNCSHAREDONRFIDSCAN_NEW="FALSE" + else + SYNCSHAREDONRFIDSCAN_NEW="TRUE" + fi + ;; + *) + echo "Unknown VALUE ${VALUE} for COMMAND ${COMMAND}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown VALUE ${VALUE} for COMMAND ${COMMAND}" >> "${PROJROOTPATH}"/logs/debug.log; fi + ;; + esac + + if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to ${SYNCSHAREDONRFIDSCAN_NEW}" >> "${PROJROOTPATH}"/logs/debug.log; fi + sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"${SYNCSHAREDONRFIDSCAN_NEW}\"|g" "${PROJROOTPATH}"/settings/sync_shared.conf + fi + } + + # Change access of file or dir + change_access() { + local file_or_dir="$1" + local group="$2" + local mod="$3" + + sudo chgrp -R "$group" "$file_or_dir" + sudo chmod -R "$mod" "$file_or_dir" + } + + ############################################################# + ############################################################# + + ############################################################# + + case "$COMMAND" in + shortcuts) + handle_shortcuts + ;; + audiofolders) + handle_audiofolders + ;; + full) + handle_full + ;; + changeOnRfidScan) + handle_changeOnRfidScan + ;; + *) + echo "Unknown COMMAND {$COMMAND}" + if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} CARDID ${CARDID} FOLDER ${FOLDER} VALUE ${VALUE}" >> "${PROJROOTPATH}"/logs/debug.log; fi + ;; + esac fi if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh ##" >> "${PROJROOTPATH}"/logs/debug.log; fi diff --git a/scripts/playout_controls.sh b/scripts/playout_controls.sh index 320331f59..a02ba9fd5 100755 --- a/scripts/playout_controls.sh +++ b/scripts/playout_controls.sh @@ -287,7 +287,7 @@ case $COMMAND in # schedule shutdown after VALUE minutes echo "${PATHDATA}/playout_controls.sh -c=shutdownsilent" | at -q q now + ${VALUE} minute fi - ;; + ;; reboot) if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi ${PATHDATA}/resume_play.sh -c=savepos && mpc clear @@ -1138,12 +1138,12 @@ case $COMMAND in dbg "Command requires \"amixer\" as volume manager." fi ;; - sharedsyncfull) - $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=full - ;; - sharedsyncchangeonrfidscan) - $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=changeOnRfidScan -v="$VALUE" - ;; + sharedsyncfull) + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=full + ;; + sharedsyncchangeonrfidscan) + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=changeOnRfidScan -v="$VALUE" + ;; *) echo Unknown COMMAND $COMMAND VALUE $VALUE if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo "Unknown COMMAND ${COMMAND} VALUE ${VALUE}" >> ${PATHDATA}/../logs/debug.log; fi diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 0d773b49a..3cb98bdf3 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -314,24 +314,24 @@ if [ "$CARDID" ]; then $CMDBLUETOOTHTOGGLE) $PATHDATA/playout_controls.sh -c=bluetoothtoggle -v=toggle ;; - $SYNCSHAREDFULL) - $PATHDATA/playout_controls.sh -c=sharedsyncfull - ;; + $SYNCSHAREDFULL) + $PATHDATA/playout_controls.sh -c=sharedsyncfull + ;; $SYNCSHAREDONRFIDSCANTOGGLE) - $PATHDATA/playout_controls.sh -c=sharedsyncchangeonrfidscan -v=toggle - ;; + $PATHDATA/playout_controls.sh -c=sharedsyncchangeonrfidscan -v=toggle + ;; *) # We checked if the card was a special command, seems it wasn't. # Now we expect it to be a trigger for one or more audio file(s). # Let's look at the ID, write a bit of log information and then try to play audio. - - # If enabled sync shortcut $CARDID + + # If enabled sync shortcut $CARDID if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=shortcuts -i="$CARDID" + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=shortcuts -i="$CARDID" fi - # Look for human readable shortcut in folder 'shortcuts' + # Look for human readable shortcut in folder 'shortcuts' # check if CARDID has a text file by the same name - which would contain the human readable folder name if [ -f $PATHDATA/../shared/shortcuts/$CARDID ] then @@ -364,179 +364,179 @@ fi if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "# Attempting to play: $AUDIOFOLDERSPATH/$FOLDER" >> $PATHDATA/../logs/debug.log; fi if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "# Type of play \$VALUE: $VALUE" >> $PATHDATA/../logs/debug.log; fi -# check if $FOLDER is not empty +# check if $FOLDER is not empty if [ ! -z "$FOLDER" ]; then - # If enabled sync audio folder $FOLDER + # If enabled sync audio folder $FOLDER if [ "${SYNCSHAREDENABLED}" == "TRUE" ]; then - $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=audiofolders -d="$FOLDER" + $PATHDATA/../components/synchronisation/sync-shared/sync-shared.sh -c=audiofolders -d="$FOLDER" fi - # check if $FOLDER points to existing directory - if [ -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "\$FOLDER not empty and dir exists: ${AUDIOFOLDERSPATH}/${FOLDER}" >> $PATHDATA/../logs/debug.log; fi - - # if we play a folder the first time, add some sensible information to the folder.conf - if [ ! -f "${AUDIOFOLDERSPATH}/${FOLDER}/folder.conf" ]; then - # now we create a default folder.conf file by calling this script - # with the command param createDefaultFolderConf - # (see script for details) - # the $FOLDER would not need to be passed on, because it is already set in this script - # see inc.writeFolderConfig.sh for details - . $PATHDATA/inc.writeFolderConfig.sh -c=createDefaultFolderConf -d="${FOLDER}" - fi - - # get the name of the last folder played. As mpd doesn't store the name of the last - # playlist, we have to keep track of it via the Latest_Folder_Played file - LASTFOLDER=$(cat $PATHDATA/../settings/Latest_Folder_Played) - LASTPLAYLIST=$(cat $PATHDATA/../settings/Latest_Playlist_Played) - # this might need to go? resume not working... echo ${FOLDER} > $PATHDATA/../settings/Latest_Folder_Played - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTFOLDER: $LASTFOLDER" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: $LASTPLAYLIST" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Checking 'recursive' list? VAR \$VALUE: $VALUE" >> $PATHDATA/../logs/debug.log; fi - - if [ "$VALUE" == "recursive" ]; then - # set path to playlist - # replace subfolder slashes with " % " - PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }-%RCRSV%.m3u" - PLAYLISTNAME="${FOLDER//\//\ %\ }-%RCRSV%" - $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' > "${PLAYLISTPATH}" - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? YES" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" --list 'recursive' > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi - else - # set path to playlist - # replace subfolder slashes with " % " - PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }.m3u" - PLAYLISTNAME="${FOLDER//\//\ %\ }" - $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" > "${PLAYLISTPATH}" - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? NO" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi - fi - - # Second Swipe value - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$SECONDSWIPE: ${SECONDSWIPE}" >> $PATHDATA/../logs/debug.log; fi - # Playlist name - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$PLAYLISTNAME: ${PLAYLISTNAME}" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: ${LASTPLAYLIST}" >> $PATHDATA/../logs/debug.log; fi - - # Setting a VAR to start "play playlist from start" - # This will be changed in the following checks "if this is the second swipe" - PLAYPLAYLIST=yes - - # Check if the second swipe happened - # - The same playlist is cued up ("$LASTPLAYLIST" == "$PLAYLISTNAME") - if [ "$LASTPLAYLIST" == "$PLAYLISTNAME" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Second Swipe DID happen: \$LASTPLAYLIST == \$PLAYLISTNAME" >> $PATHDATA/../logs/debug.log; fi - - # check if - # - $SECONDSWIPE is set to toggle pause/play ("$SECONDSWIPE" == "PAUSE") - # - AND (-a) - # - check the length of the playlist, if =0 then it was cleared before, a state, which should only - # be possible after a reboot ($PLLENGTH -gt 0) - PLLENGTH=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=playlistlength: ).*') - if [ $PLLENGTH -eq 0 ] - then - # after a reboot we want to play the playlist once no matter what the setting is - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Take second wipe as first after fresh boot" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "PAUSE" -a $PLLENGTH -gt 0 ] - then - # The following involves NOT playing the playlist, so we set: - PLAYPLAYLIST=no - - STATE=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=state: ).*') - if [ $STATE == "play" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " MPD playing, pausing the player" >> $PATHDATA/../logs/debug.log; fi - sudo $PATHDATA/playout_controls.sh -c=playerpause &>/dev/null - else - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "MPD not playing, start playing" >> $PATHDATA/../logs/debug.log; fi - sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null - fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: toggle pause/play" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "PLAY" -a $PLLENGTH -gt 0 ] - then - # The following involves NOT playing the playlist, so we set: - PLAYPLAYLIST=no - sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: Resume playback" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "NOAUDIOPLAY" ] - then - # The following involves NOT playing the playlist, so we set: - PLAYPLAYLIST=no - # following needs testing (see https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/914) - # Special case for NOAUDIOPLAY because once the playlist has finished, - # it needs to be noted by the system that the second swipe is like a *first* swipe. - currentSong=`mpc current` - if [[ -z "$currentSong" ]]; then - #end of playlist (EOPL) reached. Ignore last played playlist - PLAYPLAYLIST=yes - fi - - # "$SECONDSWIPE" == "NOAUDIOPLAY" - # "$LASTPLAYLIST" == "$PLAYLISTNAME" => same playlist triggered again - # => do nothing - # echo "do nothing" > /dev/null 2>&1 - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: do nothing" >> $PATHDATA/../logs/debug.log; fi - elif [ "$SECONDSWIPE" == "SKIPNEXT" ] - then - # We will not play the playlist but skip to the next track: - PLAYPLAYLIST=skipnext - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: skip next track" >> $PATHDATA/../logs/debug.log; fi - fi - fi - # now we check if we are still on for playing what we got passed on: - if [ "$PLAYPLAYLIST" == "yes" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "We must play the playlist no matter what: \$PLAYPLAYLIST == yes" >> $PATHDATA/../logs/debug.log; fi - - # Above we already checked if the folder exists -d "$AUDIOFOLDERSPATH/$FOLDER" - # - # the process is as such - because of the recursive play option: - # - each folder can be played. - # - a single folder will create a playlist with the same name as the folder - # - because folders can live inside other folders, the relative path might contain - # slashes (e.g. audiobooks/Moby Dick/) - # - because slashes can not be in the playlist name, slashes are replaced with " % " - # - the "recursive" option means that the content of the folder AND all subfolders - # is being played - # - in this case, the playlist is related to the same folder name, which means we need - # to make a different name for "recursive" playout - # - a recursive playlist has the suffix " %RCRSV%" - keeping it cryptic to avoid clashes - # with a possible "real" name for a folder - # - with this new logic, there are no more SPECIALFORMAT playlists. Live streams and podcasts - # are now all unfolded into the playlist - # - creating the playlist is now done in the php script with parameters: - # $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' - - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi - - # save position of current playing list "stop" - $PATHDATA/playout_controls.sh -c=playerstop - # play playlist - # the variable passed on to play is the playlist name -v (NOT the folder name) - # because (see above) a folder can be played recursively (including subfolders) or flat (only containing files) - # load new playlist and play - $PATHDATA/playout_controls.sh -c=playlistaddplay -v="${PLAYLISTNAME}" -d="${FOLDER}" - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playlistaddplay -v=\"${PLAYLISTNAME}\" -d=\"${FOLDER}\"" >> $PATHDATA/../logs/debug.log; fi - # save latest playlist not to file - sudo echo ${PLAYLISTNAME} > $PATHDATA/../settings/Latest_Playlist_Played - sudo chown pi:www-data $PATHDATA/../settings/Latest_Playlist_Played - sudo chmod 777 $PATHDATA/../settings/Latest_Playlist_Played - fi - if [ "$PLAYPLAYLIST" == "skipnext" ] - then - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Skip to the next track in the playlist: \$PLAYPLAYLIST == skipnext" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi - - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playernext" >> $PATHDATA/../logs/debug.log; fi - $PATHDATA/playout_controls.sh -c=playernext - fi - else - if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Path not found $AUDIOFOLDERSPATH/$FOLDER" >> $PATHDATA/../logs/debug.log; fi - fi + # check if $FOLDER points to existing directory + if [ -d "${AUDIOFOLDERSPATH}/${FOLDER}" ]; then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "\$FOLDER not empty and dir exists: ${AUDIOFOLDERSPATH}/${FOLDER}" >> $PATHDATA/../logs/debug.log; fi + + # if we play a folder the first time, add some sensible information to the folder.conf + if [ ! -f "${AUDIOFOLDERSPATH}/${FOLDER}/folder.conf" ]; then + # now we create a default folder.conf file by calling this script + # with the command param createDefaultFolderConf + # (see script for details) + # the $FOLDER would not need to be passed on, because it is already set in this script + # see inc.writeFolderConfig.sh for details + . $PATHDATA/inc.writeFolderConfig.sh -c=createDefaultFolderConf -d="${FOLDER}" + fi + + # get the name of the last folder played. As mpd doesn't store the name of the last + # playlist, we have to keep track of it via the Latest_Folder_Played file + LASTFOLDER=$(cat $PATHDATA/../settings/Latest_Folder_Played) + LASTPLAYLIST=$(cat $PATHDATA/../settings/Latest_Playlist_Played) + # this might need to go? resume not working... echo ${FOLDER} > $PATHDATA/../settings/Latest_Folder_Played + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTFOLDER: $LASTFOLDER" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: $LASTPLAYLIST" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Checking 'recursive' list? VAR \$VALUE: $VALUE" >> $PATHDATA/../logs/debug.log; fi + + if [ "$VALUE" == "recursive" ]; then + # set path to playlist + # replace subfolder slashes with " % " + PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }-%RCRSV%.m3u" + PLAYLISTNAME="${FOLDER//\//\ %\ }-%RCRSV%" + $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' > "${PLAYLISTPATH}" + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? YES" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" --list 'recursive' > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi + else + # set path to playlist + # replace subfolder slashes with " % " + PLAYLISTPATH="${PLAYLISTSFOLDERPATH}/${FOLDER//\//\ %\ }.m3u" + PLAYLISTNAME="${FOLDER//\//\ %\ }" + $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" > "${PLAYLISTPATH}" + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "recursive? NO" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "$PATHDATA/playlist_recursive_by_folder.php --folder \"${FOLDER}\" > \"${PLAYLISTPATH}\"" >> $PATHDATA/../logs/debug.log; fi + fi + + # Second Swipe value + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$SECONDSWIPE: ${SECONDSWIPE}" >> $PATHDATA/../logs/debug.log; fi + # Playlist name + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$PLAYLISTNAME: ${PLAYLISTNAME}" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Var \$LASTPLAYLIST: ${LASTPLAYLIST}" >> $PATHDATA/../logs/debug.log; fi + + # Setting a VAR to start "play playlist from start" + # This will be changed in the following checks "if this is the second swipe" + PLAYPLAYLIST=yes + + # Check if the second swipe happened + # - The same playlist is cued up ("$LASTPLAYLIST" == "$PLAYLISTNAME") + if [ "$LASTPLAYLIST" == "$PLAYLISTNAME" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Second Swipe DID happen: \$LASTPLAYLIST == \$PLAYLISTNAME" >> $PATHDATA/../logs/debug.log; fi + + # check if + # - $SECONDSWIPE is set to toggle pause/play ("$SECONDSWIPE" == "PAUSE") + # - AND (-a) + # - check the length of the playlist, if =0 then it was cleared before, a state, which should only + # be possible after a reboot ($PLLENGTH -gt 0) + PLLENGTH=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=playlistlength: ).*') + if [ $PLLENGTH -eq 0 ] + then + # after a reboot we want to play the playlist once no matter what the setting is + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Take second wipe as first after fresh boot" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "PAUSE" -a $PLLENGTH -gt 0 ] + then + # The following involves NOT playing the playlist, so we set: + PLAYPLAYLIST=no + + STATE=$(echo -e "status\nclose" | nc -w 1 localhost 6600 | grep -o -P '(?<=state: ).*') + if [ $STATE == "play" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " MPD playing, pausing the player" >> $PATHDATA/../logs/debug.log; fi + sudo $PATHDATA/playout_controls.sh -c=playerpause &>/dev/null + else + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "MPD not playing, start playing" >> $PATHDATA/../logs/debug.log; fi + sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null + fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: toggle pause/play" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "PLAY" -a $PLLENGTH -gt 0 ] + then + # The following involves NOT playing the playlist, so we set: + PLAYPLAYLIST=no + sudo $PATHDATA/playout_controls.sh -c=playerplay &>/dev/null + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: Resume playback" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "NOAUDIOPLAY" ] + then + # The following involves NOT playing the playlist, so we set: + PLAYPLAYLIST=no + # following needs testing (see https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/914) + # Special case for NOAUDIOPLAY because once the playlist has finished, + # it needs to be noted by the system that the second swipe is like a *first* swipe. + currentSong=`mpc current` + if [[ -z "$currentSong" ]]; then + #end of playlist (EOPL) reached. Ignore last played playlist + PLAYPLAYLIST=yes + fi + + # "$SECONDSWIPE" == "NOAUDIOPLAY" + # "$LASTPLAYLIST" == "$PLAYLISTNAME" => same playlist triggered again + # => do nothing + # echo "do nothing" > /dev/null 2>&1 + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: do nothing" >> $PATHDATA/../logs/debug.log; fi + elif [ "$SECONDSWIPE" == "SKIPNEXT" ] + then + # We will not play the playlist but skip to the next track: + PLAYPLAYLIST=skipnext + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Completed: skip next track" >> $PATHDATA/../logs/debug.log; fi + fi + fi + # now we check if we are still on for playing what we got passed on: + if [ "$PLAYPLAYLIST" == "yes" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "We must play the playlist no matter what: \$PLAYPLAYLIST == yes" >> $PATHDATA/../logs/debug.log; fi + + # Above we already checked if the folder exists -d "$AUDIOFOLDERSPATH/$FOLDER" + # + # the process is as such - because of the recursive play option: + # - each folder can be played. + # - a single folder will create a playlist with the same name as the folder + # - because folders can live inside other folders, the relative path might contain + # slashes (e.g. audiobooks/Moby Dick/) + # - because slashes can not be in the playlist name, slashes are replaced with " % " + # - the "recursive" option means that the content of the folder AND all subfolders + # is being played + # - in this case, the playlist is related to the same folder name, which means we need + # to make a different name for "recursive" playout + # - a recursive playlist has the suffix " %RCRSV%" - keeping it cryptic to avoid clashes + # with a possible "real" name for a folder + # - with this new logic, there are no more SPECIALFORMAT playlists. Live streams and podcasts + # are now all unfolded into the playlist + # - creating the playlist is now done in the php script with parameters: + # $PATHDATA/playlist_recursive_by_folder.php --folder "${FOLDER}" --list 'recursive' + + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi + + # save position of current playing list "stop" + $PATHDATA/playout_controls.sh -c=playerstop + # play playlist + # the variable passed on to play is the playlist name -v (NOT the folder name) + # because (see above) a folder can be played recursively (including subfolders) or flat (only containing files) + # load new playlist and play + $PATHDATA/playout_controls.sh -c=playlistaddplay -v="${PLAYLISTNAME}" -d="${FOLDER}" + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playlistaddplay -v=\"${PLAYLISTNAME}\" -d=\"${FOLDER}\"" >> $PATHDATA/../logs/debug.log; fi + # save latest playlist not to file + sudo echo ${PLAYLISTNAME} > $PATHDATA/../settings/Latest_Playlist_Played + sudo chown pi:www-data $PATHDATA/../settings/Latest_Playlist_Played + sudo chmod 777 $PATHDATA/../settings/Latest_Playlist_Played + fi + if [ "$PLAYPLAYLIST" == "skipnext" ] + then + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Skip to the next track in the playlist: \$PLAYPLAYLIST == skipnext" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR FOLDER: $FOLDER" >> $PATHDATA/../logs/debug.log; fi + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " VAR PLAYLISTPATH: $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi + + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playernext" >> $PATHDATA/../logs/debug.log; fi + $PATHDATA/playout_controls.sh -c=playernext + fi + else + if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Path not found $AUDIOFOLDERSPATH/$FOLDER" >> $PATHDATA/../logs/debug.log; fi + fi else if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "var FOLDER empty" >> $PATHDATA/../logs/debug.log; fi fi diff --git a/settings/rfid_trigger_play.conf.sample b/settings/rfid_trigger_play.conf.sample index 6bb7451b0..b9eb6843a 100755 --- a/settings/rfid_trigger_play.conf.sample +++ b/settings/rfid_trigger_play.conf.sample @@ -16,7 +16,7 @@ # A section starts with ## # Example: ## Audio player # A command's description is *above* the command and starts with ### -# Example: +# Example: # ### Stop player # CMDSTOP="%CMDSTOP%" # This structuring was introduced to have a human readable display in the Web UI @@ -146,7 +146,7 @@ TOGGLEWIFI="%TOGGLEWIFI%" ### Read out the Wifi IP over the Phoniebox speakers CMDREADWIFIIP="%CMDREADWIFIIP%" -## Recording audio commands +## Recording audio commands ### Start recording for 10 sec. duration RECORDSTART10="%RECORDSTART10%" ### Start recording for 60 sec. duration From e574191d73f438a7ef45b1b6981df5a72b14b5c6 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:21:39 +0100 Subject: [PATCH 46/54] applied filename convention --- .gitignore | 4 ++-- components/synchronisation/sync-shared/README.md | 4 ++-- ..._configuration.sh => change-configuration.sh} | 16 ++++++++-------- .../sync-shared/install-sync-shared.sh | 2 +- ...hared.conf.sample => sync-shared.conf.sample} | 0 .../synchronisation/sync-shared/sync-shared.sh | 10 +++++----- scripts/rfid_trigger_play.sh | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) rename components/synchronisation/sync-shared/{change_configuration.sh => change-configuration.sh} (88%) rename components/synchronisation/sync-shared/settings/{sync_shared.conf.sample => sync-shared.conf.sample} (100%) diff --git a/.gitignore b/.gitignore index dea85e28b..593e3b75b 100755 --- a/.gitignore +++ b/.gitignore @@ -14,8 +14,8 @@ settings/Playlists_Folders_Path settings/rfid_trigger_play.conf settings/Second_Swipe settings/ShowCover -settings/sync_shared.conf -settings/Sync_Shared_Enabled +settings/sync-shared.conf +settings/sync-shared-enabled settings/version htdocs/config.php scripts/deviceName.txt diff --git a/components/synchronisation/sync-shared/README.md b/components/synchronisation/sync-shared/README.md index dcb05489f..fbb2ab7d8 100644 --- a/components/synchronisation/sync-shared/README.md +++ b/components/synchronisation/sync-shared/README.md @@ -33,12 +33,12 @@ You may also change the settings in the according files directly. ### Settings: -**{INSTALLATION_ROOT}/settings/Sync_Shared_Enabled** +**{INSTALLATION_ROOT}/settings/sync-shared-enabled** Holds the activation state of this feature. Values are "TRUE" or "FALSE" -**{INSTALLATION_ROOT}/settings/sync_shared.conf** +**{INSTALLATION_ROOT}/settings/sync-shared.conf** SYNCSHAREDMODE: The mode to access the server files. SSH or MOUNT diff --git a/components/synchronisation/sync-shared/change_configuration.sh b/components/synchronisation/sync-shared/change-configuration.sh similarity index 88% rename from components/synchronisation/sync-shared/change_configuration.sh rename to components/synchronisation/sync-shared/change-configuration.sh index baa570342..2c4427916 100755 --- a/components/synchronisation/sync-shared/change_configuration.sh +++ b/components/synchronisation/sync-shared/change-configuration.sh @@ -2,7 +2,7 @@ PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJROOTPATH="${PATHDATA}/../../.." -CONFFILE="${PROJROOTPATH}/settings/Sync_Shared_Enabled" +CONFFILE="${PROJROOTPATH}/settings/sync-shared-enabled" SKIP_INITIAL_CHECK="$1" @@ -18,7 +18,7 @@ set_activation() { fi # Let global controls know this feature is enabled - echo -e "\nLet global controls know this feature is ${SETTINGSTATE}. (Sync_Shared_Enabled -> ${SETTINGVALUE})" + echo -e "\nLet global controls know this feature is ${SETTINGSTATE}. (sync-shared-enabled -> ${SETTINGVALUE})" echo "$SETTINGVALUE" > "$CONFFILE" sudo chgrp www-data "$CONFFILE" @@ -27,13 +27,13 @@ set_activation() { init_settings() { # Init config from sample if not present - if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then - cp "${PATHDATA}/settings/sync_shared.conf.sample" "${PROJROOTPATH}/settings/sync_shared.conf" + if [ ! -f "${PROJROOTPATH}/settings/sync-shared.conf" ]; then + cp "${PATHDATA}/settings/sync-shared.conf.sample" "${PROJROOTPATH}/settings/sync-shared.conf" # change the read/write so that later this might also be editable through the web app - sudo chgrp www-data "${PROJROOTPATH}/settings/sync_shared.conf" - sudo chmod 775 "${PROJROOTPATH}/settings/sync_shared.conf" + sudo chgrp www-data "${PROJROOTPATH}/settings/sync-shared.conf" + sudo chmod 775 "${PROJROOTPATH}/settings/sync-shared.conf" fi - . "${PROJROOTPATH}"/settings/sync_shared.conf + . "${PROJROOTPATH}"/settings/sync-shared.conf } set_setting() { @@ -42,7 +42,7 @@ set_setting() { # check if value is set and not equal to the current settings value if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then - sed -i "s|^${SETTINGNAME}=.*|${SETTINGNAME}=\"${SETTINGVALUE}\"|g" "${PROJROOTPATH}/settings/sync_shared.conf" + sed -i "s|^${SETTINGNAME}=.*|${SETTINGNAME}=\"${SETTINGVALUE}\"|g" "${PROJROOTPATH}/settings/sync-shared.conf" echo "New value: \"${SETTINGVALUE}\"" fi } diff --git a/components/synchronisation/sync-shared/install-sync-shared.sh b/components/synchronisation/sync-shared/install-sync-shared.sh index a9e225157..410bfcba2 100755 --- a/components/synchronisation/sync-shared/install-sync-shared.sh +++ b/components/synchronisation/sync-shared/install-sync-shared.sh @@ -21,6 +21,6 @@ sudo chmod ugo+rx "${PATHDATA}/sync-shared.sh" echo -e "\nChecking rsync package" sudo apt install rsync -y -"${PATHDATA}"/change_configuration.sh "SkipInitialCheck" +"${PATHDATA}"/change-configuration.sh "SkipInitialCheck" echo -e "\n\nFINAL NOTE:\nPlease check README.md for further configuration" diff --git a/components/synchronisation/sync-shared/settings/sync_shared.conf.sample b/components/synchronisation/sync-shared/settings/sync-shared.conf.sample similarity index 100% rename from components/synchronisation/sync-shared/settings/sync_shared.conf.sample rename to components/synchronisation/sync-shared/settings/sync-shared.conf.sample diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index c7c20e886..732b8323b 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -42,8 +42,8 @@ if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_s ####################### # Activation status of component sync-shared-from-server SYNCSHAREDENABLED="FALSE" -if [ -f "${PROJROOTPATH}/settings/Sync_Shared_Enabled" ]; then - SYNCSHAREDENABLED=`cat "${PROJROOTPATH}/settings/Sync_Shared_Enabled"` +if [ -f "${PROJROOTPATH}/settings/sync-shared-enabled" ]; then + SYNCSHAREDENABLED=`cat "${PROJROOTPATH}/settings/sync-shared-enabled"` fi @@ -64,12 +64,12 @@ else ############################################################# # Read configuration file - if [ ! -f "${PROJROOTPATH}/settings/sync_shared.conf" ]; then + if [ ! -f "${PROJROOTPATH}/settings/sync-shared.conf" ]; then echo "Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" >> "${PROJROOTPATH}"/logs/debug.log; fi exit fi - . "${PROJROOTPATH}"/settings/sync_shared.conf + . "${PROJROOTPATH}"/settings/sync-shared.conf ############################################################# # Get args from command line (see Usage above) @@ -269,7 +269,7 @@ else if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to ${SYNCSHAREDONRFIDSCAN_NEW}" >> "${PROJROOTPATH}"/logs/debug.log; fi - sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"${SYNCSHAREDONRFIDSCAN_NEW}\"|g" "${PROJROOTPATH}"/settings/sync_shared.conf + sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"${SYNCSHAREDONRFIDSCAN_NEW}\"|g" "${PROJROOTPATH}"/settings/sync-shared.conf fi } diff --git a/scripts/rfid_trigger_play.sh b/scripts/rfid_trigger_play.sh index 3cb98bdf3..8e56c075f 100755 --- a/scripts/rfid_trigger_play.sh +++ b/scripts/rfid_trigger_play.sh @@ -66,8 +66,8 @@ fi ####################### # Activation status of component sync-shared-from-server SYNCSHAREDENABLED="FALSE" -if [ -f $PATHDATA/../settings/Sync_Shared_Enabled ]; then - SYNCSHAREDENABLED=`cat $PATHDATA/../settings/Sync_Shared_Enabled` +if [ -f $PATHDATA/../settings/sync-shared-enabled ]; then + SYNCSHAREDENABLED=`cat $PATHDATA/../settings/sync-shared-enabled` fi if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo "Sync: SYNCSHAREDENABLED=$SYNCSHAREDENABLED" >> $PATHDATA/../logs/debug.log; fi From 90587b75ce61edaf977460bda16440a4f50432f6 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:28:51 +0100 Subject: [PATCH 47/54] refactored filepath to var --- .../sync-shared/change-configuration.sh | 21 ++++++++++--------- .../sync-shared/sync-shared.sh | 7 ++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/components/synchronisation/sync-shared/change-configuration.sh b/components/synchronisation/sync-shared/change-configuration.sh index 2c4427916..078c531dd 100755 --- a/components/synchronisation/sync-shared/change-configuration.sh +++ b/components/synchronisation/sync-shared/change-configuration.sh @@ -2,7 +2,8 @@ PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJROOTPATH="${PATHDATA}/../../.." -CONFFILE="${PROJROOTPATH}/settings/sync-shared-enabled" +STATEFILE="${PROJROOTPATH}/settings/sync-shared-enabled" +CONFFILE="${PROJROOTPATH}/settings/sync-shared.conf" SKIP_INITIAL_CHECK="$1" @@ -20,20 +21,20 @@ set_activation() { # Let global controls know this feature is enabled echo -e "\nLet global controls know this feature is ${SETTINGSTATE}. (sync-shared-enabled -> ${SETTINGVALUE})" - echo "$SETTINGVALUE" > "$CONFFILE" - sudo chgrp www-data "$CONFFILE" - sudo chmod 775 "$CONFFILE" + echo "$SETTINGVALUE" > "$STATEFILE" + sudo chgrp www-data "$STATEFILE" + sudo chmod 775 "$STATEFILE" } init_settings() { # Init config from sample if not present - if [ ! -f "${PROJROOTPATH}/settings/sync-shared.conf" ]; then - cp "${PATHDATA}/settings/sync-shared.conf.sample" "${PROJROOTPATH}/settings/sync-shared.conf" + if [ ! -f "$CONFFILE" ]; then + cp "${PATHDATA}/settings/sync-shared.conf.sample" "$CONFFILE" # change the read/write so that later this might also be editable through the web app - sudo chgrp www-data "${PROJROOTPATH}/settings/sync-shared.conf" - sudo chmod 775 "${PROJROOTPATH}/settings/sync-shared.conf" + sudo chgrp www-data "$CONFFILE" + sudo chmod 775 "$CONFFILE" fi - . "${PROJROOTPATH}"/settings/sync-shared.conf + . "$CONFFILE" } set_setting() { @@ -42,7 +43,7 @@ set_setting() { # check if value is set and not equal to the current settings value if [ ! -z "$SETTINGVALUE" -a "${!SETTINGNAME}" != "$SETTINGVALUE" ]; then - sed -i "s|^${SETTINGNAME}=.*|${SETTINGNAME}=\"${SETTINGVALUE}\"|g" "${PROJROOTPATH}/settings/sync-shared.conf" + sed -i "s|^${SETTINGNAME}=.*|${SETTINGNAME}=\"${SETTINGVALUE}\"|g" "$CONFFILE" echo "New value: \"${SETTINGVALUE}\"" fi } diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index 732b8323b..02ef1a3c9 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -64,12 +64,13 @@ else ############################################################# # Read configuration file - if [ ! -f "${PROJROOTPATH}/settings/sync-shared.conf" ]; then + CONFFILE="${PROJROOTPATH}/settings/sync-shared.conf" + if [ ! -f "$CONFFILE" ]; then echo "Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Settingsfile does not exist. Please read ${PATHDATA}/README.md to set configuration" >> "${PROJROOTPATH}"/logs/debug.log; fi exit fi - . "${PROJROOTPATH}"/settings/sync-shared.conf + . "$CONFFILE" ############################################################# # Get args from command line (see Usage above) @@ -269,7 +270,7 @@ else if [ ! -z "${SYNCSHAREDONRFIDSCAN_NEW}" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Set SYNCSHAREDONRFIDSCAN to ${SYNCSHAREDONRFIDSCAN_NEW}" >> "${PROJROOTPATH}"/logs/debug.log; fi - sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"${SYNCSHAREDONRFIDSCAN_NEW}\"|g" "${PROJROOTPATH}"/settings/sync-shared.conf + sed -i "s|^SYNCSHAREDONRFIDSCAN=.*|SYNCSHAREDONRFIDSCAN=\"${SYNCSHAREDONRFIDSCAN_NEW}\"|g" "$CONFFILE" fi } From 135b5f0ba0cf4206843e70ec428d4e91c326bf35 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sun, 26 Feb 2023 03:55:50 +0100 Subject: [PATCH 48/54] updated README added special thanks section --- components/synchronisation/sync-shared/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/synchronisation/sync-shared/README.md b/components/synchronisation/sync-shared/README.md index fbb2ab7d8..490f4bfc2 100644 --- a/components/synchronisation/sync-shared/README.md +++ b/components/synchronisation/sync-shared/README.md @@ -53,3 +53,7 @@ SYNCSHAREDREMOTETIMOUT: The timeout to reach the server (in seconds) (used to ch SYNCSHAREDREMOTEPATH: The path to the shared files to sync (without trailing slash) (remote path for SSH mode or local path for MOUNT mode). e.g. "/mnt/Phoniebox" SYNCSHAREDONRFIDSCAN: Holds the activation state of the optional feature "RFID scan sync". Values are "TRUE" or "FALSE" + + +## Special Thanks +inspired by [splitti - phoniebox_rsync](https://github.com/splitti/phoniebox_rsync) From 6384a09a950d86da5461e27157b0e98effdea1e6 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Wed, 1 Mar 2023 02:26:37 +0100 Subject: [PATCH 49/54] fixed db update after sync for spotify version --- .../synchronisation/sync-shared/sync-shared.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index 02ef1a3c9..3cbb14d17 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -141,7 +141,7 @@ else sync_from_server() { local src_path="$1" local dst_path="$2" - local update_mpc="$3" + local update_db="$3" if is_mode_ssh ; then # Quote source path to deal with whitespaces in paths @@ -159,9 +159,16 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: files copied. change access of files" >> "${PROJROOTPATH}"/logs/debug.log; fi change_access "$dst_path" "www-data" "775" - if [ ! -z "$update_mpc" ]; then + if [ ! -z "$update_db" ]; then if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: update database" >> "${PROJROOTPATH}"/logs/debug.log; fi - sudo mpc update --wait "$dst_path" > /dev/null 2>&1 + # if spotify edition is installed, update via mopidy as mpc update doesnt work + if [ "$EDITION" == "plusSpotify" ]; then + # don't stop / start service (like in payout_controls scan) as all mpd calls after will fail + # (or an artifical sleep time would be needed to make sure mpd is started) + sudo mopidyctl local scan > /dev/null 2>&1 + else + mpc --wait update "$dst_path" > /dev/null 2>&1 + fi fi else @@ -204,7 +211,7 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi elif exec_for_mode [ -d "${SYNCAUDIOFOLDERSPATH}/${FOLDER}" ] ; then - sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "UpdateMPC" + sync_from_server "${SYNCAUDIOFOLDERSPATH}/${FOLDER}/" "${LOCAL_AUDIOFOLDERSPATH}/${FOLDER}/" "UpdateDB" else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder $FOLDER not found in REMOTE $SYNCAUDIOFOLDERSPATH" >> "${PROJROOTPATH}"/logs/debug.log; fi @@ -237,7 +244,7 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH} does not exist. created" >> "${PROJROOTPATH}"/logs/debug.log; fi else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Folder ${SYNCAUDIOFOLDERSPATH}" >> "${PROJROOTPATH}"/logs/debug.log; fi - sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "UpdateMPC" + sync_from_server "${SYNCAUDIOFOLDERSPATH}/" "${LOCAL_AUDIOFOLDERSPATH}/" "UpdateDB" fi From 40ff9ce0be1f0a09981a04301ba454db7ee9909d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Wed, 1 Mar 2023 02:57:37 +0100 Subject: [PATCH 50/54] install packages for openssh-client added --- components/synchronisation/sync-shared/install-sync-shared.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/synchronisation/sync-shared/install-sync-shared.sh b/components/synchronisation/sync-shared/install-sync-shared.sh index 410bfcba2..aa2f96e05 100755 --- a/components/synchronisation/sync-shared/install-sync-shared.sh +++ b/components/synchronisation/sync-shared/install-sync-shared.sh @@ -20,6 +20,8 @@ sudo chmod ugo+rx "${PATHDATA}/sync-shared.sh" # Make sure required packages are installed echo -e "\nChecking rsync package" sudo apt install rsync -y +echo -e "\nChecking ssh package" +sudo apt install openssh-client -y "${PATHDATA}"/change-configuration.sh "SkipInitialCheck" From cd57af1010213374843f1a9d9b0c780610d9bd7d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Wed, 1 Mar 2023 21:52:33 +0100 Subject: [PATCH 51/54] updated comments --- .../sync-shared/sync-shared.sh | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index 3cbb14d17..128bf00a7 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -1,9 +1,12 @@ #!/bin/bash -# Description +# This script synchronises shortcuts and/or audiofolders from a server to the local storage. -# Set the date and time of now -NOW=`date +%Y-%m-%d.%H:%M:%S` +# VALID COMMANDS: +# shortcuts (with -i) +# audiofolders (with -d) +# full +# changeOnRfidScan(with -v=on | off | toogle) # USAGE EXAMPLES: # @@ -16,16 +19,11 @@ NOW=`date +%Y-%m-%d.%H:%M:%S` # sync full: # ./sync_shared.sh -c=full # -# sync toggle SyncOnRfidScan: +# toggle sync OnRfidScan: # ./sync_shared.sh -c=changeOnRfidScan -v=toggle -# -# -# VALID COMMANDS: -# shortcuts (with -i) -# audiofolders (with -d) -# full -# changeOnRfidScan(with -v=on | off | toogle) +# Set the date and time of now +NOW=`date +%Y-%m-%d.%H:%M:%S` # The absolute path to the folder which contains all the scripts. # Unless you are working with symlinks, leave the following line untouched. @@ -40,7 +38,7 @@ PROJROOTPATH="${PATHDATA}/../../.." if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "########### SCRIPT sync_shared.sh (${NOW}) ##" >> "${PROJROOTPATH}"/logs/debug.log; fi ####################### -# Activation status of component sync-shared-from-server +# Activation status of component sync-shared SYNCSHAREDENABLED="FALSE" if [ -f "${PROJROOTPATH}/settings/sync-shared-enabled" ]; then SYNCSHAREDENABLED=`cat "${PROJROOTPATH}/settings/sync-shared-enabled"` @@ -54,7 +52,7 @@ else if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: enabled" >> "${PROJROOTPATH}"/logs/debug.log; fi ############################################################# - # Read global configuration file (and create if not exists) + # Read global configuration file if [ ! -f "${PROJROOTPATH}/settings/global.conf" ]; then echo "Global settingsfile does not exist. Please call the script from a defined entrypoint" if [ "${DEBUG_sync_shared_sh}" == "TRUE" ]; then echo "Sync: Global settingsfile does not exist. Please call the script from a defined entrypoint" >> "${PROJROOTPATH}"/logs/debug.log; fi @@ -93,7 +91,6 @@ else LOCAL_SHORTCUTSPATH="${PROJROOTPATH}/shared/shortcuts" LOCAL_AUDIOFOLDERSPATH="${AUDIOFOLDERSPATH%/}" - ############################################################# ############################################################# # Functions @@ -176,7 +173,7 @@ else fi } - # Sync shortcut CARDID + # Sync shortcut for CARDID handle_shortcuts() { if [ "$SYNCSHAREDONRFIDSCAN" == "TRUE" ]; then if is_server_reachable ; then @@ -282,6 +279,7 @@ else } # Change access of file or dir + # only changes group as the user should be correctly taken from caller context (logged in user or service) change_access() { local file_or_dir="$1" local group="$2" @@ -291,11 +289,10 @@ else sudo chmod -R "$mod" "$file_or_dir" } - ############################################################# ############################################################# ############################################################# - + # Main switch case "$COMMAND" in shortcuts) handle_shortcuts From ee43b275c05ca398a2c7cdf30680b6764146e977 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Wed, 1 Mar 2023 22:13:16 +0100 Subject: [PATCH 52/54] Update README.md --- .../synchronisation/sync-shared/README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/components/synchronisation/sync-shared/README.md b/components/synchronisation/sync-shared/README.md index 490f4bfc2..6dd665615 100644 --- a/components/synchronisation/sync-shared/README.md +++ b/components/synchronisation/sync-shared/README.md @@ -1,24 +1,25 @@ # Synchronize shared files from a server This component activates a synchronisation from a server to the Phoniebox for the shared folders 'shortcuts' and 'audiofolders'. -This can be initiated as a full-sync command and optionally on every RFID scan for the particular CardID (and corresponding audiofolder). +This can be initiated as a "full-sync" command and optionally on every RFID scan for the particular CardID (and corresponding audiofolder). -For the full-sync bind a CardId to the command "SYNCSHAREDFULL". +For the "full-sync" bind a CardId to the command "SYNCSHAREDFULL". For the "RFID scan sync" feature, activate the option in the configuration. There is also a command to toggle the activation of the "RFID scan sync" feature via CardId (bind to command "SYNCSHAREDONRFIDSCANTOGGLE"). ## Synchronisation -The synchronisation will be FROM a server TO the Phoniebox, overriding (or deleting) existing files. So configuration of audiofiles / -folders and CardIds made via WebUi will be lost after sync. -If you want to make the initial setup via WebUi copy the files and use it as a base for the server. +The synchronisation will be FROM a server TO the Phoniebox, overriding existing files. So configuration of audiofiles / -folders made locally will be lost after sync. +If you want to make the initial setup e.g. via WebUi copy the files and use it as a base for the server. The "folder.conf" files will be synced if present on the server, but not delete if not (they are automatically generated on playback). -If the feature "RFID scan sync" is activated, there will be a check on every RFID scan against the server if a matching shortcut and audiofolder is found and the changes will be transfered. -The playback will be delayed for the time the data are transfered (see "SYNCSHAREDFULL" to use a full-sync if a lot of new files have been added). -If the server is not reachable the check will be aborted after the timeout. So an unreachable server will cause a delay (see command "SYNCSHAREDONRFIDSCANTOGGLE" to toggle activation state). - To access the files on the server two modes are supported: SSH or MOUNT. Please make sure you have the correct access rights for the source and use key-based authentication for SSH. +### RFID scan sync +If the feature "RFID scan sync" is activated, there will be a check on every RFID scan against the server if a matching shortcut and audiofolder is found and the changes will be transfered. +The playback will be delayed for the time the data are transfered (see "SYNCSHAREDFULL" to use a full-sync if a lot of new files have been added). +If the server is not reachable the check will be aborted after the timeout. So an unreachable server will cause a delay (see command "SYNCSHAREDONRFIDSCANTOGGLE" to toggle activation state). +Deleted shortcuts / audiofolders (not the contained items) will not be purged locally if deleted on remote. This is also true for changed shortcuts (the old audiofolder / -files will remain). To also delete not existing items us a "full-sync". ## Installation From cd0e33931ba3b0c353e54a9f927ae0c8692527d8 Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 2 Mar 2023 01:32:43 +0100 Subject: [PATCH 53/54] fixed logic for subfolder shortcuts --- components/synchronisation/sync-shared/sync-shared.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/synchronisation/sync-shared/sync-shared.sh b/components/synchronisation/sync-shared/sync-shared.sh index 128bf00a7..dca8f07bf 100755 --- a/components/synchronisation/sync-shared/sync-shared.sh +++ b/components/synchronisation/sync-shared/sync-shared.sh @@ -121,6 +121,11 @@ else is_server_reachable() { return `nc -z "$SYNCSHAREDREMOTESERVER" -w "$SYNCSHAREDREMOTETIMOUT" "$SYNCSHAREDREMOTEPORT"` } + + # Check if first parameter ends with the character second parameter + endswith() { + case "$1" in *"$2") true;; *) false;; esac; + } # Sync all files from source to destination # Some special options are needed as the 'folder.conf' file will be generated on playback. @@ -148,6 +153,9 @@ else local ssh_conn="${SYNCSHAREDREMOTESSHUSER}@${SYNCSHAREDREMOTESERVER}:" fi + if endswith "$dst_path" "/" ; then + mkdir -p "$dst_path" + fi rsync_changes=$(rsync --compress --recursive --itemize-changes --safe-links --times --omit-dir-times --delete --prune-empty-dirs --filter='-rp folder.conf' --exclude='placeholder' --exclude='.*/' --exclude='@*/' "${ssh_port[@]}" "${ssh_conn}""${src_path}" "${dst_path}") if [ $? -eq 0 -a -n "$rsync_changes" ]; then @@ -164,7 +172,7 @@ else # (or an artifical sleep time would be needed to make sure mpd is started) sudo mopidyctl local scan > /dev/null 2>&1 else - mpc --wait update "$dst_path" > /dev/null 2>&1 + mpc update --wait > /dev/null 2>&1 fi fi From 78a5b854badf33d8d9ba974df8138b3ffc9a0d3d Mon Sep 17 00:00:00 2001 From: AlvinSchiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 2 Mar 2023 01:58:32 +0100 Subject: [PATCH 54/54] Update README.md --- components/synchronisation/sync-shared/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/synchronisation/sync-shared/README.md b/components/synchronisation/sync-shared/README.md index 6dd665615..d55b61b0c 100644 --- a/components/synchronisation/sync-shared/README.md +++ b/components/synchronisation/sync-shared/README.md @@ -1,8 +1,9 @@ # Synchronize shared files from a server This component activates a synchronisation from a server to the Phoniebox for the shared folders 'shortcuts' and 'audiofolders'. -This can be initiated as a "full-sync" command and optionally on every RFID scan for the particular CardID (and corresponding audiofolder). +It allows to manage the shortcuts and audiofiles of one to many Phonieboxes in a central place (e.g. NAS, one main Phoniebox, ...) in the network, but keeps the possibility to play audio offline once the data where synced. +The synchronisation can be initiated as a "full-sync" command and optionally on every RFID scan for the particular CardID (and corresponding audiofolder). For the "full-sync" bind a CardId to the command "SYNCSHAREDFULL". For the "RFID scan sync" feature, activate the option in the configuration. There is also a command to toggle the activation of the "RFID scan sync" feature via CardId (bind to command "SYNCSHAREDONRFIDSCANTOGGLE").