rclone_script-install-dialog.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. #!/bin/bash
  2. # define colors for output
  3. NORMAL="\Zn"
  4. BLACK="\Z0"
  5. RED="\Z1"
  6. GREEN="\Z2"
  7. YELLOW="\Z3"
  8. BLUE="\Z4"
  9. MAGENTA="\Z5"
  10. CYAN="\Z6"
  11. WHITE="\Z7"
  12. BOLD="\Zb"
  13. REVERSE="\Zr"
  14. UNDERLINE="\Zu"
  15. # global variables
  16. url="https://raw.githubusercontent.com/Jandalf81/rclone_script"
  17. branch="beta"
  18. remotebasedir = ""
  19. backtitle="RCLONE_SCRIPT installer"
  20. # Welcome dialog
  21. dialog \
  22. --backtitle "${backtitle}" \
  23. --title "Welcome" \
  24. --ascii-lines \
  25. --colors \
  26. --no-collapse \
  27. --cr-wrap \
  28. --yesno \
  29. "\nThis script will configure RetroPie so that your savefiles and statefiles are synchronized with a remote destination. Several packages and scripts will be installed, see\n\n https://github.com/Jandalf81/rclone_script/blob/master/ReadMe.md\n\nfor a rundown.\n\nAre you sure you wish to continue?" \
  30. 28 110 2>&1 > /dev/tty \
  31. || exit
  32. # Warn the user if they are using the BETA branch
  33. function dialogBetaWarning ()
  34. {
  35. dialog \
  36. --backtitle "${backtitle}" \
  37. --title "Beta Warning" \
  38. --ascii-lines \
  39. --colors \
  40. --no-collapse \
  41. --cr-wrap \
  42. --yesno \
  43. "\n${RED}${UNDERLINE}WARNING!${NORMAL}\n\nYou are about to install a beta version!\nAre you ${RED}REALLY${NORMAL} sure you want to continue?" \
  44. 10 50 2>&1 > /dev/tty \
  45. || exit
  46. }
  47. # Installer
  48. function installer ()
  49. {
  50. initSteps
  51. dialogShowProgress 0
  52. 1RCLONE
  53. 2PNGVIEW
  54. 3IMAGEMAGICK
  55. 4RCLONE_SCRIPT
  56. }
  57. # Initialize array $STEPS()
  58. # OUTPUT
  59. # $steps()
  60. function initSteps ()
  61. {
  62. steps[1]="1. RCLONE"
  63. steps[2]=" 1a. Testing for RCLONE binary [ waiting... ]"
  64. steps[3]=" 1b. Getting RCLONE binary [ waiting... ]"
  65. steps[4]=" 1c. Testing RCLONE remote [ waiting... ]"
  66. steps[5]=" 1d. Create RCLONE remote [ waiting... ]"
  67. steps[6]="2. PNGVIEW"
  68. steps[7]=" 2a. Testing for PNGVIEW binary [ waiting... ]"
  69. steps[8]=" 2b. Getting PNGVIEW source [ waiting... ]"
  70. steps[9]=" 2c. Compiling PNGVIEW [ waiting... ]"
  71. steps[10]="3. IMAGEMAGICK"
  72. steps[11]=" 3a. Testing for IMAGEMAGICK [ waiting... ]"
  73. steps[12]=" 3b. Getting IMAGEMAGICK [ waiting... ]"
  74. steps[13]="4. RCLONE_SCRIPT"
  75. steps[14]=" 4a. Getting RCLONE_SCRIPT [ waiting... ]"
  76. steps[15]=" 4b. Creating RCLONE_SCRIPT menu item [ waiting... ]"
  77. steps[16]=" 4c. Configure RCLONE_SCRIPT [ waiting... ]"
  78. steps[17]="5. RUNCOMMAND"
  79. steps[18]=" 5a. RUNCOMMAND-ONSTART [ waiting... ]"
  80. steps[19]=" 5b. RUNCOMMAND-ONEND [ waiting... ]"
  81. steps[20]="6. Local SAVEFILE directory"
  82. steps[21]=" 6a. Test for local SAVEFILE directory [ waiting... ]"
  83. steps[22]=" 6b. Create local SAVEFILE directory [ waiting... ]"
  84. steps[23]="7. Remote SAVEFILE directory"
  85. steps[24]=" 7a. Test for local SAVEFILE directory [ waiting... ]"
  86. steps[25]=" 7b. Create local SAVEFILE directory [ waiting... ]"
  87. steps[26]="8. Configure RETROARCH"
  88. steps[27]=" 8a. Setting local SAVEFILE directory [ waiting... ]"
  89. steps[28]="9. Finalizing"
  90. steps[29]=" 9a. Saving configuration [ waiting... ]"
  91. }
  92. # Build progress from array $STEPS()
  93. # INPUT
  94. # $steps()
  95. # OUTPUT
  96. # $progress
  97. function buildProgress ()
  98. {
  99. progress=""
  100. for ((i=0; i<=${#steps[*]}; i++))
  101. do
  102. progress="${progress}${steps[i]}\n"
  103. done
  104. }
  105. # Show Progress dialog
  106. # INPUT
  107. # 1 > Percentage to show in dialog
  108. # $backtitle
  109. # $progress
  110. function dialogShowProgress ()
  111. {
  112. local percent="$1"
  113. buildProgress
  114. clear
  115. clear
  116. echo "${percent}" | dialog \
  117. --stdout \
  118. --colors \
  119. --ascii-lines \
  120. --no-collapse \
  121. --cr-wrap \
  122. --backtitle "${backtitle}" \
  123. --title "Installer" \
  124. --gauge "${progress}" 36 90 0 \
  125. 2>&1 > /dev/tty
  126. sleep 1
  127. }
  128. # Update item of $STEPS() and show updated progress dialog
  129. # INPUT
  130. # 1 > Number of step to update
  131. # 2 > New status for step
  132. # 3 > Percentage to show in progress dialog
  133. # $steps()
  134. # OUTPUT
  135. # $steps()
  136. function updateStep ()
  137. {
  138. local step="$1"
  139. local newStatus="$2"
  140. local percent="$3"
  141. local oldline
  142. local newline
  143. # translate and colorize $NEWSTATUS
  144. case "${newStatus}" in
  145. "waiting") newStatus="[ ${NORMAL}WAITING...${NORMAL} ]" ;;
  146. "in progress") newStatus="[ ${NORMAL}IN PROGRESS${NORMAL} ]" ;;
  147. "done") newStatus="[ ${GREEN}DONE${NORMAL} ]" ;;
  148. "found") newStatus="[ ${GREEN}FOUND${NORMAL} ]" ;;
  149. "not found") newStatus="[ ${RED}NOT FOUND${NORMAL} ]" ;;
  150. "failed") newStatus="[ ${RED}FAILED${NORMAL} ]" ;;
  151. "skipped") newStatus="[ ${YELLOW}${BOLD}SKIPPED${NORMAL} ]" ;;
  152. *) newStatus="[ ${RED}UNDEFINED${NORMAL} ]" ;;
  153. esac
  154. # search $STEP in $STEPS
  155. for ((i=0; i<${#steps[*]}; i++))
  156. do
  157. if [[ ${steps[i]} =~ .*$step.* ]]
  158. then
  159. # update $STEP with $NEWSTATUS
  160. oldline="${steps[i]}"
  161. oldline="${oldline%%[*}"
  162. newline="${oldline}${newStatus}"
  163. steps[i]="${newline}"
  164. break
  165. fi
  166. done
  167. # show progress dialog
  168. dialogShowProgress ${percent}
  169. }
  170. function 1RCLONE ()
  171. {
  172. # 1a. Testing for RCLONE binary
  173. updateStep "1a" "in progress" 0
  174. 1aTestRCLONE
  175. if [[ $? -eq 0 ]]
  176. then
  177. updateStep "1a" "found" 5
  178. updateStep "1b" "skipped" 10
  179. else
  180. updateStep "1a" "not found" 5
  181. # 1b. Getting RCLONE binary
  182. updateStep "1b" "in progress" 5
  183. 1bInstallRCLONE
  184. if [[ $? -eq 0 ]]
  185. then
  186. updateStep "1b" "done" 10
  187. else
  188. updateStep "1b" "failed" 5
  189. fi
  190. fi
  191. # 1c. Testing RCLONE configuration
  192. updateStep "1c" "in progress" 10
  193. 1cTestRCLONEremote
  194. if [[ $? -eq 0 ]]
  195. then
  196. updateStep "1c" "found" 15
  197. updateStep "1d" "skipped" 20
  198. else
  199. updateStep "1c" "not found" 15
  200. # 1d. Create RCLONE remote
  201. updateStep "1d" "in progress" 15
  202. 1dCreateRCLONEremote
  203. updateStep "1d" "done" 20
  204. fi
  205. }
  206. # Checks if RCLONE is installed
  207. # RETURN
  208. # 0 > RCLONE is installed
  209. # 1 > RCLONE is not installed
  210. function 1aTestRCLONE ()
  211. {
  212. printf "$(date +%FT%T%:z):\t1aTestRCLONE\tSTART\n" >> ./rclone_script-install.log
  213. if [ -f /usr/bin/rclone ]
  214. then
  215. printf "$(date +%FT%T%:z):\t1aTestRCLONE\tFOUND\n" >> ./rclone_script-install.log
  216. return 0
  217. else
  218. printf "$(date +%FT%T%:z):\t1aTestRCLONE\tNOT FOUND\n" >> ./rclone_script-install.log
  219. return 1
  220. fi
  221. }
  222. # Installs RCLONE by download
  223. # RETURN
  224. # 0 > RCLONE has been installed
  225. # 1 > Error while installing RCLONE
  226. function 1bInstallRCLONE ()
  227. {
  228. printf "$(date +%FT%T%:z):\t1bInstallRCLONE\tSTART\n" >> ./rclone_script-install.log
  229. # TODO get RCLONE for 64bit
  230. { # try
  231. # get binary
  232. wget -P ~ https://downloads.rclone.org/rclone-current-linux-arm.zip --append-output=./rclone_script-install.log &&
  233. unzip ~/rclone-current-linux-arm.zip -d ~ >> ./rclone_script-install.log &&
  234. cd ~/rclone-v* &&
  235. # move binary
  236. sudo mv rclone /usr/bin >> ./rclone_script-install.log &&
  237. sudo chown root:root /usr/bin/rclone >> ./rclone_script-install.log &&
  238. sudo chmod 755 /usr/bin/rclone >> ./rclone_script-install.log &&
  239. cd ~ &&
  240. # remove temp files
  241. rm ~/rclone-current-linux-arm.zip >> ./rclone_script-install.log &&
  242. rm -r ~/rclone-v* >> ./rclone_script-install.log &&
  243. printf "$(date +%FT%T%:z):\t1bInstallRCLONE\tDONE\n" >> ./rclone_script-install.log
  244. return 0
  245. } || { #catch
  246. printf "$(date +%FT%T%:z):\t1bInstallRCLONE\tERROR\n" >> ./rclone_script-install.log
  247. # remove temp files
  248. rm ~/rclone-current-linux-arm.zip >> ./rclone_script-install.log &&
  249. rm -r ~/rclone-v* >> ./rclone_script-install.log &&
  250. return 1
  251. }
  252. }
  253. # Checks if there's a RCLONE remote called RETROPIE
  254. # RETURN
  255. # 0 > remote RETROPIE has been found
  256. # 1 > no remote RETROPIE found
  257. function 1cTestRCLONEremote ()
  258. {
  259. printf "$(date +%FT%T%:z):\t1cTestRCLONEremote\tSTART\n" >> ./rclone_script-install.log
  260. local remotes=$(rclone listremotes)
  261. local retval=$(grep -i "^retropie:" <<< ${remotes})
  262. if [ "${retval}" == "retropie:" ]
  263. then
  264. printf "$(date +%FT%T%:z):\t1cTestRCLONEremote\tFOUND\n" >> ./rclone_script-install.log
  265. return 0
  266. else
  267. printf "$(date +%FT%T%:z):\t1cTestRCLONEremote\tNOT FOUND\n" >> ./rclone_script-install.log
  268. return 1
  269. fi
  270. }
  271. # Tells the user to create a new RCLONE remote called RETROPIE
  272. # RETURN
  273. # 0 > remote RETROPIE has been created (no other OUTPUT possible)
  274. function 1dCreateRCLONEremote ()
  275. {
  276. printf "$(date +%FT%T%:z):\t1dCreateRCLONEremote\tSTART\n" >> ./rclone_script-install.log
  277. dialog \
  278. --stdout \
  279. --colors \
  280. --ascii-lines \
  281. --no-collapse \
  282. --cr-wrap \
  283. --backtitle "${backtitle}" \
  284. --title "Installer" \
  285. --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 \
  286. 2>&1 > /dev/tty
  287. rclone config
  288. 1cTestRCLONEremote
  289. if [[ $? -eq 1 ]]
  290. then
  291. dialog \
  292. --stdout \
  293. --colors \
  294. --ascii-lines \
  295. --no-collapse \
  296. --cr-wrap \
  297. --backtitle "${backtitle}" \
  298. --title "Installer" \
  299. --msgbox "\nNo remote ${RED}retropie${NORMAL} found.\nPlease try again." 20 50 \
  300. 2>&1 > /dev/tty
  301. 1dCreateRCLONEremote
  302. else
  303. printf "$(date +%FT%T%:z):\t1dCreateRCLONEremote\tFOUND\n" >> ./rclone_script-install.log
  304. return 0
  305. fi
  306. }
  307. function 2PNGVIEW ()
  308. {
  309. # 2a. Testing for PNGVIEW binary
  310. updateStep "2a" "in progress" 20
  311. 2aTestPNGVIEW
  312. if [[ $? -eq 0 ]]
  313. then
  314. updateStep "2a" "found" 25
  315. updateStep "2b" "skipped" 30
  316. updateStep "2c" "skipped" 35
  317. else
  318. updateStep "2a" "not found" 25
  319. # 2b. Getting PNGVIEW source
  320. updateStep "2b" "in progress" 25
  321. 2bGetPNGVIEWsource
  322. if [[ $? -eq 0 ]]
  323. then
  324. updateStep "2b" "done" 30
  325. # 2c. Compiling PNGVIEW
  326. updateStep "2c" "in progress" 30
  327. 2cCompilePNGVIEW
  328. if [[ $? -eq 0 ]]
  329. then
  330. updateStep "2c" "done" 35
  331. else
  332. updateStep "2c" "failed" 30
  333. exit
  334. fi
  335. else
  336. updateStep "2b" "failed" 25
  337. exit
  338. fi
  339. fi
  340. }
  341. # Checks if PNGVIEW is installed
  342. # RETURN
  343. # 0 > PNGVIEW is installed
  344. # 1 > PNGVIEW is not installed
  345. function 2aTestPNGVIEW ()
  346. {
  347. printf "$(date +%FT%T%:z):\t2aTestPNGVIEW\tSTART\n" >> ./rclone_script-install.log
  348. if [ -f /usr/bin/pngview ]
  349. then
  350. printf "$(date +%FT%T%:z):\t2aTestPNGVIEW\tFOUND\n" >> ./rclone_script-install.log
  351. return 0
  352. else
  353. printf "$(date +%FT%T%:z):\t2aTestPNGVIEW\tNOT FOUND\n" >> ./rclone_script-install.log
  354. return 1
  355. fi
  356. }
  357. # Gets PNGVIEW source
  358. # RETURN
  359. # 0 > source downloaded and unzipped
  360. # 1 > no source downloaded, removed temp files
  361. function 2bGetPNGVIEWsource ()
  362. {
  363. printf "$(date +%FT%T%:z):\t2bGetPNGVIEWsource\tSTART\n" >> ./rclone_script-install.log
  364. { #try
  365. wget -P ~ https://github.com/AndrewFromMelbourne/raspidmx/archive/master.zip --append-output=./rclone_script-install.log &&
  366. unzip ~/master.zip -d ~ >> ./rclone_script-install.log &&
  367. printf "$(date +%FT%T%:z):\t2bGetPNGVIEWsource\tDONE\n" >> ./rclone_script-install.log &&
  368. return 0
  369. } || { #catch
  370. printf "$(date +%FT%T%:z):\t2bGetPNGVIEWsource\tERROR\n" >> ./rclone_script-install.log &&
  371. rm ~/master.zip >> ./rclone_script-install.log &&
  372. sudo rm -r ~/raspidmx-master >> ./rclone_script-install.log &&
  373. return 1
  374. }
  375. }
  376. # Compiles PNGVIEW source, moves binaries
  377. # RETURN
  378. # 0 > compiled without errors, moved binaries, removed temp files
  379. # 1 > errors while compiling, removed temp files
  380. function 2cCompilePNGVIEW ()
  381. {
  382. printf "$(date +%FT%T%:z):\t2cCompilePNGVIEW\tSTART\n" >> ./rclone_script-install.log
  383. { #try
  384. # compile
  385. # cd ~/raspidmx-master &&
  386. make --directory=~/raspidmx-master >> ./rclone_script-install.log &&
  387. # move binary files
  388. sudo mv ~/raspidmx-master/pngview/pngview /usr/bin >> ./rclone_script-install.log &&
  389. sudo mv ~/raspidmx-master/lib/libraspidmx.so.1 /usr/lib >> ./rclone_script-install.log &&
  390. sudo chown root:root /usr/bin/pngview >> ./rclone_script-install.log &&
  391. sudo chmod 755 /usr/bin/pngview >> ./rclone_script-install.log &&
  392. # remove temp files
  393. rm ~/master.zip >> ./rclone_script-install.log &&
  394. sudo rm -r ~/raspidmx-master >> ./rclone_script-install.log &&
  395. printf "$(date +%FT%T%:z):\t2cCompilePNGVIEW\tDONE\n" >> ./rclone_script-install.log &&
  396. return 0
  397. } || { #catch
  398. printf "$(date +%FT%T%:z):\t2cCompilePNGVIEW\tERROR\n" >> ./rclone_script-install.log &&
  399. # remove temp files
  400. rm ~/master.zip >> ./rclone_script-install.log &&
  401. sudo rm -r ~/raspidmx-master >> ./rclone_script-install.log &&
  402. return 1
  403. }
  404. }
  405. function 3IMAGEMAGICK ()
  406. {
  407. # 3a. Testing for IMAGEMAGICK
  408. updateStep "3a" "in progress" 35
  409. 3aTestIMAGEMAGICK
  410. if [[ $? -eq 0 ]]
  411. then
  412. updateStep "3a" "found" 40
  413. updateStep "3b" "skipped" 45
  414. else
  415. updateStep "3a" "not found" 40
  416. # 3b. Getting IMAGEMAGICK
  417. updateStep "3b" "in progress" 40
  418. 3bInstallIMAGEMAGICK
  419. if [[ $? -eq 0 ]]
  420. then
  421. updateStep "3b" "done" 45
  422. else
  423. updateStep "3b" "failed" 40
  424. fi
  425. fi
  426. }
  427. # Checks is IMAGEMAGICK is installed
  428. # RETURN
  429. # 0 > IMAGEMAGICK is installed
  430. # 1 > IMAGEMAGICK is not installed
  431. function 3aTestIMAGEMAGICK ()
  432. {
  433. printf "$(date +%FT%T%:z):\t3aTestIMAGEMAGICK\tSTART\n" >> ./rclone_script-install.log
  434. if [ -f /usr/bin/convert ]
  435. then
  436. printf "$(date +%FT%T%:z):\t3aTestIMAGEMAGICK\tFOUND\n" >> ./rclone_script-install.log
  437. return 0
  438. else
  439. printf "$(date +%FT%T%:z):\t3aTestIMAGEMAGICK\tNOT FOUND\n" >> ./rclone_script-install.log
  440. return 1
  441. fi
  442. }
  443. # Installs IMAGEMAGICK via APT-GET
  444. # RETURN
  445. # 0 > IMAGEMAGICK has been installed
  446. # 1 > Error while installing IMAGEMAGICK
  447. function 3bInstallIMAGEMAGICK ()
  448. {
  449. printf "$(date +%FT%T%:z):\t3bInstallIMAGEMAGICK\tSTART\n" >> ./rclone_script-install.log
  450. sudo apt-get update >> ./rclone_script-install.log &&
  451. sudo apt-get --yes install imagemagick >> ./rclone_script-install.log &&
  452. if [[ $? -eq 0 ]]
  453. then
  454. printf "$(date +%FT%T%:z):\t3bInstallIMAGEMAGICK\tDONE\n" >> ./rclone_script-install.log &&
  455. return 0
  456. else
  457. printf "$(date +%FT%T%:z):\t3bInstallIMAGEMAGICK\tERROR\n" >> ./rclone_script-install.log &&
  458. return 1
  459. fi
  460. }
  461. function 4RCLONE_SCRIPT ()
  462. {
  463. # 4a. Getting RCLONE_SCRIPT
  464. updateStep "4a" "in progress" 45
  465. 4aGetRCLONE_SCRIPT
  466. if [[ $? -eq 0 ]]
  467. then
  468. updateStep "4a" "done" 50
  469. else
  470. updateStep "4a" "failed" 45
  471. exit
  472. fi
  473. # 4b. Creating RCLONE_SCRIPT menu item
  474. updateStep "4b" "in progress" 50
  475. 4bCreateRCLONE_SCRIPTMenuItem
  476. if [[ $? -eq 0 ]]
  477. then
  478. updateStep "4b" "done" 55
  479. else
  480. updateStep "4b" "failed" 50
  481. exit
  482. fi
  483. # 4c. Configure RCLONE_SCRIPT
  484. }
  485. # Gets RCLONE_SCRIPT
  486. # RETURN
  487. # 0 > downloaded successfully
  488. # 1 > errors while downloading
  489. function 4aGetRCLONE_SCRIPT ()
  490. {
  491. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tSTART\n" >> ./rclone_script-install.log
  492. # create directory if necessary
  493. if [ ! -d ~/scripts/rclone_script ]
  494. then
  495. mkdir ~/scripts/rclone_script >> ./rclone_script-install.log
  496. fi
  497. { #try
  498. # get script files
  499. wget -N -P ~/scripts/rclone_script ${url}/${branch}/rclone_script.sh --append-output=./rclone_script-install.log &&
  500. wget -N -P ~/scripts/rclone_script ${url}/${branch}/rclone_script-menu.sh --append-output=./rclone_script-install.log &&
  501. wget -N -P ~/scripts/rclone_script ${url}/${branch}/rclone_script-uninstall.sh --append-output=./rclone_script-install.log &&
  502. # change mod
  503. chmod +x ~/scripts/rclone_script/rclone_script.sh >> ./rclone_script-install.log &&
  504. chmod +x ~/scripts/rclone_script/rclone_script-menu.sh >> ./rclone_script-install.log &&
  505. chmod +x ~/scripts/rclone_script/rclone_script-uninstall.sh >> ./rclone_script-install.log &&
  506. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tDONE\n" >> ./rclone_script-install.log &&
  507. return 0
  508. } || { # catch
  509. printf "$(date +%FT%T%:z):\t4aGetRCLONE_SCRIPT\tERROR\n" >> ./rclone_script-install.log
  510. return 1
  511. }
  512. }
  513. # Creates a menu item for RCLONE_SCRIPT in RetroPie menu
  514. # RETURN
  515. # 0 > menu item has been found or created
  516. # 1 > error while creating menu item
  517. function 4bCreateRCLONE_SCRIPTMenuItem ()
  518. {
  519. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tSTART\n" >> ./rclone_script-install.log
  520. # move menu script
  521. mv --force ~/scripts/rclone_script/rclone_script-menu.sh ~/RetroPie/retropiemenu >> ./rclone_script-install.log
  522. # check if menu item exists
  523. if grep -Fq "<path>./rclone_script-menu.sh</path>" ~/.emulationstation/gamelists/retropie/gamelist.xml
  524. then
  525. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tFOUND\n" >> ./rclone_script-install.log
  526. return 0
  527. else
  528. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tNOT FOUND\n" >> ./rclone_script-install.log
  529. sed -i "/<\/gameList>/c\\\\t<game>\n\t\t<path>.\/rclone_script-menu.sh<\/path>\n\t\t<name>RCLONE_SCRIPT menu<\/name>\n\t\t<desc>Customize RCLONE_SCRIPT, start a full sync, uninstall RCLONE_SCRIPT<\/desc>\n\t\t<image></image>\n\t<\/game>\n<\/gameList>" ~/.emulationstation/gamelists/retropie/gamelist.xml
  530. if [[ $? -eq 0 ]]
  531. then
  532. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tCREATED\n" >> ./rclone_script-install.log
  533. return 0
  534. else
  535. printf "$(date +%FT%T%:z):\t4bCreateRCLONE_SCRIPTMenuItem\tERROR\n" >> ./rclone_script-install.log
  536. return 1
  537. fi
  538. fi
  539. }
  540. # main
  541. if [ "${branch}" == "beta" ]
  542. then
  543. dialogBetaWarning
  544. fi
  545. installer