rclone_script-install.sh 32 KB

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