rclone_script-install-dialog.sh 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. #!/bin/bash
  2. # define colors for output
  3. NORMAL="\Zn"
  4. BLACK="\Z0"
  5. RED="\Z1"
  6. GREEN="\Z2"
  7. YELLOW="\Z3\Zb"
  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. # configuration variables
  19. remotebasedir=""
  20. shownotifications=""
  21. backtitle="RCLONE_SCRIPT installer"
  22. ##################
  23. # WELCOME DIALOG #
  24. ##################
  25. dialog \
  26. --backtitle "${backtitle}" \
  27. --title "Welcome" \
  28. --ascii-lines \
  29. --colors \
  30. --no-collapse \
  31. --cr-wrap \
  32. --yesno \
  33. "\nThis script will configure RetroPie so that your savefiles and statefiles will be ${YELLOW}synchronized with a remote destination${NORMAL}. Several packages and scripts will be installed, see\n\n https://github.com/Jandalf81/rclone_script/blob/master/ReadMe.md\n\nfor a rundown. In short, any time you ${GREEN}start${NORMAL} or ${RED}stop${NORMAL} a ROM the savefiles and savestates for that ROM will be ${GREEN}down-${NORMAL} and ${RED}uploaded${NORMAL} ${GREEN}from${NORMAL} and ${RED}to${NORMAL} a remote destination. To do so, RetroPie will be configured to put all savefiles and statefiles in distinct directories, seperated from the ROMS directories. If you already have some savefiles there, you will need to ${YELLOW}move them manually${NORMAL} after installation.\n\nAre you sure you wish to continue?" \
  34. 20 90 2>&1 > /dev/tty \
  35. || exit
  36. ####################
  37. # DIALOG FUNCTIONS #
  38. ####################
  39. # Warn the user if they are using the BETA branch
  40. function dialogBetaWarning ()
  41. {
  42. dialog \
  43. --backtitle "${backtitle}" \
  44. --title "Beta Warning" \
  45. --ascii-lines \
  46. --colors \
  47. --no-collapse \
  48. --cr-wrap \
  49. --yesno \
  50. "\n${RED}${UNDERLINE}WARNING!${NORMAL}\n\nYou are about to install a beta version!\nAre you ${RED}REALLY${NORMAL} sure you want to continue?" \
  51. 10 50 2>&1 > /dev/tty \
  52. || exit
  53. }
  54. # Build progress from array $STEPS()
  55. # INPUT
  56. # $steps()
  57. # OUTPUT
  58. # $progress
  59. function buildProgress ()
  60. {
  61. progress=""
  62. for ((i=0; i<=${#steps[*]}; i++))
  63. do
  64. progress="${progress}${steps[i]}\n"
  65. done
  66. }
  67. # Show Progress dialog
  68. # INPUT
  69. # 1 > Percentage to show in dialog
  70. # $backtitle
  71. # $progress
  72. function dialogShowProgress ()
  73. {
  74. local percent="$1"
  75. buildProgress
  76. clear
  77. clear
  78. echo "${percent}" | dialog \
  79. --stdout \
  80. --colors \
  81. --ascii-lines \
  82. --no-collapse \
  83. --cr-wrap \
  84. --backtitle "${backtitle}" \
  85. --title "Installer" \
  86. --gauge "${progress}" 36 90 0 \
  87. 2>&1 > /dev/tty
  88. sleep 1
  89. }
  90. # Show summary dialog
  91. function dialogShowSummary ()
  92. {
  93. # list all remotes and their type
  94. remotes=$(rclone listremotes -l)
  95. # get line wiht RETROPIE remote
  96. retval=$(grep -i "^retropie:" <<< ${remotes})
  97. remoteType="${retval#*:}"
  98. remoteType=$(echo ${remoteType} | xargs)
  99. dialog \
  100. --backtitle "${backtitle}" \
  101. --title "Summary" \
  102. --ascii-lines \
  103. --colors \
  104. --no-collapse \
  105. --cr-wrap \
  106. --yesno \
  107. "\n${GREEN}All done!${NORMAL}\n\nFrom now on, all your saves and states will be synchronized each time you start or stop a ROM.\n\nAll system will put their saves and states in\n Local: \"${YELLOW}~/RetroPie/saves/<SYSTEM>${NORMAL}\"\n Remote: \"${YELLOW}retropie:${remotebasedir}/<SYSTEM>\" (${remoteType})${NORMAL}\nIf you already have some saves in the ROM directories, you need to move them there manually now! Afterward, you should ${red}reboot${NORMAL} your RetroPie. Then, you should start a full sync via\n ${YELLOW}RetroPie / RCLONE_SCRIPT menu / 1 Full sync${NORMAL}\n\nCall\n ${YELLOW}RetroPie / RCLONE_SCRIPT menu / 9 uninstall${NORMAL}\nto remove all or parts of this script.\n\n${RED}Reboot RetroPie now?${NORMAL}" 25 90
  108. case $? in
  109. 0) sudo shutdown -r now ;;
  110. esac
  111. }
  112. ##################
  113. # STEP FUNCTIONS #
  114. ##################
  115. # Initialize array $STEPS()
  116. # OUTPUT
  117. # $steps()
  118. function initSteps ()
  119. {
  120. steps[1]="1. RCLONE"
  121. steps[2]=" 1a. Testing for RCLONE binary [ waiting... ]"
  122. steps[3]=" 1b. Getting RCLONE binary [ waiting... ]"
  123. steps[4]=" 1c. Testing RCLONE remote [ waiting... ]"
  124. steps[5]=" 1d. Create RCLONE remote [ waiting... ]"
  125. steps[6]="2. PNGVIEW"
  126. steps[7]=" 2a. Testing for PNGVIEW binary [ waiting... ]"
  127. steps[8]=" 2b. Getting PNGVIEW source [ waiting... ]"
  128. steps[9]=" 2c. Compiling PNGVIEW [ waiting... ]"
  129. steps[10]="3. IMAGEMAGICK"
  130. steps[11]=" 3a. Testing for IMAGEMAGICK [ waiting... ]"
  131. steps[12]=" 3b. Getting IMAGEMAGICK [ waiting... ]"
  132. steps[13]="4. RCLONE_SCRIPT"
  133. steps[14]=" 4a. Getting RCLONE_SCRIPT [ waiting... ]"
  134. steps[15]=" 4b. Creating RCLONE_SCRIPT menu item [ waiting... ]"
  135. steps[16]=" 4c. Configure RCLONE_SCRIPT [ waiting... ]"
  136. steps[17]="5. RUNCOMMAND"
  137. steps[18]=" 5a. RUNCOMMAND-ONSTART [ waiting... ]"
  138. steps[19]=" 5b. RUNCOMMAND-ONEND [ waiting... ]"
  139. steps[20]="6. Local SAVEFILE directory"
  140. steps[21]=" 6a. Check local base directory [ waiting... ]"
  141. steps[22]=" 6b. Check local <SYSTEM> directories [ waiting... ]"
  142. steps[23]="7. Remote SAVEFILE directory"
  143. steps[24]=" 7a. Check remote base directory [ waiting... ]"
  144. steps[25]=" 7b. Check remote <SYSTEM> directories [ waiting... ]"
  145. steps[26]="8. Configure RETROARCH"
  146. steps[27]=" 8a. Setting local SAVEFILE directories [ waiting... ]"
  147. steps[28]="9. Finalizing"
  148. steps[29]=" 9a. Saving configuration [ waiting... ]"
  149. }
  150. # Update item of $STEPS() and show updated progress dialog
  151. # INPUT
  152. # 1 > Number of step to update
  153. # 2 > New status for step
  154. # 3 > Percentage to show in progress dialog
  155. # $steps()
  156. # OUTPUT
  157. # $steps()
  158. function updateStep ()
  159. {
  160. local step="$1"
  161. local newStatus="$2"
  162. local percent="$3"
  163. local oldline
  164. local newline
  165. # translate and colorize $NEWSTATUS
  166. case "${newStatus}" in
  167. "waiting") newStatus="[ ${NORMAL}WAITING...${NORMAL} ]" ;;
  168. "in progress") newStatus="[ ${NORMAL}IN PROGRESS${NORMAL} ]" ;;
  169. "done") newStatus="[ ${GREEN}DONE${NORMAL} ]" ;;
  170. "found") newStatus="[ ${GREEN}FOUND${NORMAL} ]" ;;
  171. "not found") newStatus="[ ${RED}NOT FOUND${NORMAL} ]" ;;
  172. "created") newStatus="[ ${GREEN}CREATED${NORMAL} ]" ;;
  173. "failed") newStatus="[ ${RED}FAILED${NORMAL} ]" ;;
  174. "skipped") newStatus="[ ${YELLOW}SKIPPED${NORMAL} ]" ;;
  175. *) newStatus="[ ${RED}UNDEFINED${NORMAL} ]" ;;
  176. esac
  177. # search $STEP in $STEPS
  178. for ((i=0; i<${#steps[*]}; i++))
  179. do
  180. if [[ ${steps[i]} =~ .*$step.* ]]
  181. then
  182. # update $STEP with $NEWSTATUS
  183. oldline="${steps[i]}"
  184. oldline="${oldline%%[*}"
  185. newline="${oldline}${newStatus}"
  186. steps[i]="${newline}"
  187. break
  188. fi
  189. done
  190. # show progress dialog
  191. dialogShowProgress ${percent}
  192. }
  193. #######################
  194. # INSTALLER FUNCTIONS #
  195. #######################
  196. # Installer
  197. function installer ()
  198. {
  199. initSteps
  200. dialogShowProgress 0
  201. 1RCLONE
  202. 2PNGVIEW
  203. 3IMAGEMAGICK
  204. 4RCLONE_SCRIPT
  205. 5RUNCOMMAND
  206. 6LocalSAVEFILEDirectory
  207. 7RemoteSAVEFILEDirectory
  208. 8ConfigureRETROARCH
  209. 9Finalize
  210. dialogShowSummary
  211. }
  212. function 1RCLONE ()
  213. {
  214. # 1a. Testing for RCLONE binary
  215. updateStep "1a" "in progress" 0
  216. 1aTestRCLONE
  217. if [[ $? -eq 0 ]]
  218. then
  219. updateStep "1a" "found" 5
  220. updateStep "1b" "skipped" 10
  221. else
  222. updateStep "1a" "not found" 5
  223. # 1b. Getting RCLONE binary
  224. updateStep "1b" "in progress" 5
  225. 1bInstallRCLONE
  226. if [[ $? -eq 0 ]]
  227. then
  228. updateStep "1b" "done" 10
  229. else
  230. updateStep "1b" "failed" 5
  231. fi
  232. fi
  233. # 1c. Testing RCLONE configuration
  234. updateStep "1c" "in progress" 10
  235. 1cTestRCLONEremote
  236. if [[ $? -eq 0 ]]
  237. then
  238. updateStep "1c" "found" 15
  239. updateStep "1d" "skipped" 20
  240. else
  241. updateStep "1c" "not found" 15
  242. # 1d. Create RCLONE remote
  243. updateStep "1d" "in progress" 15
  244. 1dCreateRCLONEremote
  245. updateStep "1d" "done" 20
  246. fi
  247. }
  248. # Checks if RCLONE is installed
  249. # RETURN
  250. # 0 > RCLONE is installed
  251. # 1 > RCLONE is not installed
  252. function 1aTestRCLONE ()
  253. {
  254. printf "$(date +%FT%T%:z):\t1aTestRCLONE\tSTART\n" >> ./rclone_script-install.log
  255. if [ -f /usr/bin/rclone ]
  256. then
  257. printf "$(date +%FT%T%:z):\t1aTestRCLONE\tFOUND\n" >> ./rclone_script-install.log
  258. return 0
  259. else
  260. printf "$(date +%FT%T%:z):\t1aTestRCLONE\tNOT FOUND\n" >> ./rclone_script-install.log
  261. return 1
  262. fi
  263. }
  264. # Installs RCLONE by download
  265. # RETURN
  266. # 0 > RCLONE has been installed
  267. # 1 > Error while installing RCLONE
  268. function 1bInstallRCLONE ()
  269. {
  270. printf "$(date +%FT%T%:z):\t1bInstallRCLONE\tSTART\n" >> ./rclone_script-install.log
  271. # TODO get RCLONE for 64bit
  272. { # try
  273. # get binary
  274. wget -P ~ https://downloads.rclone.org/rclone-current-linux-arm.zip --append-output=./rclone_script-install.log &&
  275. unzip ~/rclone-current-linux-arm.zip -d ~ >> ./rclone_script-install.log &&
  276. cd ~/rclone-v* &&
  277. # move binary
  278. sudo mv rclone /usr/bin >> ./rclone_script-install.log &&
  279. sudo chown root:root /usr/bin/rclone >> ./rclone_script-install.log &&
  280. sudo chmod 755 /usr/bin/rclone >> ./rclone_script-install.log &&
  281. cd ~ &&
  282. # remove temp files
  283. rm ~/rclone-current-linux-arm.zip >> ./rclone_script-install.log &&
  284. rm -r ~/rclone-v* >> ./rclone_script-install.log &&
  285. printf "$(date +%FT%T%:z):\t1bInstallRCLONE\tDONE\n" >> ./rclone_script-install.log
  286. return 0
  287. } || { #catch
  288. printf "$(date +%FT%T%:z):\t1bInstallRCLONE\tERROR\n" >> ./rclone_script-install.log
  289. # remove temp files
  290. rm ~/rclone-current-linux-arm.zip >> ./rclone_script-install.log &&
  291. rm -r ~/rclone-v* >> ./rclone_script-install.log &&
  292. return 1
  293. }
  294. }
  295. # Checks if there's a RCLONE remote called RETROPIE
  296. # RETURN
  297. # 0 > remote RETROPIE has been found
  298. # 1 > no remote RETROPIE found
  299. function 1cTestRCLONEremote ()
  300. {
  301. printf "$(date +%FT%T%:z):\t1cTestRCLONEremote\tSTART\n" >> ./rclone_script-install.log
  302. local remotes=$(rclone listremotes)
  303. local retval=$(grep -i "^retropie:" <<< ${remotes})
  304. if [ "${retval}" == "retropie:" ]
  305. then
  306. printf "$(date +%FT%T%:z):\t1cTestRCLONEremote\tFOUND\n" >> ./rclone_script-install.log
  307. return 0
  308. else
  309. printf "$(date +%FT%T%:z):\t1cTestRCLONEremote\tNOT FOUND\n" >> ./rclone_script-install.log
  310. return 1
  311. fi
  312. }
  313. # Tells the user to create a new RCLONE remote called RETROPIE
  314. # RETURN
  315. # 0 > remote RETROPIE has been created (no other OUTPUT possible)
  316. function 1dCreateRCLONEremote ()
  317. {
  318. printf "$(date +%FT%T%:z):\t1dCreateRCLONEremote\tSTART\n" >> ./rclone_script-install.log
  319. dialog \
  320. --stdout \
  321. --colors \
  322. --ascii-lines \
  323. --no-collapse \
  324. --cr-wrap \
  325. --backtitle "${backtitle}" \
  326. --title "Installer" \
  327. --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 \
  328. 2>&1 > /dev/tty
  329. rclone config
  330. 1cTestRCLONEremote
  331. if [[ $? -eq 1 ]]
  332. then
  333. dialog \
  334. --stdout \
  335. --colors \
  336. --ascii-lines \
  337. --no-collapse \
  338. --cr-wrap \
  339. --backtitle "${backtitle}" \
  340. --title "Installer" \
  341. --msgbox "\nNo remote ${RED}retropie${NORMAL} found.\nPlease try again." 20 50 \
  342. 2>&1 > /dev/tty
  343. 1dCreateRCLONEremote
  344. else
  345. printf "$(date +%FT%T%:z):\t1dCreateRCLONEremote\tFOUND\n" >> ./rclone_script-install.log
  346. return 0
  347. fi
  348. }
  349. function 2PNGVIEW ()
  350. {
  351. # 2a. Testing for PNGVIEW binary
  352. updateStep "2a" "in progress" 20
  353. 2aTestPNGVIEW
  354. if [[ $? -eq 0 ]]
  355. then
  356. updateStep "2a" "found" 25
  357. updateStep "2b" "skipped" 30
  358. updateStep "2c" "skipped" 35
  359. else
  360. updateStep "2a" "not found" 25
  361. # 2b. Getting PNGVIEW source
  362. updateStep "2b" "in progress" 25
  363. 2bGetPNGVIEWsource
  364. if [[ $? -eq 0 ]]
  365. then
  366. updateStep "2b" "done" 30
  367. # 2c. Compiling PNGVIEW
  368. updateStep "2c" "in progress" 30
  369. 2cCompilePNGVIEW
  370. if [[ $? -eq 0 ]]
  371. then
  372. updateStep "2c" "done" 35
  373. else
  374. updateStep "2c" "failed" 30
  375. exit
  376. fi
  377. else
  378. updateStep "2b" "failed" 25
  379. exit
  380. fi
  381. fi
  382. }
  383. # Checks if PNGVIEW is installed
  384. # RETURN
  385. # 0 > PNGVIEW is installed
  386. # 1 > PNGVIEW is not installed
  387. function 2aTestPNGVIEW ()
  388. {
  389. printf "$(date +%FT%T%:z):\t2aTestPNGVIEW\tSTART\n" >> ./rclone_script-install.log
  390. if [ -f /usr/bin/pngview ]
  391. then
  392. printf "$(date +%FT%T%:z):\t2aTestPNGVIEW\tFOUND\n" >> ./rclone_script-install.log
  393. return 0
  394. else
  395. printf "$(date +%FT%T%:z):\t2aTestPNGVIEW\tNOT FOUND\n" >> ./rclone_script-install.log
  396. return 1
  397. fi
  398. }
  399. # Gets PNGVIEW source
  400. # RETURN
  401. # 0 > source downloaded and unzipped
  402. # 1 > no source downloaded, removed temp files
  403. function 2bGetPNGVIEWsource ()
  404. {
  405. printf "$(date +%FT%T%:z):\t2bGetPNGVIEWsource\tSTART\n" >> ./rclone_script-install.log
  406. { #try
  407. wget -P ~ https://github.com/AndrewFromMelbourne/raspidmx/archive/master.zip --append-output=./rclone_script-install.log &&
  408. unzip ~/master.zip -d ~ >> ./rclone_script-install.log &&
  409. printf "$(date +%FT%T%:z):\t2bGetPNGVIEWsource\tDONE\n" >> ./rclone_script-install.log &&
  410. return 0
  411. } || { #catch
  412. printf "$(date +%FT%T%:z):\t2bGetPNGVIEWsource\tERROR\n" >> ./rclone_script-install.log &&
  413. rm ~/master.zip >> ./rclone_script-install.log &&
  414. sudo rm -r ~/raspidmx-master >> ./rclone_script-install.log &&
  415. return 1
  416. }
  417. }
  418. # Compiles PNGVIEW source, moves binaries
  419. # RETURN
  420. # 0 > compiled without errors, moved binaries, removed temp files
  421. # 1 > errors while compiling, removed temp files
  422. function 2cCompilePNGVIEW ()
  423. {
  424. printf "$(date +%FT%T%:z):\t2cCompilePNGVIEW\tSTART\n" >> ./rclone_script-install.log
  425. { #try
  426. # compile
  427. # cd ~/raspidmx-master &&
  428. make --directory=~/raspidmx-master >> ./rclone_script-install.log &&
  429. # move binary files
  430. sudo mv ~/raspidmx-master/pngview/pngview /usr/bin >> ./rclone_script-install.log &&
  431. sudo mv ~/raspidmx-master/lib/libraspidmx.so.1 /usr/lib >> ./rclone_script-install.log &&
  432. sudo chown root:root /usr/bin/pngview >> ./rclone_script-install.log &&
  433. sudo chmod 755 /usr/bin/pngview >> ./rclone_script-install.log &&
  434. # remove temp files
  435. rm ~/master.zip >> ./rclone_script-install.log &&
  436. sudo rm -r ~/raspidmx-master >> ./rclone_script-install.log &&
  437. printf "$(date +%FT%T%:z):\t2cCompilePNGVIEW\tDONE\n" >> ./rclone_script-install.log &&
  438. return 0
  439. } || { #catch
  440. printf "$(date +%FT%T%:z):\t2cCompilePNGVIEW\tERROR\n" >> ./rclone_script-install.log &&
  441. # remove temp files
  442. rm ~/master.zip >> ./rclone_script-install.log &&
  443. sudo rm -r ~/raspidmx-master >> ./rclone_script-install.log &&
  444. return 1
  445. }
  446. }
  447. function 3IMAGEMAGICK ()
  448. {
  449. # 3a. Testing for IMAGEMAGICK
  450. updateStep "3a" "in progress" 35
  451. 3aTestIMAGEMAGICK
  452. if [[ $? -eq 0 ]]
  453. then
  454. updateStep "3a" "found" 40
  455. updateStep "3b" "skipped" 45
  456. else
  457. updateStep "3a" "not found" 40
  458. # 3b. Getting IMAGEMAGICK
  459. updateStep "3b" "in progress" 40
  460. 3bInstallIMAGEMAGICK
  461. if [[ $? -eq 0 ]]
  462. then
  463. updateStep "3b" "done" 45
  464. else
  465. updateStep "3b" "failed" 40
  466. fi
  467. fi
  468. }
  469. # Checks is IMAGEMAGICK is installed
  470. # RETURN
  471. # 0 > IMAGEMAGICK is installed
  472. # 1 > IMAGEMAGICK is not installed
  473. function 3aTestIMAGEMAGICK ()
  474. {
  475. printf "$(date +%FT%T%:z):\t3aTestIMAGEMAGICK\tSTART\n" >> ./rclone_script-install.log
  476. if [ -f /usr/bin/convert ]
  477. then
  478. printf "$(date +%FT%T%:z):\t3aTestIMAGEMAGICK\tFOUND\n" >> ./rclone_script-install.log
  479. return 0
  480. else
  481. printf "$(date +%FT%T%:z):\t3aTestIMAGEMAGICK\tNOT FOUND\n" >> ./rclone_script-install.log
  482. return 1
  483. fi
  484. }
  485. # Installs IMAGEMAGICK via APT-GET
  486. # RETURN
  487. # 0 > IMAGEMAGICK has been installed
  488. # 1 > Error while installing IMAGEMAGICK
  489. function 3bInstallIMAGEMAGICK ()
  490. {
  491. printf "$(date +%FT%T%:z):\t3bInstallIMAGEMAGICK\tSTART\n" >> ./rclone_script-install.log
  492. sudo apt-get update >> ./rclone_script-install.log &&
  493. sudo apt-get --yes install imagemagick >> ./rclone_script-install.log &&
  494. if [[ $? -eq 0 ]]
  495. then
  496. printf "$(date +%FT%T%:z):\t3bInstallIMAGEMAGICK\tDONE\n" >> ./rclone_script-install.log &&
  497. return 0
  498. else
  499. printf "$(date +%FT%T%:z):\t3bInstallIMAGEMAGICK\tERROR\n" >> ./rclone_script-install.log &&
  500. return 1
  501. fi
  502. }
  503. function 4RCLONE_SCRIPT ()
  504. {
  505. # 4a. Getting RCLONE_SCRIPT
  506. updateStep "4a" "in progress" 45
  507. 4aGetRCLONE_SCRIPT
  508. if [[ $? -eq 0 ]]
  509. then
  510. updateStep "4a" "done" 50
  511. else
  512. updateStep "4a" "failed" 45
  513. exit
  514. fi
  515. # 4b. Creating RCLONE_SCRIPT menu item
  516. updateStep "4b" "in progress" 50
  517. 4bCreateRCLONE_SCRIPTMenuItem
  518. if [[ $? -eq 0 ]]
  519. then
  520. updateStep "4b" "done" 55
  521. else
  522. updateStep "4b" "failed" 50
  523. exit
  524. fi
  525. # 4c. Configure RCLONE_SCRIPT
  526. updateStep "4c" "in progress" 55
  527. 4cConfigureRCLONE_SCRIPT
  528. updateStep "4c" "done" 60
  529. }
  530. # Gets RCLONE_SCRIPT
  531. # RETURN
  532. # 0 > downloaded successfully
  533. # 1 > errors while downloading
  534. function 4aGetRCLONE_SCRIPT ()
  535. {
  536. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tSTART\n" >> ./rclone_script-install.log
  537. # create directory if necessary
  538. if [ ! -d ~/scripts/rclone_script ]
  539. then
  540. mkdir ~/scripts/rclone_script >> ./rclone_script-install.log
  541. fi
  542. { #try
  543. # get script files
  544. wget -N -P ~/scripts/rclone_script ${url}/${branch}/rclone_script.sh --append-output=./rclone_script-install.log &&
  545. wget -N -P ~/scripts/rclone_script ${url}/${branch}/rclone_script-menu.sh --append-output=./rclone_script-install.log &&
  546. wget -N -P ~/scripts/rclone_script ${url}/${branch}/rclone_script-uninstall.sh --append-output=./rclone_script-install.log &&
  547. # change mod
  548. chmod +x ~/scripts/rclone_script/rclone_script.sh >> ./rclone_script-install.log &&
  549. chmod +x ~/scripts/rclone_script/rclone_script-menu.sh >> ./rclone_script-install.log &&
  550. chmod +x ~/scripts/rclone_script/rclone_script-uninstall.sh >> ./rclone_script-install.log &&
  551. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tDONE\n" >> ./rclone_script-install.log &&
  552. return 0
  553. } || { # catch
  554. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tERROR\n" >> ./rclone_script-install.log
  555. return 1
  556. }
  557. }
  558. # Creates a menu item for RCLONE_SCRIPT in RetroPie menu
  559. # RETURN
  560. # 0 > menu item has been found or created
  561. # 1 > error while creating menu item
  562. function 4bCreateRCLONE_SCRIPTMenuItem ()
  563. {
  564. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tSTART\n" >> ./rclone_script-install.log
  565. # move menu script
  566. mv --force ~/scripts/rclone_script/rclone_script-menu.sh ~/RetroPie/retropiemenu >> ./rclone_script-install.log
  567. # check if menu item exists
  568. if grep -Fq "<path>./rclone_script-menu.sh</path>" ~/.emulationstation/gamelists/retropie/gamelist.xml
  569. then
  570. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tFOUND\n" >> ./rclone_script-install.log
  571. return 0
  572. else
  573. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tNOT FOUND\n" >> ./rclone_script-install.log
  574. sed -i "/<\/gameList>/c\\\\t<game>\n\t\t<path>.\/rclone_script-menu.sh<\/path>\n\t\t<name>RCLONE_SCRIPT menu<\/name>\n\t\t<desc>Customize RCLONE_SCRIPT, start a full sync, uninstall RCLONE_SCRIPT<\/desc>\n\t\t<image></image>\n\t<\/game>\n<\/gameList>" ~/.emulationstation/gamelists/retropie/gamelist.xml
  575. if [[ $? -eq 0 ]]
  576. then
  577. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tCREATED\n" >> ./rclone_script-install.log
  578. return 0
  579. else
  580. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tERROR\n" >> ./rclone_script-install.log
  581. return 1
  582. fi
  583. fi
  584. }
  585. # Gets user input to configure RCLONE_SCRIPT
  586. function 4cConfigureRCLONE_SCRIPT ()
  587. {
  588. printf "$(date +%FT%T%:z):\t4cConfigureRCLONE_SCRIPT\tSTART\n" >> ./rclone_script-install.log
  589. remotebasedir=$(dialog \
  590. --stdout \
  591. --colors \
  592. --ascii-lines \
  593. --no-collapse \
  594. --cr-wrap \
  595. --backtitle "${backtitle}" \
  596. --title "Remote base directory" \
  597. --inputbox "\nPlease name the directory which will be used as your ${YELLOW}remote base directory${NORMAL}. If necessary, this directory will be created.\n\nExamples:\n* RetroArch\n* mySaves/RetroArch\n\n" 18 40 "RetroArch"
  598. )
  599. dialog \
  600. --stdout \
  601. --colors \
  602. --ascii-lines \
  603. --no-collapse \
  604. --cr-wrap \
  605. --backtitle "${backtitle}" \
  606. --title "Notifications" \
  607. --yesno "\nDo you wish to see ${YELLOW}notifications${NORMAL} whenever RCLONE_SCRIPT is synchronizing?" 18 40
  608. case $? in
  609. 0) shownotifications="TRUE" ;;
  610. 1) shownotifications="FALSE" ;;
  611. *) shownotifications="FALSE" ;;
  612. esac
  613. printf "$(date +%FT%T%:z):\t4cConfigureRCLONE_SCRIPT\tDONE\n" >> ./rclone_script-install.log
  614. }
  615. function 5RUNCOMMAND ()
  616. {
  617. # 5a. RUNCOMMAND-ONSTART
  618. updateStep "5a" "in progress" 60
  619. 5aRUNCOMMAND-ONSTART
  620. case $? in
  621. 0) updateStep "5a" "found" 65 ;;
  622. 1) updateStep "5a" "created" 65 ;;
  623. esac
  624. # 5b. RUNCOMMAND-ONEND
  625. updateStep "5b" "in progress" 65
  626. 5aRUNCOMMAND-ONEND
  627. case $? in
  628. 0) updateStep "5b" "found" 70 ;;
  629. 1) updateStep "5b" "created" 70 ;;
  630. esac
  631. }
  632. # Checks call of RCLONE_SCRIPT by RUNCOMMAND-ONSTART
  633. # RETURNS
  634. # 0 > call found
  635. # 1 > call created
  636. function 5aRUNCOMMAND-ONSTART ()
  637. {
  638. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tSTART\n" >> ./rclone_script-install.log
  639. # check if RUNCOMMAND-ONSTART.sh exists
  640. if [ -f /opt/retropie/configs/all/runcommand-onstart.sh ]
  641. then
  642. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tFILE FOUND\n" >> ./rclone_script-install.log
  643. # check if there's a call to RCLONE_SCRIPT
  644. if grep -Fq "~/scripts/rclone_script/rclone_script.sh" /opt/retropie/configs/all/runcommand-onstart.sh
  645. then
  646. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tCALL FOUND\n" >> ./rclone_script-install.log
  647. return 0
  648. else
  649. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tCALL NOT FOUND\n" >> ./rclone_script-install.log
  650. # add call
  651. echo "~/scripts/rclone_script/rclone_script.sh \"down\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"" >> /opt/retropie/configs/all/runcommand-onstart.sh
  652. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tCALL CREATED\n" >> ./rclone_script-install.log
  653. return 1
  654. fi
  655. else
  656. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tFILE NOT FOUND\n" >> ./rclone_script-install.log
  657. echo "#!/bin/bash" > /opt/retropie/configs/all/runcommand-onstart.sh
  658. echo "~/scripts/rclone_script/rclone_script.sh \"down\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"" >> /opt/retropie/configs/all/runcommand-onstart.sh
  659. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tFILE CREATED\n" >> ./rclone_script-install.log
  660. return 1
  661. fi
  662. }
  663. # Checks call of RCLONE_SCRIPT by RUNCOMMAND-ONEND
  664. # RETURNS
  665. # 0 > call found
  666. # 1 > call created
  667. function 5aRUNCOMMAND-ONEND ()
  668. {
  669. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tSTART\n" >> ./rclone_script-install.log
  670. # check if RUNCOMMAND-ONEND.sh exists
  671. if [ -f /opt/retropie/configs/all/runcommand-onend.sh ]
  672. then
  673. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tFILE FOUND\n" >> ./rclone_script-install.log
  674. # check if there's a call to RCLONE_SCRIPT
  675. if grep -Fq "~/scripts/rclone_script/rclone_script.sh" /opt/retropie/configs/all/runcommand-onend.sh
  676. then
  677. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tCALL FOUND\n" >> ./rclone_script-install.log
  678. return 0
  679. else
  680. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tCALL NOT FOUND\n" >> ./rclone_script-install.log
  681. # add call
  682. echo "~/scripts/rclone_script/rclone_script.sh \"up\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"" >> /opt/retropie/configs/all/runcommand-onend.sh
  683. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tCALL CREATED\n" >> ./rclone_script-install.log
  684. return 1
  685. fi
  686. else
  687. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tFILE NOT FOUND\n" >> ./rclone_script-install.log
  688. echo "#!/bin/bash" > /opt/retropie/configs/all/runcommand-onend.sh
  689. echo "~/scripts/rclone_script/rclone_script.sh \"up\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"" >> /opt/retropie/configs/all/runcommand-onend.sh
  690. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tFILE CREATED\n" >> ./rclone_script-install.log
  691. return 1
  692. fi
  693. }
  694. function 6LocalSAVEFILEDirectory ()
  695. {
  696. # 6a. Test for local SAVEFILE directory
  697. updateStep "6a" "in progress" 70
  698. 6aCheckLocalBaseDirectory
  699. case $? in
  700. 0) updateStep "6a" "found" 75 ;;
  701. 1) updateStep "6a" "created" 75 ;;
  702. esac
  703. # 6b. Check local <SYSTEM> directories
  704. updateStep "6b" "in progress" 75
  705. 6bCheckLocalSystemDirectories
  706. case $? in
  707. 0) updateStep "6b" "found" 80 ;;
  708. 1) updateStep "6b" "created" 80 ;;
  709. esac
  710. }
  711. # Checks if the local base SAVEFILE directory exists
  712. # RETURN
  713. # 0 > directory exists
  714. # 1 > directory has been created
  715. function 6aCheckLocalBaseDirectory ()
  716. {
  717. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tSTART\n" >> ./rclone_script-install.log
  718. # check if local base dir exists
  719. if [ -d ~/RetroPie/saves ]
  720. then
  721. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tFOUND\n" >> ./rclone_script-install.log
  722. return 0
  723. else
  724. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tNOT FOUND\n" >> ./rclone_script-install.log
  725. mkdir ~/RetroPie/saves
  726. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tCREATED\n" >> ./rclone_script-install.log
  727. return 1
  728. fi
  729. }
  730. # Checks if the local system specific directories exists
  731. # RETURN
  732. # 0 > all found
  733. # 1 > created at least one
  734. function 6bCheckLocalSystemDirectories ()
  735. {
  736. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tSTART\n" >> ./rclone_script-install.log
  737. local retval=0
  738. # for each directory in ROMS directory...
  739. for directory in ~/RetroPie/roms/*
  740. do
  741. system="${directory##*/}"
  742. if [ -d ~/RetroPie/saves/${system} ]
  743. then
  744. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tFOUND ${system}\n" >> ./rclone_script-install.log
  745. else
  746. mkdir ~/RetroPie/saves/${system}
  747. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tCREATED ${system}\n" >> ./rclone_script-install.log
  748. retval=1
  749. fi
  750. done
  751. return ${retval}
  752. }
  753. function 7RemoteSAVEFILEDirectory ()
  754. {
  755. # 7a. Check remote base directory
  756. updateStep "7a" "in progress" 80
  757. 7aCheckRemoteBaseDirectory
  758. case $? in
  759. 0) updateStep "7a" "found" 85 ;;
  760. 1) updateStep "7a" "created" 85 ;;
  761. 255) updateStep "7a" "failed" 80 ;;
  762. esac
  763. # 7b. Check remote <system> directories
  764. updateStep "7b" "in progress" 85
  765. 7bCheckRemoteSystemDirectories
  766. case $? in
  767. 0) updateStep "7b" "found" 90 ;;
  768. 1) updateStep "7b" "created" 90 ;;
  769. 255) updateStep "7b" "failed" 85 ;;
  770. esac
  771. }
  772. # Checks if the remote base SAVEFILE directory exists
  773. # RETURN
  774. # 0 > directory exists
  775. # 1 > directory has been created
  776. # 255 > error while creating directory
  777. function 7aCheckRemoteBaseDirectory ()
  778. {
  779. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tSTART\n" >> ./rclone_script-install.log
  780. # list all directories from remote
  781. remoteDirs=$(rclone lsf --dirs-only -R retropie:)
  782. # for each line...
  783. while read path
  784. do
  785. if [ "${path}" == "${remotebasedir}/" ]
  786. then
  787. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tFOUND\n" >> ./rclone_script-install.log
  788. return 0
  789. fi
  790. done <<< "${remoteDirs}"
  791. # if there has been no match...
  792. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tNOT FOUND\n" >> ./rclone_script-install.log
  793. rclone mkdir retropie:"${remotebasedir}" >> ./rclone_script-install.log
  794. case $? in
  795. 0) printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tCREATED\n" >> ./rclone_script-install.log; return 1 ;;
  796. *) printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tERROR\n" >> ./rclone_script-install.log;return 255 ;;
  797. esac
  798. }
  799. # Checks if the remote system specific directories exist
  800. # RETURN
  801. # 0 > all found
  802. # 1 > created at least one
  803. # 255 > error while creating directory
  804. function 7bCheckRemoteSystemDirectories ()
  805. {
  806. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tSTART\n" >> ./rclone_script-install.log
  807. local retval=0
  808. local output
  809. # list all directories in $REMOTEBASEDIR from remote
  810. remoteDirs=$(rclone lsf --dirs-only -R retropie:"${remotebasedir}")
  811. # for each directory in ROMS directory...
  812. for directory in ~/RetroPie/roms/*
  813. do
  814. system="${directory##*/}"
  815. # use grep to search $SYSTEM in $DIRECTORIES
  816. output=$(grep "${system}/" -nx <<< "${remoteDirs}")
  817. if [ "${output}" = "" ]
  818. then
  819. # create system dir
  820. rclone mkdir retropie:"${remotebasedir}/${system}"
  821. if [[ $? -eq 0 ]]
  822. then
  823. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tCREATED ${system}\n" >> ./rclone_script-install.log
  824. retval=1
  825. else
  826. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tERROR\n" >> ./rclone_script-install.log
  827. return 255
  828. fi
  829. else
  830. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tFOUND ${system}\n" >> ./rclone_script-install.log
  831. fi
  832. done
  833. return ${retval}
  834. }
  835. function 8ConfigureRETROARCH ()
  836. {
  837. # 8a. Setting local SAVEFILE directory
  838. updateStep "8a" "in progress" 90
  839. 8aSetLocalSAVEFILEDirectory
  840. updateStep "8a" "done" 95
  841. }
  842. # Sets parameters in all system specific configuration files
  843. function 8aSetLocalSAVEFILEDirectory ()
  844. {
  845. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tSTART\n" >> ./rclone_script-install.log
  846. local retval
  847. # for each directory...
  848. for directory in /opt/retropie/configs/*
  849. do
  850. system="${directory##*/}"
  851. # skip directory ALL
  852. if [ "${system}" = "all" ]
  853. then
  854. continue
  855. fi
  856. # test if there's a RETROARCH.CFG
  857. if [ -f "${directory}/retroarch.cfg" ]
  858. then
  859. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tFOUND retroarch.cfg FOR ${system}\n" >> ./rclone_script-install.log
  860. # test file for SAVEFILE_DIRECTORY
  861. retval=$(grep -i "^savefile_directory = " ${directory}/retroarch.cfg)
  862. if [ ! "${retval}" = "" ]
  863. then
  864. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tREPLACED savefile_directory\n" >> ./rclone_script-install.log
  865. # replace existing parameter
  866. sed -i "/^savefile_directory = /c\savefile_directory = \"~/RetroPie/saves/${system}\"" ${directory}/retroarch.cfg
  867. else
  868. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tADDED savefile_directory\n" >> ./rclone_script-install.log
  869. # create new parameter above "#include..."
  870. sed -i "/^#include \"\/opt\/retropie\/configs\/all\/retroarch.cfg\"/c\savefile_directory = \"~\/RetroPie\/saves\/${system}\"\n#include \"\/opt\/retropie\/configs\/all\/retroarch.cfg\"" ${directory}/retroarch.cfg
  871. fi
  872. # test file for SAVESTATE_DIRECTORY
  873. retval=$(grep -i "^savestate_directory = " ${directory}/retroarch.cfg)
  874. if [ ! "${retval}" = "" ]
  875. then
  876. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tREPLACED savestate_directory\n" >> ./rclone_script-install.log
  877. # replace existing parameter
  878. sed -i "/^savestate_directory = /c\savestate_directory = \"~/RetroPie/saves/${system}\"" ${directory}/retroarch.cfg
  879. else
  880. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tADDED savestate_directory\n" >> ./rclone_script-install.log
  881. # create new parameter above "#include..."
  882. sed -i "/^#include \"\/opt\/retropie\/configs\/all\/retroarch.cfg\"/c\savestate_directory = \"~\/RetroPie\/saves\/${system}\"\n#include \"\/opt\/retropie\/configs\/all\/retroarch.cfg\"" ${directory}/retroarch.cfg
  883. fi
  884. fi
  885. done
  886. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tDONE\n" >> ./rclone_script-install.log
  887. }
  888. function 9Finalize ()
  889. {
  890. # 9a. Saving configuration
  891. updateStep "9a" "in progress" 95
  892. 9aSaveConfiguration
  893. updateStep "9a" "done" 100
  894. }
  895. # Saves the configuration of RCLONE_SCRIPT
  896. function 9aSaveConfiguration ()
  897. {
  898. printf "$(date +%FT%T%:z):\t9aSaveConfiguration\tSTART\n" >> ./rclone_script-install.log
  899. echo "remotebasedir=${remotebasedir}" > ~/scripts/rclone_script/rclone_script.ini
  900. echo "shownotifications=${shownotifications}" > ~/scripts/rclone_script/rclone_script.ini
  901. echo "logfile=~/scripts/rclone_script.log" >> ~/scripts/rclone_script/rclone_script.ini
  902. echo "debug=0" >> ~/scripts/rclone_script/rclone_script.ini
  903. printf "$(date +%FT%T%:z):\t9aSaveConfiguration\tDONE\n" >> ./rclone_script-install.log
  904. }
  905. ########
  906. # MAIN #
  907. ########
  908. if [ "${branch}" == "beta" ]
  909. then
  910. dialogBetaWarning
  911. fi
  912. installer