mirror of
https://github.com/Febbweiss/rclone_script.git
synced 2026-03-04 22:25:36 +00:00
changed function log
removed function debug fixed function deleteFileFromRemote
This commit is contained in:
108
rclone_script.sh
108
rclone_script.sh
@@ -12,6 +12,7 @@ UNDERLINE=$(tput smul)
|
|||||||
# include settings file
|
# include settings file
|
||||||
config=~/scripts/rclone_script/rclone_script.ini
|
config=~/scripts/rclone_script/rclone_script.ini
|
||||||
source ${config}
|
source ${config}
|
||||||
|
logLevel=2
|
||||||
|
|
||||||
|
|
||||||
# parameters
|
# parameters
|
||||||
@@ -27,24 +28,36 @@ command="$5"
|
|||||||
####################
|
####################
|
||||||
|
|
||||||
function log ()
|
function log ()
|
||||||
|
# Prints messages of different severeties to a logfile
|
||||||
|
# Each message will look something like this:
|
||||||
|
# <TIMESTAMP> <SEVERITY> <CALLING_FUNCTION> <MESSAGE>
|
||||||
|
# needs a set variable $logLevel
|
||||||
|
# -1 > No logging at all
|
||||||
|
# 0 > prints ERRORS only
|
||||||
|
# 1 > prints ERRORS and WARNINGS
|
||||||
|
# 2 > prints ERRORS, WARNINGS and INFO
|
||||||
|
# 3 > prints ERRORS, WARNINGS, INFO and DEBUGGING
|
||||||
|
# needs a set variable $log pointing to a file
|
||||||
|
# Usage
|
||||||
|
# log 0 "This is an ERROR Message"
|
||||||
|
# log 1 "This is a WARNING"
|
||||||
|
# log 2 "This is just an INFO"
|
||||||
|
# log 3 "This is a DEBUG message"
|
||||||
{
|
{
|
||||||
severity=$1
|
severity=$1
|
||||||
message=$2
|
message=$2
|
||||||
printf "$(date +%FT%T%:z):\t${severity}:\t${message}\n" >> ${logfile}
|
|
||||||
}
|
if (( ${severity} <= ${logLevel} ))
|
||||||
|
then
|
||||||
function debug ()
|
case ${severity} in
|
||||||
{
|
0) level="ERROR" ;;
|
||||||
log "DEBUG" "direction: ${direction}"
|
1) level="WARNING" ;;
|
||||||
log "DEBUG" "system: ${system}"
|
2) level="INFO" ;;
|
||||||
log "DEBUG" "emulator: ${emulator}"
|
3) level="DEBUG" ;;
|
||||||
log "DEBUG" "rom: ${rom}"
|
esac
|
||||||
log "DEBUG" "command: ${command}"
|
|
||||||
log "DEBUG" "remotebasedir: ${remotebasedir}"
|
printf "$(date +%FT%T%:z):\t${level}\t${0##*/}\t${FUNCNAME[1]}\t${message}\n" >> ${logfile}
|
||||||
log "DEBUG" "rompath: ${rompath}"
|
fi
|
||||||
log "DEBUG" "romfilename: ${romfilename}"
|
|
||||||
log "DEBUG" "romfilebase: ${romfilebase}"
|
|
||||||
log "DEBUG" "romfileext: ${romfileext}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function killOtherNotification ()
|
function killOtherNotification ()
|
||||||
@@ -52,11 +65,11 @@ function killOtherNotification ()
|
|||||||
# get PID of other PNGVIEW process
|
# get PID of other PNGVIEW process
|
||||||
otherPID=$(pgrep --full pngview)
|
otherPID=$(pgrep --full pngview)
|
||||||
|
|
||||||
if [ "${debug}" = "1" ]; then log "DEBUG" "Other PIDs: ${otherPID}"; fi
|
if [ "${debug}" = "1" ]; then log 3 "Other PIDs: ${otherPID}"; fi
|
||||||
|
|
||||||
if [ "${otherPID}" != "" ]
|
if [ "${otherPID}" != "" ]
|
||||||
then
|
then
|
||||||
if [ "${debug}" = "1" ]; then log "DEBUG" "Kill other PNGVIEW ${otherPID}"; fi
|
if [ "${debug}" = "1" ]; then log 3 "Kill other PNGVIEW ${otherPID}"; fi
|
||||||
|
|
||||||
kill ${otherPID}
|
kill ${otherPID}
|
||||||
fi
|
fi
|
||||||
@@ -131,7 +144,7 @@ function getTypeOfRemote ()
|
|||||||
# list all remotes and their type
|
# list all remotes and their type
|
||||||
remotes=$(rclone listremotes -l)
|
remotes=$(rclone listremotes -l)
|
||||||
|
|
||||||
# get line wiht RETROPIE remote
|
# get line with RETROPIE remote
|
||||||
retval=$(grep -i "^retropie:" <<< ${remotes})
|
retval=$(grep -i "^retropie:" <<< ${remotes})
|
||||||
|
|
||||||
remoteType="${retval#*:}"
|
remoteType="${retval#*:}"
|
||||||
@@ -148,28 +161,28 @@ function getAvailableConnection ()
|
|||||||
gatewayIP=$(ip r | grep default | cut -d " " -f 3)
|
gatewayIP=$(ip r | grep default | cut -d " " -f 3)
|
||||||
if [ "${gatewayIP}" == "" ]
|
if [ "${gatewayIP}" == "" ]
|
||||||
then
|
then
|
||||||
log "INFO" "Gateway could not be detected"
|
log 2 "Gateway could not be detected"
|
||||||
return 2
|
return 2
|
||||||
else
|
else
|
||||||
log "INFO" "Gateway IP: ${gatewayIP}"
|
log 2 "Gateway IP: ${gatewayIP}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ping -q -w 1 -c 1 ${gatewayIP} > /dev/null
|
ping -q -w 1 -c 1 ${gatewayIP} > /dev/null
|
||||||
if [[ $? -eq 0 ]]
|
if [[ $? -eq 0 ]]
|
||||||
then
|
then
|
||||||
log "INFO" "Gateway PING successful"
|
log 2 "Gateway PING successful"
|
||||||
else
|
else
|
||||||
log "INFO" "Gateway could not be PINGed"
|
log 2 "Gateway could not be PINGed"
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ping -q -w 1 -c 1 "www.google.com" > /dev/null
|
ping -q -w 1 -c 1 "www.google.com" > /dev/null
|
||||||
if [[ $? -eq 0 ]]
|
if [[ $? -eq 0 ]]
|
||||||
then
|
then
|
||||||
log "INFO" "www.google.com PING successful"
|
log 2 "www.google.com PING successful"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
log "INFO" "www.google.com could not be PINGed"
|
log 2 "www.google.com could not be PINGed"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -187,15 +200,15 @@ function downloadSaves ()
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "INFO" "Started ${system}/${romfilename} "
|
log 2 "Started ${system}/${romfilename} "
|
||||||
log "INFO" "Downloading saves and states for ${system}/${romfilename} from ${remoteType}..."
|
log 2 "Downloading saves and states for ${system}/${romfilename} from ${remoteType}..."
|
||||||
showNotification "Downloading saves and states from ${remoteType}..."
|
showNotification "Downloading saves and states from ${remoteType}..."
|
||||||
|
|
||||||
getAvailableConnection
|
getAvailableConnection
|
||||||
availableConnection=$?
|
availableConnection=$?
|
||||||
if [[ ${availableConnection} -gt ${neededConnection} ]]
|
if [[ ${availableConnection} -gt ${neededConnection} ]]
|
||||||
then
|
then
|
||||||
log "ERROR" "Needed Connection not available. Needed ${neededConnection}, available ${availableConnection}"
|
log 0 "Needed Connection not available. Needed ${neededConnection}, available ${availableConnection}"
|
||||||
|
|
||||||
case ${neededConnection} in
|
case ${neededConnection} in
|
||||||
0) showNotification "Downloading saves and states from ${remoteType}... No Internet connection available" "red" "" "" "" "forced" ;;
|
0) showNotification "Downloading saves and states from ${remoteType}... No Internet connection available" "red" "" "" "" "forced" ;;
|
||||||
@@ -214,10 +227,10 @@ function downloadSaves ()
|
|||||||
|
|
||||||
if [ "${remotefiles}" = "" ]
|
if [ "${remotefiles}" = "" ]
|
||||||
then # no remote files found
|
then # no remote files found
|
||||||
log "INFO" "No remote files found"
|
log 2 "No remote files found"
|
||||||
showNotification "Downloading saves and states from ${remoteType}... No remote files found"
|
showNotification "Downloading saves and states from ${remoteType}... No remote files found"
|
||||||
else # remote files found
|
else # remote files found
|
||||||
log "INFO" "Found remote files"
|
log 2 "Found remote files"
|
||||||
|
|
||||||
# download saves and states to corresponding ROM
|
# download saves and states to corresponding ROM
|
||||||
rclone copy retropie:${remotebasedir}/${system} ~/RetroPie/saves/${system} --include "${filter}.*" --update >> ${logfile}
|
rclone copy retropie:${remotebasedir}/${system} ~/RetroPie/saves/${system} --include "${filter}.*" --update >> ${logfile}
|
||||||
@@ -225,15 +238,15 @@ function downloadSaves ()
|
|||||||
|
|
||||||
if [ "${retval}" = "0" ]
|
if [ "${retval}" = "0" ]
|
||||||
then
|
then
|
||||||
log "INFO" "Done"
|
log 2 "Done"
|
||||||
showNotification "Downloading saves and states from ${remoteType}... Done" "green"
|
showNotification "Downloading saves and states from ${remoteType}... Done" "green"
|
||||||
else
|
else
|
||||||
log "ERROR" "Saves and states could not be downloaded"
|
log 2 "Saves and states could not be downloaded"
|
||||||
showNotification "Downloading saves and states from ${remoteType}... ERROR" "red" "" "" "" "forced"
|
showNotification "Downloading saves and states from ${remoteType}... ERROR" "red" "" "" "" "forced"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else # error with RCLONE
|
else # error with RCLONE
|
||||||
log "ERROR" "Saves and states could not be downloaded"
|
log 0 "Saves and states could not be downloaded"
|
||||||
showNotification "Downloading saves and states from ${remoteType}... ERROR" "red" "" "" "" "forced"
|
showNotification "Downloading saves and states from ${remoteType}... ERROR" "red" "" "" "" "forced"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -246,15 +259,15 @@ function uploadSaves ()
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "INFO" "Stopped ${system}/${romfilename} "
|
log 2 "Stopped ${system}/${romfilename} "
|
||||||
log "INFO" "Uploading saves and states for ${system}/${romfilename} to ${remoteType}..."
|
log 2 "Uploading saves and states for ${system}/${romfilename} to ${remoteType}..."
|
||||||
showNotification "Uploading saves and states to ${remoteType}..."
|
showNotification "Uploading saves and states to ${remoteType}..."
|
||||||
|
|
||||||
getAvailableConnection
|
getAvailableConnection
|
||||||
availableConnection=$?
|
availableConnection=$?
|
||||||
if [[ ${availableConnection} -gt ${neededConnection} ]]
|
if [[ ${availableConnection} -gt ${neededConnection} ]]
|
||||||
then
|
then
|
||||||
log "ERROR" "Needed Connection not available. Needed ${neededConnection}, available ${availableConnection}"
|
log 0 "Needed Connection not available. Needed ${neededConnection}, available ${availableConnection}"
|
||||||
|
|
||||||
case ${neededConnection} in
|
case ${neededConnection} in
|
||||||
0) showNotification "Uploading saves and states to ${remoteType}... No Internet connection available" "red" "" "" "" "forced" ;;
|
0) showNotification "Uploading saves and states to ${remoteType}... No Internet connection available" "red" "" "" "" "forced" ;;
|
||||||
@@ -268,7 +281,7 @@ function uploadSaves ()
|
|||||||
|
|
||||||
if [ "${localfiles}" = "" ]
|
if [ "${localfiles}" = "" ]
|
||||||
then # no local files found
|
then # no local files found
|
||||||
log "INFO" "No local saves and states found"
|
log 2 "No local saves and states found"
|
||||||
showNotification "Uploading saves and states to ${remoteType}... No local files found"
|
showNotification "Uploading saves and states to ${remoteType}... No local files found"
|
||||||
else # local files found
|
else # local files found
|
||||||
# upload saves and states to corresponding ROM
|
# upload saves and states to corresponding ROM
|
||||||
@@ -277,10 +290,10 @@ function uploadSaves ()
|
|||||||
|
|
||||||
if [ "${retval}" = "0" ]
|
if [ "${retval}" = "0" ]
|
||||||
then
|
then
|
||||||
log "INFO" "Done"
|
log 2 "Done"
|
||||||
showNotification "Uploading saves and states to ${remoteType}... Done" "green"
|
showNotification "Uploading saves and states to ${remoteType}... Done" "green"
|
||||||
else
|
else
|
||||||
log "ERROR" "saves and states could not be uploaded"
|
log 2 "saves and states could not be uploaded"
|
||||||
showNotification "Uploading saves and states to ${remoteType}... ERROR" "red" "" "" "" "forced"
|
showNotification "Uploading saves and states to ${remoteType}... ERROR" "red" "" "" "" "forced"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -297,20 +310,23 @@ function deleteFileFromRemote ()
|
|||||||
# 2 > file could not be deleted
|
# 2 > file could not be deleted
|
||||||
{
|
{
|
||||||
fileToDelete="$1"
|
fileToDelete="$1"
|
||||||
|
log 2 "File to delete: retropie:${remotebasedir}/${fileToDelete}"
|
||||||
|
|
||||||
getAvailableConnection
|
getAvailableConnection
|
||||||
availableConnection=$?
|
availableConnection=$?
|
||||||
if [[ ${availableConnection} -gt ${neededConnection} ]]
|
if [[ ${availableConnection} -gt ${neededConnection} ]]
|
||||||
then
|
then
|
||||||
log "ERROR" "Needed Connection not available. Needed ${neededConnection}, available ${availableConnection}"
|
log 0 "Needed Connection not available. Needed ${neededConnection}, available ${availableConnection}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rclone delete retropie:${remotebasedir}/${fileToDelete} 2>&1 >> ${logfile}
|
rclone delete "retropie:${remotebasedir}/${fileToDelete}" 2>&1 >> ${logfile}
|
||||||
if [[ $? -eq 0 ]]
|
if [[ $? -eq 0 ]]
|
||||||
then
|
then
|
||||||
|
log 2 "File deleted successfully"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
log 0 "File could not be deleted. Error Code $?"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -319,7 +335,17 @@ function deleteFileFromRemote ()
|
|||||||
# MAIN #
|
# MAIN #
|
||||||
########
|
########
|
||||||
|
|
||||||
if [ "${debug}" = "1" ]; then debug; fi
|
#if [ "${debug}" = "1" ]; then debug; fi
|
||||||
|
log 3 "direction: ${direction}"
|
||||||
|
log 3 "system: ${system}"
|
||||||
|
log 3 "emulator: ${emulator}"
|
||||||
|
log 3 "rom: ${rom}"
|
||||||
|
log 3 "command: ${command}"
|
||||||
|
log 3 "remotebasedir: ${remotebasedir}"
|
||||||
|
log 3 "rompath: ${rompath}"
|
||||||
|
log 3 "romfilename: ${romfilename}"
|
||||||
|
log 3 "romfilebase: ${romfilebase}"
|
||||||
|
log 3 "romfileext: ${romfileext}"
|
||||||
|
|
||||||
if [ "${direction}" == "up" ] && [ "${system}" != "kodi" ]
|
if [ "${direction}" == "up" ] && [ "${system}" != "kodi" ]
|
||||||
then
|
then
|
||||||
|
|||||||
Reference in New Issue
Block a user