rclone_script-install-dialog.sh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. #!/bin/bash
  2. # define colors for output
  3. NORMAL="\Zn"
  4. BLACK="\Z0"
  5. RED="\Z1"
  6. GREEN="\Z2"
  7. YELLOW="\Z3"
  8. BLUE="\Z4"
  9. MAGENTA="\Z5"
  10. CYAN="\Z6"
  11. WHITE="\Z7"
  12. BOLD="\Zb"
  13. REVERSE="\Zr"
  14. UNDERLINE="\Zu"
  15. # global variables
  16. url="https://raw.githubusercontent.com/Jandalf81/rclone_script"
  17. branch="beta"
  18. remotebasedir = ""
  19. backtitle="RCLONE_SCRIPT installer"
  20. # Welcome dialog
  21. dialog \
  22. --backtitle "${backtitle}" \
  23. --title "Welcome" \
  24. --ascii-lines \
  25. --colors \
  26. --no-collapse \
  27. --cr-wrap \
  28. --yesno \
  29. "\nThis script will configure RetroPie so that your savefiles and statefiles are synchronized with a remote destination. Several packages and scripts will be installed, see\n\n https://github.com/Jandalf81/rclone_script/blob/master/ReadMe.md\n\nfor a rundown.\n\nAre you sure you wish to continue?" \
  30. 28 110 2>&1 > /dev/tty \
  31. || exit
  32. # Warn the user if they are using the BETA branch
  33. function dialogBetaWarning ()
  34. {
  35. dialog \
  36. --backtitle "${backtitle}" \
  37. --title "Beta Warning" \
  38. --ascii-lines \
  39. --colors \
  40. --no-collapse \
  41. --cr-wrap \
  42. --yesno \
  43. "\n${RED}${UNDERLINE}WARNING!${NORMAL}\n\nYou are about to install a beta version!\nAre you ${RED}REALLY${NORMAL} sure you want to continue?" \
  44. 10 50 2>&1 > /dev/tty \
  45. || exit
  46. }
  47. # Installer
  48. function installer ()
  49. {
  50. local retval
  51. initSteps
  52. dialogShowProgress 0
  53. # 1a. Testing for RCLONE binary
  54. updateStep "1a" "in progress" 0
  55. 1aTestRCLONE
  56. if [[ $? -eq 0 ]]
  57. then
  58. updateStep "1a" "found" 5
  59. updateStep "1b" "skipped" 10
  60. else
  61. updateStep "1a" "not found" 5
  62. # 1b. Getting RCLONE binary
  63. updateStep "1b" "in progress" 5
  64. 1bInstallRCLONE
  65. if [[ $? -eq 0 ]]
  66. then
  67. updateStep "1b" "done" 10
  68. else
  69. updateStep "1b" "failed" 5
  70. fi
  71. fi
  72. # 1c. Testing RCLONE configuration
  73. updateStep "1c" "in progress" 10
  74. 1cTestRCLONEremote
  75. if [[ $? -eq 0 ]]
  76. then
  77. updateStep "1c" "found" 15
  78. updateStep "1d" "skipped" 20
  79. else
  80. updateStep "1c" "not found" 15
  81. # 1d. Create RCLONE remote
  82. updateStep "1d" "in progress" 15
  83. 1dCreateRCLONEremote
  84. updateStep "1d" "done" 20
  85. fi
  86. }
  87. # Initialize array $STEPS()
  88. # OUTPUT
  89. # $steps()
  90. function initSteps ()
  91. {
  92. steps[1]="1. RCLONE"
  93. steps[2]=" 1a. Testing for RCLONE binary [ waiting... ]"
  94. steps[3]=" 1b. Getting RCLONE binary [ waiting... ]"
  95. steps[4]=" 1c. Testing RCLONE remote [ waiting... ]"
  96. steps[5]=" 1d. Create RCLONE remote [ waiting... ]"
  97. steps[6]="2. PNGVIEW"
  98. steps[7]=" 2a. Testing for PNGVIEW binary [ waiting... ]"
  99. steps[8]=" 2b. Getting PNGVIEW source [ waiting... ]"
  100. steps[9]=" 2c. Compiling PNGVIEW [ waiting... ]"
  101. steps[10]="3. IMAGEMAGICK"
  102. steps[11]=" 3a. Testing for IMAGEMAGICK [ waiting... ]"
  103. steps[12]=" 3b. Getting IMAGEMAGICK [ waiting... ]"
  104. steps[13]="4. RCLONE_SCRIPT"
  105. steps[14]=" 4a. Getting RCLONE_SCRIPT [ waiting... ]"
  106. steps[15]=" 4b. Creating RCLONE_SCRIPT menu item [ waiting... ]"
  107. steps[16]=" 4c. Configure RCLONE_SCRIPT [ waiting... ]"
  108. steps[17]="5. RUNCOMMAND"
  109. steps[18]=" 5a. RUNCOMMAND-ONSTART [ waiting... ]"
  110. steps[19]=" 5b. RUNCOMMAND-ONEND [ waiting... ]"
  111. steps[20]="6. Local SAVEFILE directory"
  112. steps[21]=" 6a. Test for local SAVEFILE directory [ waiting... ]"
  113. steps[22]=" 6b. Create local SAVEFILE directory [ waiting... ]"
  114. steps[23]="7. Remote SAVEFILE directory"
  115. steps[24]=" 7a. Test for local SAVEFILE directory [ waiting... ]"
  116. steps[25]=" 7b. Create local SAVEFILE directory [ waiting... ]"
  117. steps[26]="8. Configure RETROARCH"
  118. steps[27]=" 8a. Setting local SAVEFILE directory [ waiting... ]"
  119. steps[28]="9. Finalizing"
  120. steps[29]=" 9a. Saving configuration [ waiting... ]"
  121. }
  122. # Build progress from array $STEPS()
  123. # INPUT
  124. # $steps()
  125. # OUTPUT
  126. # $progress
  127. function buildProgress ()
  128. {
  129. progress=""
  130. for ((i=0; i<=${#steps[*]}; i++))
  131. do
  132. progress="${progress}${steps[i]}\n"
  133. done
  134. }
  135. # Show Progress dialog
  136. # INPUT
  137. # 1 > Percentage to show in dialog
  138. # $backtitle
  139. # $progress
  140. function dialogShowProgress ()
  141. {
  142. local percent="$1"
  143. buildProgress
  144. echo "${percent}" | dialog \
  145. --stdout \
  146. --colors \
  147. --ascii-lines \
  148. --no-collapse \
  149. --cr-wrap \
  150. --backtitle "${backtitle}" \
  151. --title "Installer" \
  152. --gauge "${progress}" 36 90 0 \
  153. 2>&1 > /dev/tty
  154. sleep 1
  155. }
  156. # Update item of $STEPS() and show updated progress dialog
  157. # INPUT
  158. # 1 > Number of step to update
  159. # 2 > New status for step
  160. # 3 > Percentage to show in progress dialog
  161. # $steps()
  162. # OUTPUT
  163. # $steps()
  164. function updateStep ()
  165. {
  166. local step="$1"
  167. local newStatus="$2"
  168. local percent="$3"
  169. local oldline
  170. local newline
  171. # translate and colorize $NEWSTATUS
  172. case "${newStatus}" in
  173. "waiting") newStatus="[ ${NORMAL}WAITING...${NORMAL} ]" ;;
  174. "in progress") newStatus="[ ${NORMAL}IN PROGRESS${NORMAL} ]" ;;
  175. "done") newStatus="[ ${GREEN}DONE${NORMAL} ]" ;;
  176. "found") newStatus="[ ${GREEN}FOUND${NORMAL} ]" ;;
  177. "not found") newStatus="[ ${RED}NOT FOUND${NORMAL} ]" ;;
  178. "failed") newStatus="[ ${RED}FAILED${NORMAL} ]" ;;
  179. "skipped") newStatus="[ ${YELLOW}${BOLD}SKIPPED${NORMAL} ]" ;;
  180. *) newStatus="[ ${RED}UNDEFINED${NORMAL} ]" ;;
  181. esac
  182. # search $STEP in $STEPS
  183. for ((i=0; i<${#steps[*]}; i++))
  184. do
  185. if [[ ${steps[i]} =~ .*$step.* ]]
  186. then
  187. # update $STEP with $NEWSTATUS
  188. oldline="${steps[i]}"
  189. oldline="${oldline%%[*}"
  190. newline="${oldline}${newStatus}"
  191. steps[i]="${newline}"
  192. break
  193. fi
  194. done
  195. # show progress dialog
  196. dialogShowProgress ${percent}
  197. }
  198. # Checks if RCLONE is installed
  199. # RETURN
  200. # 0 > RCLONE is installed
  201. # 1 > RCLONE is not installed
  202. function 1aTestRCLONE ()
  203. {
  204. if [ -f /usr/bin/rclone ]
  205. then
  206. return 0
  207. else
  208. return 1
  209. fi
  210. }
  211. # Installs RCLONE
  212. # RETURN
  213. # 0 > RCLONE has been installed
  214. # 1 > Error while installing RCLONE
  215. function 1bInstallRCLONE ()
  216. {
  217. # TODO get RCLONE for 64bit
  218. { # try
  219. # get binary
  220. wget -q -P ~ https://downloads.rclone.org/rclone-current-linux-arm.zip &&
  221. unzip -q ~/rclone-current-linux-arm.zip -d ~ &&
  222. cd ~/rclone-v* &&
  223. # move binary
  224. retval=$(sudo mv rclone /usr/bin 2>&1) &&
  225. retval=$(sudo chown root:root /usr/bin/rclone 2>&1) &&
  226. retval=$(sudo chmod 755 /usr/bin/rclone 2>&1) &&
  227. cd ~ &&
  228. # remove temp files
  229. rm ~/rclone-current-linux-arm.zip > /dev/null &&
  230. rm -r ~/rclone-v* > /dev/null &&
  231. return 0
  232. } || { #catch
  233. # remove temp files
  234. rm ~/rclone-current-linux-arm.zip > /dev/null &&
  235. rm -r ~/rclone-v* > /dev/null &&
  236. return 1
  237. }
  238. }
  239. # Checks if there's a RCLONE remote called RETROPIE
  240. # RETURN
  241. # 0 > remote RETROPIE has been found
  242. # 1 > no remote RETROPIE found
  243. function 1cTestRCLONEremote ()
  244. {
  245. local remotes=$(rclone listremotes)
  246. local retval=$(grep -i "^retropie:" <<< ${remotes})
  247. if [ "${retval}" == "retropie:" ]
  248. then
  249. return 0
  250. else
  251. return 1
  252. fi
  253. }
  254. # Tells the user to create a new RCLONE remote called RETROPIE
  255. # RETURN
  256. # 0 > remote RETROPIE has been created (no other OUTPUT possible)
  257. function 1dCreateRCLONEremote ()
  258. {
  259. dialog \
  260. --stdout \
  261. --colors \
  262. --ascii-lines \
  263. --no-collapse \
  264. --cr-wrap \
  265. --backtitle "${backtitle}" \
  266. --title "Installer" \
  267. --msgbox "\nPlease create a new remote within RCLONE now. Name that remote ${RED}retropie${NORMAL}. Please consult the RCLONE documentation for further information:\n https://www.rclone.org\n\nOpening RCLONE CONFIG now..." 20 50 \
  268. 2>&1 > /dev/tty
  269. rclone config
  270. 1cTestRCLONEremote
  271. if [[ $? -eq 1 ]]
  272. then
  273. dialog \
  274. --stdout \
  275. --colors \
  276. --ascii-lines \
  277. --no-collapse \
  278. --cr-wrap \
  279. --backtitle "${backtitle}" \
  280. --title "Installer" \
  281. --msgbox "\nNo remote ${RED}retropie${NORMAL} found.\nPlease try again." 20 50 \
  282. 2>&1 > /dev/tty
  283. 1dCreateRCLONEremote
  284. else
  285. return 0
  286. fi
  287. }
  288. # main
  289. if [ "${branch}" == "beta" ]
  290. then
  291. dialogBetaWarning
  292. fi
  293. installer