mirror of
https://github.com/Febbweiss/rclone_script.git
synced 2026-03-04 22:25:36 +00:00
rclone_script-install.sh
* fixed config parameter showNotifications * added config parameter syncOnStartStop rclone_script-menu.sh * moved full sync here * made parameter showNotifications toggleable * made parameter syncOnStartStop toggleable rclone_script.sh * extended function showNotification * extended function downloadSaves * extended function uploadSaves * removed function doFullSync
This commit is contained in:
@@ -1124,7 +1124,8 @@ function 9aSaveConfiguration ()
|
|||||||
printf "$(date +%FT%T%:z):\t9aSaveConfiguration\tSTART\n" >> "${logfile}"
|
printf "$(date +%FT%T%:z):\t9aSaveConfiguration\tSTART\n" >> "${logfile}"
|
||||||
|
|
||||||
echo "remotebasedir=${remotebasedir}" > ~/scripts/rclone_script/rclone_script.ini
|
echo "remotebasedir=${remotebasedir}" > ~/scripts/rclone_script/rclone_script.ini
|
||||||
echo "shownotifications=${shownotifications}" >> ~/scripts/rclone_script/rclone_script.ini
|
echo "showNotifications=${shownotifications}" >> ~/scripts/rclone_script/rclone_script.ini
|
||||||
|
echo "syncOnStartStop=\"TRUE\"" >> ~/scripts/rclone_script/rclone_script.ini
|
||||||
echo "logfile=~/scripts/rclone_script/rclone_script.log" >> ~/scripts/rclone_script/rclone_script.ini
|
echo "logfile=~/scripts/rclone_script/rclone_script.log" >> ~/scripts/rclone_script/rclone_script.ini
|
||||||
echo "debug=0" >> ~/scripts/rclone_script/rclone_script.ini
|
echo "debug=0" >> ~/scripts/rclone_script/rclone_script.ini
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ NORMAL="\Zn"
|
|||||||
BLACK="\Z0"
|
BLACK="\Z0"
|
||||||
RED="\Z1"
|
RED="\Z1"
|
||||||
GREEN="\Z2"
|
GREEN="\Z2"
|
||||||
YELLOW="\Z3"
|
YELLOW="\Z3\Zb"
|
||||||
BLUE="\Z4"
|
BLUE="\Z4"
|
||||||
MAGENTA="\Z5"
|
MAGENTA="\Z5"
|
||||||
CYAN="\Z6"
|
CYAN="\Z6"
|
||||||
@@ -15,28 +15,166 @@ REVERSE="\Zr"
|
|||||||
UNDERLINE="\Zu"
|
UNDERLINE="\Zu"
|
||||||
|
|
||||||
|
|
||||||
|
# include settings file
|
||||||
|
config=~/scripts/rclone_script/rclone_script.ini
|
||||||
|
source ${config}
|
||||||
|
|
||||||
|
|
||||||
|
####################
|
||||||
|
# HELPER FUNCTIONS #
|
||||||
|
####################
|
||||||
|
|
||||||
|
function log ()
|
||||||
|
{
|
||||||
|
severity=$1
|
||||||
|
message=$2
|
||||||
|
printf "$(date +%FT%T%:z):\t${severity}:\t${message}\n" >> ${logfile}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTypeOfRemote ()
|
||||||
|
{
|
||||||
|
# list all remotes and their type
|
||||||
|
remotes=$(rclone listremotes -l)
|
||||||
|
|
||||||
|
# get line wiht RETROPIE remote
|
||||||
|
retval=$(grep -i "^retropie:" <<< ${remotes})
|
||||||
|
|
||||||
|
remoteType="${retval#*:}"
|
||||||
|
remoteType=$(echo ${remoteType} | xargs)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatusOfParameters ()
|
||||||
|
{
|
||||||
|
if [ "${syncOnStartStop}" == "TRUE" ]
|
||||||
|
then
|
||||||
|
statusSyncOnStartStop="${GREEN}ENABLED${NORMAL}"
|
||||||
|
else
|
||||||
|
statusSyncOnStartStop="${RED}DISABLED${NORMAL}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${showNotifications}" == "TRUE" ]
|
||||||
|
then
|
||||||
|
statusShowNotifications="${GREEN}ENABLED${NORMAL}"
|
||||||
|
else
|
||||||
|
statusShowNotifications="${RED}DISABLED${NORMAL}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveConfig ()
|
||||||
|
{
|
||||||
|
echo "remotebasedir=${remotebasedir}" > ${config}
|
||||||
|
echo "showNotifications=${showNotifications}" >> ${config}
|
||||||
|
echo "syncOnStartStop=${syncOnStartStop}" >> ${config}
|
||||||
|
echo "logfile=~/scripts/rclone_script/rclone_script.log" >> ${config}
|
||||||
|
echo "debug=0" >> ${config}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##################
|
||||||
|
# MENU FUNCTIONS #
|
||||||
|
##################
|
||||||
|
|
||||||
|
# Show the main menu. Return here anytime another dialog is closed
|
||||||
function main_menu ()
|
function main_menu ()
|
||||||
{
|
{
|
||||||
local choice
|
local choice="1"
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
|
getStatusOfParameters
|
||||||
|
|
||||||
choice=$(dialog \
|
choice=$(dialog \
|
||||||
--stdout \
|
--stdout \
|
||||||
--ascii-lines \
|
--colors \
|
||||||
--backtitle "RCLONE_SCRIPT menu" \
|
--backtitle "RCLONE_SCRIPT menu" \
|
||||||
--title "main menu" \
|
--title "main menu" \
|
||||||
|
--default-item "${choice}" \
|
||||||
--menu "\nWhat do you want to do?" 25 75 20 \
|
--menu "\nWhat do you want to do?" 25 75 20 \
|
||||||
1 "Full sync" \
|
1 "Full sync" \
|
||||||
9 "uninstall"
|
2 "Toggle \"Synchronize saves on start / stop\" (currently ${statusSyncOnStartStop})" \
|
||||||
|
3 "Toggle \"Show notifications on sync\" (currently ${statusShowNotifications})" \
|
||||||
|
"" ""\
|
||||||
|
9 "uninstall RCLONE_SCRIPT"
|
||||||
)
|
)
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) ~/scripts/rclone_script/rclone_script.sh "full" ;;
|
1) doFullSync ;;
|
||||||
|
2) toggleSyncOnStartStop ;;
|
||||||
|
3) toggleShowNotifications ;;
|
||||||
9) ~/scripts/rclone_script/rclone_script-uninstall.sh ;;
|
9) ~/scripts/rclone_script/rclone_script-uninstall.sh ;;
|
||||||
*) break ;;
|
*) break ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Syncs all files in both directions, only transferring newer files
|
||||||
|
function doFullSync ()
|
||||||
|
{
|
||||||
|
local tmpfile=~/scripts/rclone_script/tmp-sync.txt
|
||||||
|
|
||||||
|
getTypeOfRemote
|
||||||
|
printf "\nStarted full sync...\n\n" > ${tmpfile}
|
||||||
|
log "INFO" "Started full sync..."
|
||||||
|
|
||||||
|
# start sync process in background
|
||||||
|
{
|
||||||
|
# Download newer files from remote to local
|
||||||
|
printf "Downloading newer files from retropie:${remotebasedir} (${remoteType}) to ~/RetroPie/saves/...\n"
|
||||||
|
rclone copy retropie:${remotebasedir}/ ~/RetroPie/saves/ --update --verbose 2>&1
|
||||||
|
|
||||||
|
# Upload newer files from local to remote
|
||||||
|
printf "Uploading newer files from ~/RetroPie/saves/ to retropie:${remotebasedir} (${remoteType})...\n"
|
||||||
|
rclone copy ~/RetroPie/saves/ retropie:${remotebasedir}/ --update --verbose 2>&1
|
||||||
|
|
||||||
|
printf "Done\n"
|
||||||
|
} >> ${tmpfile} & # capture output of background process
|
||||||
|
|
||||||
|
dialog \
|
||||||
|
--backtitle "${backtitle}" \
|
||||||
|
--title "Doing full sync..." \
|
||||||
|
--colors \
|
||||||
|
--no-collapse \
|
||||||
|
--cr-wrap \
|
||||||
|
--tailbox ${tmpfile} 40 120
|
||||||
|
|
||||||
|
wait
|
||||||
|
|
||||||
|
cat ${tmpfile} >> ${logfile}
|
||||||
|
rm ${tmpfile}
|
||||||
|
|
||||||
|
log "INFO" "Finished full sync..."
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSyncOnStartStop ()
|
||||||
|
{
|
||||||
|
if [ "${syncOnStartStop}" == "TRUE" ]
|
||||||
|
then
|
||||||
|
syncOnStartStop="FALSE"
|
||||||
|
else
|
||||||
|
syncOnStartStop="TRUE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
saveConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleShowNotifications ()
|
||||||
|
{
|
||||||
|
if [ "${showNotifications}" == "TRUE" ]
|
||||||
|
then
|
||||||
|
showNotifications="FALSE"
|
||||||
|
else
|
||||||
|
showNotifications="TRUE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
saveConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
########
|
||||||
|
# MAIN #
|
||||||
|
########
|
||||||
|
|
||||||
|
# make puTTY draw fancy lines
|
||||||
|
export NCURSES_NO_UTF8_ACS=1
|
||||||
|
|
||||||
main_menu
|
main_menu
|
||||||
@@ -10,7 +10,8 @@ UNDERLINE=$(tput smul)
|
|||||||
|
|
||||||
|
|
||||||
# include settings file
|
# include settings file
|
||||||
source ~/scripts/rclone_script/rclone_script.ini
|
config=~/scripts/rclone_script/rclone_script.ini
|
||||||
|
source ${config}
|
||||||
|
|
||||||
|
|
||||||
# parameters
|
# parameters
|
||||||
@@ -21,14 +22,18 @@ rom="$4"
|
|||||||
command="$5"
|
command="$5"
|
||||||
|
|
||||||
|
|
||||||
log ()
|
####################
|
||||||
|
# HELPER FUNCTIONS #
|
||||||
|
####################
|
||||||
|
|
||||||
|
function log ()
|
||||||
{
|
{
|
||||||
severity=$1
|
severity=$1
|
||||||
message=$2
|
message=$2
|
||||||
printf "$(date +%FT%T%:z):\t${severity}:\t${message}\n" >> ${logfile}
|
printf "$(date +%FT%T%:z):\t${severity}:\t${message}\n" >> ${logfile}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug ()
|
function debug ()
|
||||||
{
|
{
|
||||||
log "DEBUG" "direction: ${direction}"
|
log "DEBUG" "direction: ${direction}"
|
||||||
log "DEBUG" "system: ${system}"
|
log "DEBUG" "system: ${system}"
|
||||||
@@ -42,7 +47,7 @@ debug ()
|
|||||||
log "DEBUG" "romfileext: ${romfileext}"
|
log "DEBUG" "romfileext: ${romfileext}"
|
||||||
}
|
}
|
||||||
|
|
||||||
killOtherNotification ()
|
function killOtherNotification ()
|
||||||
{
|
{
|
||||||
# get PID of other PNGVIEW process
|
# get PID of other PNGVIEW process
|
||||||
otherPID=$(pgrep --full pngview)
|
otherPID=$(pgrep --full pngview)
|
||||||
@@ -57,8 +62,14 @@ killOtherNotification ()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
showNotification ()
|
function showNotification ()
|
||||||
{
|
{
|
||||||
|
# Quit here, if Notifications are not to be shown and they are not forced
|
||||||
|
if [ "${showNotifications}" == "FALSE" ] && [ "$6" != "force" ]
|
||||||
|
then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
message="$1"
|
message="$1"
|
||||||
|
|
||||||
if [ "$2" = "" ]
|
if [ "$2" = "" ]
|
||||||
@@ -101,7 +112,7 @@ showNotification ()
|
|||||||
nohup pngview -b 0 -l 10000 ~/scripts/rclone_script/rclone_script-notification.png -x ${posx} -y ${posy} -t ${timeout} &>/dev/null &
|
nohup pngview -b 0 -l 10000 ~/scripts/rclone_script/rclone_script-notification.png -x ${posx} -y ${posy} -t ${timeout} &>/dev/null &
|
||||||
}
|
}
|
||||||
|
|
||||||
getROMFileName ()
|
function getROMFileName ()
|
||||||
{
|
{
|
||||||
rompath="${rom%/*}" # directory containing $rom
|
rompath="${rom%/*}" # directory containing $rom
|
||||||
romfilename="${rom##*/}" # filename of $rom, including extension
|
romfilename="${rom##*/}" # filename of $rom, including extension
|
||||||
@@ -109,13 +120,13 @@ getROMFileName ()
|
|||||||
romfileext="${romfilename#*.}" # extension of $rom
|
romfileext="${romfilename#*.}" # extension of $rom
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareFilter ()
|
function prepareFilter ()
|
||||||
{
|
{
|
||||||
filter="${romfilebase//\[/\\[}"
|
filter="${romfilebase//\[/\\[}"
|
||||||
filter="${filter//\]/\\]}"
|
filter="${filter//\]/\\]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
getTypeOfRemote ()
|
function getTypeOfRemote ()
|
||||||
{
|
{
|
||||||
# list all remotes and their type
|
# list all remotes and their type
|
||||||
remotes=$(rclone listremotes -l)
|
remotes=$(rclone listremotes -l)
|
||||||
@@ -127,8 +138,19 @@ getTypeOfRemote ()
|
|||||||
remoteType=$(echo ${remoteType} | xargs)
|
remoteType=$(echo ${remoteType} | xargs)
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadSaves ()
|
|
||||||
|
##################
|
||||||
|
# SYNC FUNCTIONS #
|
||||||
|
##################
|
||||||
|
|
||||||
|
function downloadSaves ()
|
||||||
{
|
{
|
||||||
|
if [ "${syncOnStartStop}" == "FALSE" ]
|
||||||
|
then
|
||||||
|
showNotification "!!! Synchronization is currently disabled !!!" "red" "" "" "" "forced"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
log "INFO" "Started ${romfilename} (${system})"
|
log "INFO" "Started ${romfilename} (${system})"
|
||||||
log "INFO" "Downloading saves and states from ${remoteType}..."
|
log "INFO" "Downloading saves and states from ${remoteType}..."
|
||||||
showNotification "Downloading saves and states from ${remoteType}..."
|
showNotification "Downloading saves and states from ${remoteType}..."
|
||||||
@@ -167,8 +189,14 @@ downloadSaves ()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadSaves ()
|
function uploadSaves ()
|
||||||
{
|
{
|
||||||
|
if [ "${syncOnStartStop}" == "FALSE" ]
|
||||||
|
then
|
||||||
|
showNotification "!!! Synchronization is currently disabled !!!" "red" "" "" "" "forced"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
log "INFO" "Stopped ${romfilename} (${system})"
|
log "INFO" "Stopped ${romfilename} (${system})"
|
||||||
log "INFO" "Uploading saves and states to ${remoteType}..."
|
log "INFO" "Uploading saves and states to ${remoteType}..."
|
||||||
showNotification "Uploading saves and states to ${remoteType}..."
|
showNotification "Uploading saves and states to ${remoteType}..."
|
||||||
@@ -195,28 +223,10 @@ uploadSaves ()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
doFullSync ()
|
|
||||||
{
|
|
||||||
# header
|
|
||||||
printf "${UNDERLINE}Full synchronization\n\n"
|
|
||||||
|
|
||||||
# Download newer files from remote to local
|
|
||||||
printf "${NORMAL}Downloading newer files from ${YELLOW}${YELLOW}retropie:${remotebasedir} (${remoteType}) ${NORMAL}to ${YELLOW}~/RetroPie/saves/${NORMAL}...\n"
|
|
||||||
rclone copy retropie:${remotebasedir}/ ~/RetroPie/saves/ --update --verbose
|
|
||||||
printf "${GREEN}Done\n"
|
|
||||||
|
|
||||||
printf "\n"
|
|
||||||
|
|
||||||
# Upload newer files from local to remote
|
|
||||||
printf "${NORMAL}Uploading newer files from ${YELLOW}~/RetroPie/saves/${NORMAL} to ${YELLOW}${YELLOW}retropie:${remotebasedir} (${remoteType})${NORMAL} ...\n"
|
|
||||||
rclone copy ~/RetroPie/saves/ retropie:${remotebasedir}/ --update --verbose
|
|
||||||
printf "${GREEN}Done\n"
|
|
||||||
|
|
||||||
printf "\n"
|
|
||||||
printf "${NORMAL}Returning to EmulationStation in ${YELLOW}10 seconds ${NORMAL}...\n"
|
|
||||||
read -t 10
|
|
||||||
}
|
|
||||||
|
|
||||||
|
########
|
||||||
|
# MAIN #
|
||||||
|
########
|
||||||
|
|
||||||
if [ "${debug}" = "1" ]; then debug; fi
|
if [ "${debug}" = "1" ]; then debug; fi
|
||||||
|
|
||||||
@@ -235,9 +245,3 @@ then
|
|||||||
getTypeOfRemote
|
getTypeOfRemote
|
||||||
downloadSaves
|
downloadSaves
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${direction}" == "full" ]
|
|
||||||
then
|
|
||||||
getTypeOfRemote
|
|
||||||
doFullSync
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user