1
0

rclone_script-install.sh 32 KB

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