rclone_script-menu.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/bin/bash
  2. NORMAL="\Zn"
  3. BLACK="\Z0"
  4. RED="\Z1"
  5. GREEN="\Z2"
  6. YELLOW="\Z3\Zb"
  7. BLUE="\Z4"
  8. MAGENTA="\Z5"
  9. CYAN="\Z6"
  10. WHITE="\Z7"
  11. BOLD="\Zb"
  12. REVERSE="\Zr"
  13. UNDERLINE="\Zu"
  14. # include settings file
  15. config=~/scripts/rclone_script/rclone_script.ini
  16. source ${config}
  17. ####################
  18. # HELPER FUNCTIONS #
  19. ####################
  20. function log ()
  21. {
  22. severity=$1
  23. message=$2
  24. printf "$(date +%FT%T%:z):\t${severity}:\t${message}\n" >> ${logfile}
  25. }
  26. function getTypeOfRemote ()
  27. {
  28. # list all remotes and their type
  29. remotes=$(rclone listremotes -l)
  30. # get line wiht RETROPIE remote
  31. retval=$(grep -i "^retropie:" <<< ${remotes})
  32. remoteType="${retval#*:}"
  33. remoteType=$(echo ${remoteType} | xargs)
  34. }
  35. function getStatusOfParameters ()
  36. {
  37. if [ "${syncOnStartStop}" == "TRUE" ]
  38. then
  39. statusSyncOnStartStop="${GREEN}ENABLED${NORMAL}"
  40. else
  41. statusSyncOnStartStop="${RED}DISABLED${NORMAL}"
  42. fi
  43. if [ "${showNotifications}" == "TRUE" ]
  44. then
  45. statusShowNotifications="${GREEN}ENABLED${NORMAL}"
  46. else
  47. statusShowNotifications="${RED}DISABLED${NORMAL}"
  48. fi
  49. }
  50. function saveConfig ()
  51. {
  52. echo "remotebasedir=${remotebasedir}" > ${config}
  53. echo "showNotifications=${showNotifications}" >> ${config}
  54. echo "syncOnStartStop=${syncOnStartStop}" >> ${config}
  55. echo "logfile=~/scripts/rclone_script/rclone_script.log" >> ${config}
  56. echo "debug=0" >> ${config}
  57. }
  58. ##################
  59. # MENU FUNCTIONS #
  60. ##################
  61. # Show the main menu. Return here anytime another dialog is closed
  62. function main_menu ()
  63. {
  64. local choice="1"
  65. while true
  66. do
  67. getStatusOfParameters
  68. choice=$(dialog \
  69. --stdout \
  70. --colors \
  71. --backtitle "RCLONE_SCRIPT menu" \
  72. --title "main menu" \
  73. --default-item "${choice}" \
  74. --menu "\nWhat do you want to do?" 25 75 20 \
  75. 1 "Full synchronization of all savefiles and statefiles" \
  76. 2 "Toggle \"Synchronize saves on start / stop\" (currently ${statusSyncOnStartStop})" \
  77. 3 "Toggle \"Show notifications on sync\" (currently ${statusShowNotifications})" \
  78. "" ""\
  79. 9 "uninstall RCLONE_SCRIPT"
  80. )
  81. case "$choice" in
  82. 1) doFullSync ;;
  83. 2) toggleSyncOnStartStop ;;
  84. 3) toggleShowNotifications ;;
  85. 9) ~/scripts/rclone_script/rclone_script-uninstall.sh ;;
  86. *) break ;;
  87. esac
  88. done
  89. }
  90. # Syncs all files in both directions, only transferring newer files
  91. function doFullSync ()
  92. {
  93. local tmpfile=~/scripts/rclone_script/tmp-sync.txt
  94. getTypeOfRemote
  95. printf "\nStarted full sync...\n\n" > ${tmpfile}
  96. log "INFO" "Started full sync..."
  97. # start sync process in background
  98. {
  99. # Download newer files from remote to local
  100. printf "Downloading newer files from retropie:${remotebasedir} (${remoteType}) to ~/RetroPie/saves/...\n"
  101. rclone copy retropie:${remotebasedir}/ ~/RetroPie/saves/ --update --verbose 2>&1
  102. # Upload newer files from local to remote
  103. printf "Uploading newer files from ~/RetroPie/saves/ to retropie:${remotebasedir} (${remoteType})...\n"
  104. rclone copy ~/RetroPie/saves/ retropie:${remotebasedir}/ --update --verbose 2>&1
  105. printf "Done\n"
  106. } >> ${tmpfile} & # capture output of background process
  107. dialog \
  108. --backtitle "${backtitle}" \
  109. --title "Doing full sync..." \
  110. --colors \
  111. --no-collapse \
  112. --cr-wrap \
  113. --tailbox ${tmpfile} 40 120
  114. wait
  115. cat ${tmpfile} >> ${logfile}
  116. rm ${tmpfile}
  117. log "INFO" "Finished full sync..."
  118. }
  119. function toggleSyncOnStartStop ()
  120. {
  121. if [ "${syncOnStartStop}" == "TRUE" ]
  122. then
  123. syncOnStartStop="FALSE"
  124. else
  125. syncOnStartStop="TRUE"
  126. fi
  127. saveConfig
  128. }
  129. function toggleShowNotifications ()
  130. {
  131. if [ "${showNotifications}" == "TRUE" ]
  132. then
  133. showNotifications="FALSE"
  134. else
  135. showNotifications="TRUE"
  136. fi
  137. saveConfig
  138. }
  139. ########
  140. # MAIN #
  141. ########
  142. # make puTTY draw fancy lines
  143. export NCURSES_NO_UTF8_ACS=1
  144. main_menu