rclone_script-install.sh 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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="psp-save-support"
  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. wget -N -P ~/scripts/rclone_script ${url}/${branch}/emulator_settings.xml --append-output="${logfile}" &&
  545. # change mod
  546. chmod +x ~/scripts/rclone_script/rclone_script.sh >> "${logfile}" &&
  547. chmod +x ~/scripts/rclone_script/rclone_script-menu.sh >> "${logfile}" &&
  548. chmod +x ~/scripts/rclone_script/rclone_script-uninstall.sh >> "${logfile}" &&
  549. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tDONE\n" >> "${logfile}" &&
  550. return 0
  551. } || { # catch
  552. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tERROR\n" >> "${logfile}" &&
  553. return 1
  554. }
  555. }
  556. # Creates a menu item for RCLONE_SCRIPT in RetroPie menu
  557. # RETURN
  558. # 0 > menu item has been found or created
  559. # 1 > error while creating menu item
  560. function 4bCreateRCLONE_SCRIPTMenuItem ()
  561. {
  562. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tSTART\n" >> "${logfile}"
  563. # create redirect script
  564. printf "#!/bin/bash\n~/scripts/rclone_script/rclone_script-menu.sh" > ~/RetroPie/retropiemenu/rclone_script-redirect.sh
  565. chmod +x ~/RetroPie/retropiemenu/rclone_script-redirect.sh
  566. # check if menu item exists
  567. if [[ $(xmlstarlet sel -t -v "count(/gameList/game[path='./rclone_script-redirect.sh'])" ~/.emulationstation/gamelists/retropie/gamelist.xml) -eq 0 ]]
  568. then
  569. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tNOT FOUND\n" >> "${logfile}"
  570. xmlstarlet ed \
  571. --inplace \
  572. --subnode "/gameList" --type elem -n game -v "" \
  573. --subnode "/gameList/game[last()]" --type elem -n path -v "./rclone_script-redirect.sh" \
  574. --subnode "/gameList/game[last()]" --type elem -n name -v "RCLONE_SCRIPT menu" \
  575. --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" \
  576. ~/.emulationstation/gamelists/retropie/gamelist.xml
  577. if [[ $? -eq 0 ]]
  578. then
  579. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tCREATED\n" >> "${logfile}"
  580. return 0
  581. else
  582. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tERROR\n" >> "${logfile}"
  583. return 1
  584. fi
  585. else
  586. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tFOUND\n" >> "${logfile}"
  587. return 0
  588. fi
  589. }
  590. # Gets user input to configure RCLONE_SCRIPT
  591. function 4cConfigureRCLONE_SCRIPT ()
  592. {
  593. printf "$(date +%FT%T%:z):\t4cConfigureRCLONE_SCRIPT\tSTART\n" >> "${logfile}"
  594. remotebasedir=$(dialog \
  595. --stdout \
  596. --colors \
  597. --no-collapse \
  598. --cr-wrap \
  599. --no-cancel \
  600. --backtitle "${backtitle}" \
  601. --title "Remote base directory" \
  602. --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"
  603. )
  604. dialog \
  605. --stdout \
  606. --colors \
  607. --no-collapse \
  608. --cr-wrap \
  609. --backtitle "${backtitle}" \
  610. --title "Notifications" \
  611. --yesno "\nDo you wish to see ${YELLOW}notifications${NORMAL} whenever RCLONE_SCRIPT is synchronizing?" 18 40
  612. case $? in
  613. 0) shownotifications="TRUE" ;;
  614. 1) shownotifications="FALSE" ;;
  615. *) shownotifications="FALSE" ;;
  616. esac
  617. choice=$(dialog \
  618. --stdout \
  619. --colors \
  620. --no-collapse \
  621. --cr-wrap \
  622. --backtitle "${backtitle}" \
  623. --title "Needed connection" \
  624. --ok-label "Select" \
  625. --no-cancel \
  626. --menu "\nPlease select which type of connection will be needed for your configured remote" 20 50 5 \
  627. 0 "Internet access" \
  628. 1 "LAN / WLAN connection only"
  629. )
  630. neededConnection=${choice}
  631. printf "$(date +%FT%T%:z):\t4cConfigureRCLONE_SCRIPT\tDONE\n" >> "${logfile}"
  632. }
  633. function 5RUNCOMMAND ()
  634. {
  635. # 5a. RUNCOMMAND-ONSTART
  636. updateStep "5a" "in progress" 60
  637. 5aRUNCOMMAND-ONSTART
  638. case $? in
  639. 0) updateStep "5a" "found" 65 ;;
  640. 1) updateStep "5a" "created" 65 ;;
  641. esac
  642. # 5b. RUNCOMMAND-ONEND
  643. updateStep "5b" "in progress" 65
  644. 5aRUNCOMMAND-ONEND
  645. case $? in
  646. 0) updateStep "5b" "found" 70 ;;
  647. 1) updateStep "5b" "created" 70 ;;
  648. esac
  649. }
  650. # Checks call of RCLONE_SCRIPT by RUNCOMMAND-ONSTART
  651. # RETURNS
  652. # 0 > call found
  653. # 1 > call created
  654. function 5aRUNCOMMAND-ONSTART ()
  655. {
  656. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tSTART\n" >> "${logfile}"
  657. # check if RUNCOMMAND-ONSTART.sh exists
  658. if [ -f /opt/retropie/configs/all/runcommand-onstart.sh ]
  659. then
  660. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tFILE FOUND\n" >> "${logfile}"
  661. # check if there's a call to RCLONE_SCRIPT
  662. if grep -Fq "~/scripts/rclone_script/rclone_script.sh" /opt/retropie/configs/all/runcommand-onstart.sh
  663. then
  664. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tCALL FOUND\n" >> "${logfile}"
  665. return 0
  666. else
  667. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tCALL NOT FOUND\n" >> "${logfile}"
  668. # add call
  669. printf "\n~/scripts/rclone_script/rclone_script.sh \"down\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"\n" >> /opt/retropie/configs/all/runcommand-onstart.sh
  670. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tCALL CREATED\n" >> "${logfile}"
  671. return 1
  672. fi
  673. else
  674. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tFILE NOT FOUND\n" >> "${logfile}"
  675. printf "#!/bin/bash\n~/scripts/rclone_script/rclone_script.sh \"down\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"\n" > /opt/retropie/configs/all/runcommand-onstart.sh
  676. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONSTART\tFILE CREATED\n" >> "${logfile}"
  677. return 1
  678. fi
  679. }
  680. # Checks call of RCLONE_SCRIPT by RUNCOMMAND-ONEND
  681. # RETURNS
  682. # 0 > call found
  683. # 1 > call created
  684. function 5aRUNCOMMAND-ONEND ()
  685. {
  686. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tSTART\n" >> "${logfile}"
  687. # check if RUNCOMMAND-ONEND.sh exists
  688. if [ -f /opt/retropie/configs/all/runcommand-onend.sh ]
  689. then
  690. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tFILE FOUND\n" >> "${logfile}"
  691. # check if there's a call to RCLONE_SCRIPT
  692. if grep -Fq "~/scripts/rclone_script/rclone_script.sh" /opt/retropie/configs/all/runcommand-onend.sh
  693. then
  694. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tCALL FOUND\n" >> "${logfile}"
  695. return 0
  696. else
  697. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tCALL NOT FOUND\n" >> "${logfile}"
  698. # add call
  699. printf "\n~/scripts/rclone_script/rclone_script.sh \"up\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"\n" >> /opt/retropie/configs/all/runcommand-onend.sh
  700. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tCALL CREATED\n" >> "${logfile}"
  701. return 1
  702. fi
  703. else
  704. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tFILE NOT FOUND\n" >> "${logfile}"
  705. printf "#!/bin/bash\n~/scripts/rclone_script/rclone_script.sh \"up\" \"\$1\" \"\$2\" \"\$3\" \"\$4\"\n" >> /opt/retropie/configs/all/runcommand-onend.sh
  706. printf "$(date +%FT%T%:z):\t5aRUNCOMMAND-ONEND\tFILE CREATED\n" >> "${logfile}"
  707. return 1
  708. fi
  709. }
  710. function 6LocalSAVEFILEDirectory ()
  711. {
  712. # 6a. Test for local SAVEFILE directory
  713. updateStep "6a" "in progress" 70
  714. 6aCheckLocalBaseDirectory
  715. case $? in
  716. 0) updateStep "6a" "found" 75 ;;
  717. 1) updateStep "6a" "created" 75 ;;
  718. esac
  719. # 6b. Check local <SYSTEM> directories
  720. updateStep "6b" "in progress" 75
  721. 6bCheckLocalSystemDirectories
  722. case $? in
  723. 0) updateStep "6b" "found" 80 ;;
  724. 1) updateStep "6b" "created" 80 ;;
  725. esac
  726. }
  727. # Checks if the local base SAVEFILE directory exists
  728. # RETURN
  729. # 0 > directory exists
  730. # 1 > directory has been created
  731. function 6aCheckLocalBaseDirectory ()
  732. {
  733. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tSTART\n" >> "${logfile}"
  734. # check if local base dir exists
  735. if [ -d ~/RetroPie/saves ]
  736. then
  737. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tFOUND\n" >> "${logfile}"
  738. return 0
  739. else
  740. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tNOT FOUND\n" >> "${logfile}"
  741. mkdir ~/RetroPie/saves
  742. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tCREATED directory\n" >> "${logfile}"
  743. # share that new directory on the network
  744. if [[ $(grep -c "\[saves\]" /etc/samba/smb.conf) -eq 0 ]]
  745. then
  746. # add new share to SAMBA
  747. 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
  748. # restart SAMBA
  749. sudo service smbd restart
  750. printf "$(date +%FT%T%:z):\t6aCheckLocalBaseDirectory\tCREATED network share\n" >> "${logfile}"
  751. fi
  752. return 1
  753. fi
  754. }
  755. # Checks if the local system specific directories exists
  756. # RETURN
  757. # 0 > all found
  758. # 1 > created at least one
  759. function 6bCheckLocalSystemDirectories ()
  760. {
  761. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tSTART\n" >> "${logfile}"
  762. local retval=0
  763. # for each directory in ROMS directory...
  764. for directory in ~/RetroPie/roms/*
  765. do
  766. system="${directory##*/}"
  767. # check if ROMS directory is a real directory and not a SymLink
  768. if [ ! -L ~/RetroPie/roms/${system} ]
  769. then
  770. # check if same directory exists in SAVES, create if necessary
  771. if [ -d ~/RetroPie/saves/${system} ]
  772. then
  773. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tFOUND directory ${system}\n" >> "${logfile}"
  774. else
  775. mkdir ~/RetroPie/saves/${system}
  776. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tCREATED directory ${system}\n" >> "${logfile}"
  777. retval=1
  778. fi
  779. else
  780. # check if same SymLink exists in SAVES, create if necessary
  781. if [ -L ~/RetroPie/saves/${system} ]
  782. then
  783. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tFOUND symlink ${system}\n" >> "${logfile}"
  784. else
  785. ln -s $(readlink ~/RetroPie/roms/${system}) ~/RetroPie/saves/${system}
  786. printf "$(date +%FT%T%:z):\t6bCheckLocalSystemDirectories\tCREATED symlink ${system}\n" >> "${logfile}"
  787. retval=1
  788. fi
  789. fi
  790. done
  791. return ${retval}
  792. }
  793. function 7RemoteSAVEFILEDirectory ()
  794. {
  795. # 7a. Check remote base directory
  796. updateStep "7a" "in progress" 80
  797. 7aCheckRemoteBaseDirectory
  798. case $? in
  799. 0) updateStep "7a" "found" 85 ;;
  800. 1) updateStep "7a" "created" 85 ;;
  801. 255) updateStep "7a" "failed" 80 ;;
  802. esac
  803. # 7b. Check remote <system> directories
  804. updateStep "7b" "in progress" 85
  805. 7bCheckRemoteSystemDirectories
  806. case $? in
  807. 0) updateStep "7b" "found" 90 ;;
  808. 1) updateStep "7b" "created" 90 ;;
  809. 255) updateStep "7b" "failed" 85 ;;
  810. esac
  811. }
  812. # Checks if the remote base SAVEFILE directory exists
  813. # RETURN
  814. # 0 > directory exists
  815. # 1 > directory has been created
  816. # 255 > error while creating directory
  817. function 7aCheckRemoteBaseDirectory ()
  818. {
  819. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tSTART\n" >> "${logfile}"
  820. # try to read remote base dir
  821. rclone lsf "retropie:${remotebasedir}/" > /dev/null 2>&1
  822. case $? in
  823. 0)
  824. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tFOUND\n" >> "${logfile}"
  825. return 0
  826. ;;
  827. 3)
  828. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tNOT FOUND\n" >> "${logfile}"
  829. rclone mkdir "retropie:${remotebasedir}" >> "${logfile}"
  830. case $? in
  831. 0)
  832. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tCREATED\n" >> "${logfile}"
  833. return 1
  834. ;;
  835. *)
  836. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tERROR\n" >> "${logfile}"
  837. return 255
  838. ;;
  839. esac
  840. ;;
  841. *)
  842. printf "$(date +%FT%T%:z):\t7aCheckRemoteBaseDirectory\tERROR\n" >> "${logfile}"
  843. return 255
  844. ;;
  845. esac
  846. }
  847. # Checks if the remote system specific directories exist
  848. # RETURN
  849. # 0 > all found
  850. # 1 > created at least one
  851. # 255 > error while creating directory
  852. function 7bCheckRemoteSystemDirectories ()
  853. {
  854. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tSTART\n" >> "${logfile}"
  855. local retval=0
  856. local output
  857. # list all directories in $REMOTEBASEDIR from remote
  858. remoteDirs=$(rclone lsf --dirs-only "retropie:${remotebasedir}/")
  859. # for each directory in ROMS directory...
  860. for directory in ~/RetroPie/roms/*
  861. do
  862. system="${directory##*/}"
  863. # use grep to search $SYSTEM in $DIRECTORIES
  864. output=$(grep "${system}/" -nx <<< "${remoteDirs}")
  865. if [ "${output}" = "" ]
  866. then
  867. # create system dir
  868. rclone mkdir retropie:"${remotebasedir}/${system}"
  869. if [[ $? -eq 0 ]]
  870. then
  871. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tCREATED ${system}\n" >> "${logfile}"
  872. # put note if local directory is a symlink
  873. if [ -L ~/RetroPie/saves/${system} ]
  874. then
  875. 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
  876. rclone copy ~/scripts/rclone_script/readme.txt retropie:"${remotebasedir}/${system}/"
  877. rm ~/scripts/rclone_script/readme.txt
  878. fi
  879. retval=1
  880. else
  881. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tERROR\n" >> "${logfile}"
  882. return 255
  883. fi
  884. else
  885. printf "$(date +%FT%T%:z):\t7bCheckRemoteSystemDirectories\tFOUND ${system}\n" >> "${logfile}"
  886. fi
  887. done
  888. return ${retval}
  889. }
  890. function 8ConfigureRETROARCH ()
  891. {
  892. # 8a. Setting local SAVEFILE directory
  893. updateStep "8a" "in progress" 90
  894. 8aSetLocalSAVEFILEDirectory
  895. updateStep "8a" "done" 95
  896. }
  897. # Sets parameters in all system specific configuration files
  898. function 8aSetLocalSAVEFILEDirectory ()
  899. {
  900. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tSTART\n" >> "${logfile}"
  901. local retval
  902. # for each directory...
  903. for directory in /opt/retropie/configs/*
  904. do
  905. system="${directory##*/}"
  906. # skip directory ALL
  907. if [ "${system}" = "all" ]
  908. then
  909. continue
  910. fi
  911. # test if there's a RETROARCH.CFG
  912. if [ -f "${directory}/retroarch.cfg" ]
  913. then
  914. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tFOUND retroarch.cfg FOR ${system}\n" >> "${logfile}"
  915. # test file for SAVEFILE_DIRECTORY
  916. retval=$(grep -i "^savefile_directory = " ${directory}/retroarch.cfg)
  917. if [ ! "${retval}" = "" ]
  918. then
  919. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tREPLACED savefile_directory\n" >> "${logfile}"
  920. # replace existing parameter
  921. sed -i "/^savefile_directory = /c\savefile_directory = \"~/RetroPie/saves/${system}\"" ${directory}/retroarch.cfg
  922. else
  923. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tADDED savefile_directory\n" >> "${logfile}"
  924. # create new parameter above "#include..."
  925. 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
  926. fi
  927. # test file for SAVESTATE_DIRECTORY
  928. retval=$(grep -i "^savestate_directory = " ${directory}/retroarch.cfg)
  929. if [ ! "${retval}" = "" ]
  930. then
  931. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tREPLACED savestate_directory\n" >> "${logfile}"
  932. # replace existing parameter
  933. sed -i "/^savestate_directory = /c\savestate_directory = \"~/RetroPie/saves/${system}\"" ${directory}/retroarch.cfg
  934. else
  935. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tADDED savestate_directory\n" >> "${logfile}"
  936. # create new parameter above "#include..."
  937. 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
  938. fi
  939. fi
  940. done
  941. printf "$(date +%FT%T%:z):\t8aSetLocalSAVEFILEDirectory\tDONE\n" >> "${logfile}"
  942. }
  943. function 9Finalize ()
  944. {
  945. # 9a. Saving configuration
  946. updateStep "9a" "in progress" 95
  947. 9aSaveConfiguration
  948. updateStep "9a" "done" 100
  949. }
  950. # Saves the configuration of RCLONE_SCRIPT
  951. function 9aSaveConfiguration ()
  952. {
  953. printf "$(date +%FT%T%:z):\t9aSaveConfiguration\tSTART\n" >> "${logfile}"
  954. echo "remotebasedir=${remotebasedir}" > ~/scripts/rclone_script/rclone_script.ini
  955. echo "showNotifications=${shownotifications}" >> ~/scripts/rclone_script/rclone_script.ini
  956. echo "syncOnStartStop=\"TRUE\"" >> ~/scripts/rclone_script/rclone_script.ini
  957. echo "logfile=~/scripts/rclone_script/rclone_script.log" >> ~/scripts/rclone_script/rclone_script.ini
  958. echo "neededConnection=${neededConnection}" >> ~/scripts/rclone_script/rclone_script.ini
  959. echo "debug=0" >> ~/scripts/rclone_script/rclone_script.ini
  960. printf "$(date +%FT%T%:z):\t9aSaveConfiguration\tDONE\n" >> "${logfile}"
  961. }
  962. ########
  963. # MAIN #
  964. ########
  965. if [ "${branch}" == "beta" ]
  966. then
  967. dialogBetaWarning
  968. fi
  969. installer