rclone_script-uninstall-dialog.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. backtitle="RCLONE_SCRIPT uninstaller"
  16. logfile=~/scripts/rclone_script/rclone_script-uninstall.log
  17. ##################
  18. # WELCOME DIALOG #
  19. ##################
  20. dialog \
  21. --stdout \
  22. --backtitle "${backtitle}" \
  23. --title "Welcome" \
  24. --ascii-lines \
  25. --colors \
  26. --no-collapse \
  27. --cr-wrap \
  28. --yesno \
  29. "\nThis script will ${RED}uninstall RCLONE_SCRIPT${NORMAL}. If you do this, your savefiles will no longer be synchonized!\n\nAre you sure you wish to continue?" \
  30. 20 90 2>&1 > /dev/tty \
  31. || exit
  32. ####################
  33. # DIALOG FUNCTIONS #
  34. ####################
  35. # Build progress from array $STEPS()
  36. # INPUT
  37. # $steps()
  38. # OUTPUT
  39. # $progress
  40. function buildProgress ()
  41. {
  42. progress=""
  43. for ((i=0; i<=${#steps[*]}; i++))
  44. do
  45. progress="${progress}${steps[i]}\n"
  46. done
  47. }
  48. # Show Progress dialog
  49. # INPUT
  50. # 1 > Percentage to show in dialog
  51. # $backtitle
  52. # $progress
  53. function dialogShowProgress ()
  54. {
  55. local percent="$1"
  56. buildProgress
  57. clear
  58. clear
  59. echo "${percent}" | dialog \
  60. --stdout \
  61. --colors \
  62. --ascii-lines \
  63. --no-collapse \
  64. --cr-wrap \
  65. --backtitle "${backtitle}" \
  66. --title "Uninstaller" \
  67. --gauge "${progress}" 36 90 0 \
  68. 2>&1 > /dev/tty
  69. sleep 1
  70. }
  71. ##################
  72. # STEP FUNCTIONS #
  73. ##################
  74. # Initialize array $STEPS()
  75. # OUTPUT
  76. # $steps()
  77. function initSteps ()
  78. {
  79. steps[1]="1. RCLONE"
  80. steps[2]=" 1a. Remove RCLONE configuration [ waiting... ]"
  81. steps[3]=" 1b. Remove RCLONE binary [ waiting... ]"
  82. steps[4]="2. PNGVIEW"
  83. steps[5]=" 2a. Remove PNGVIEW binary [ waiting... ]"
  84. steps[6]="3. IMAGEMAGICK"
  85. steps[7]=" 3a. Remove IMAGEMAGICK binary [ waiting... ]"
  86. steps[8]="4. RCLONE_SCRIPT"
  87. steps[9]=" 4a. Remove RCLONE_SCRIPT files [ waiting... ]"
  88. steps[10]=" 4b. Remove RCLONE_SCRIPT menu item [ waiting... ]"
  89. steps[11]="5. RUNCOMMAND"
  90. steps[12]=" 5a. Remove call from RUNCOMMAND-ONSTART [ waiting... ]"
  91. steps[13]=" 5b. Remove call from RUNCOMMAND-ONEND [ waiting... ]"
  92. steps[14]="6. Local SAVEFILE directory"
  93. steps[15]=" 6a. Move savefiles to default [ waiting... ]"
  94. steps[16]=" 6b. Remove local SAVEFILE directory [ waiting... ]"
  95. steps[17]="7. Remote SAVEFILE directory"
  96. steps[18]=" 7a. Remove remote SAVEFILE directory [ waiting... ]"
  97. steps[19]="8. Configure RETROARCH"
  98. steps[20]=" 8a. Reset local SAVEFILE directories [ waiting... ]"
  99. steps[21]="9 Finalizing"
  100. steps[22]=" 9a. Remove UNINSTALL script [ waiting... ]"
  101. }
  102. # Update item of $STEPS() and show updated progress dialog
  103. # INPUT
  104. # 1 > Number of step to update
  105. # 2 > New status for step
  106. # 3 > Percentage to show in progress dialog
  107. # $steps()
  108. # OUTPUT
  109. # $steps()
  110. function updateStep ()
  111. {
  112. local step="$1"
  113. local newStatus="$2"
  114. local percent="$3"
  115. local oldline
  116. local newline
  117. # translate and colorize $NEWSTATUS
  118. case "${newStatus}" in
  119. "waiting") newStatus="[ ${NORMAL}WAITING...${NORMAL} ]" ;;
  120. "in progress") newStatus="[ ${NORMAL}IN PROGRESS${NORMAL} ]" ;;
  121. "done") newStatus="[ ${GREEN}DONE${NORMAL} ]" ;;
  122. "found") newStatus="[ ${GREEN}FOUND${NORMAL} ]" ;;
  123. "not found") newStatus="[ ${RED}NOT FOUND${NORMAL} ]" ;;
  124. "created") newStatus="[ ${GREEN}CREATED${NORMAL} ]" ;;
  125. "failed") newStatus="[ ${RED}FAILED${NORMAL} ]" ;;
  126. "skipped") newStatus="[ ${YELLOW}SKIPPED${NORMAL} ]" ;;
  127. *) newStatus="[ ${RED}UNDEFINED${NORMAL} ]" ;;
  128. esac
  129. # search $STEP in $STEPS
  130. for ((i=0; i<${#steps[*]}; i++))
  131. do
  132. if [[ ${steps[i]} =~ .*$step.* ]]
  133. then
  134. # update $STEP with $NEWSTATUS
  135. oldline="${steps[i]}"
  136. oldline="${oldline%%[*}"
  137. newline="${oldline}${newStatus}"
  138. steps[i]="${newline}"
  139. break
  140. fi
  141. done
  142. # show progress dialog
  143. dialogShowProgress ${percent}
  144. }
  145. #########################
  146. # UNINSTALLER FUNCTIONS #
  147. #########################
  148. # Uninstaller
  149. function uninstaller ()
  150. {
  151. initSteps
  152. dialogShowProgress 0
  153. 1RCLONE
  154. 2PNGVIEW
  155. 3IMAGEMAGICK
  156. 4RCLONE_SCRIPT
  157. 5RUNCOMMAND
  158. 6LocalSAVEFILEDirectory
  159. }
  160. function 1RCLONE ()
  161. {
  162. printf "$(date +%FT%T%:z):\t1RCLONE\tSTART\n" >> "${logfile}"
  163. # 1a. Remove RCLONE configuration
  164. printf "$(date +%FT%T%:z):\t1aRCLONEconfiguration\tSTART\n" >> "${logfile}"
  165. updateStep "1a" "in progress" 0
  166. if [ -d ~/.config/rclone ]
  167. then
  168. { #try
  169. sudo rm -r ~/.config/rclone >> "${logfile}" &&
  170. printf "$(date +%FT%T%:z):\t1aRCLONEconfiguration\tDONE\n" >> "${logfile}" &&
  171. updateStep "1a" "done" 8
  172. } || { #catch
  173. printf "$(date +%FT%T%:z):\t1aRCLONEconfiguration\tERROR\n" >> "${logfile}" &&
  174. updateStep "1a" "failed" 0 &&
  175. exit
  176. }
  177. else
  178. printf "$(date +%FT%T%:z):\t1aRCLONEconfiguration\tNOT FOUND\n" >> "${logfile}"
  179. updateStep "1a" "not found" 8
  180. fi
  181. # 1b. Remove RCLONE binary
  182. printf "$(date +%FT%T%:z):\t1bRCLONEbinary\tSTART\n" >> "${logfile}"
  183. updateStep "1b" "in progress" 8
  184. if [ -f /usr/bin/rclone ]
  185. then
  186. { #try
  187. sudo rm /usr/bin/rclone >> "${logfile}" &&
  188. printf "$(date +%FT%T%:z):\t1bRCLONEbinary\tDONE\n" >> "${logfile}" &&
  189. updateStep "1b" "done" 16
  190. } || { #catch
  191. printf "$(date +%FT%T%:z):\t1bRCLONEbinary\tERROR\n" >> "${logfile}" &&
  192. updateStep "1b" "failed" 8 &&
  193. exit
  194. }
  195. else
  196. printf "$(date +%FT%T%:z):\t1bRCLONEbinary\tNOT FOUND\n" >> "${logfile}"
  197. updateStep "1b" "not found" 16
  198. fi
  199. printf "$(date +%FT%T%:z):\t1RCLONE\tEND\n" >> "${logfile}"
  200. }
  201. function 2PNGVIEW ()
  202. {
  203. printf "$(date +%FT%T%:z):\t2PNGVIEW\tSTART\n" >> "${logfile}"
  204. # 2a. Remove PNGVIEW binary
  205. printf "$(date +%FT%T%:z):\t2aPNGVIEWbinary\tSTART\n" >> "${logfile}"
  206. updateStep "2a" "in progress" 16
  207. if [ -f /usr/bin/pngview ]
  208. then
  209. { #try
  210. sudo rm /usr/bin/pngview >> "${logfile}" &&
  211. sudo rm /usr/lib/libraspidmx.so.1 >> "${logfile}" &&
  212. printf "$(date +%FT%T%:z):\t2aPNGVIEWbinary\tDONE\n" >> "${logfile}" &&
  213. updateStep "2a" "done" 24
  214. } || { # catch
  215. printf "$(date +%FT%T%:z):\t2aPNGVIEWbinary\tERROR\n" >> "${logfile}" &&
  216. updateStep "2a" "failed" 16 &&
  217. exit
  218. }
  219. else
  220. printf "$(date +%FT%T%:z):\t2aPNGVIEWbinary\tNOT FOUND\n" >> "${logfile}" &&
  221. updateStep "2a" "not found" 24
  222. fi
  223. printf "$(date +%FT%T%:z):\t2PNGVIEW\tDONE\n" >> "${logfile}"
  224. }
  225. function 3IMAGEMAGICK ()
  226. {
  227. printf "$(date +%FT%T%:z):\t3IMAGEMAGICK\tSTART\n" >> "${logfile}"
  228. # 3a. Remove IMAGEMAGICK binary
  229. printf "$(date +%FT%T%:z):\t3aIMAGEMAGICKbinary\tSTART\n" >> "${logfile}"
  230. updateStep "3a" "in progress" 24
  231. if [ -f /usr/bin/convert ]
  232. then
  233. { # try
  234. sudo apt-get --yes remove imagemagick* >> "${logfile}" &&
  235. printf "$(date +%FT%T%:z):\t3aIMAGEMAGICKbinary\tDONE\n" >> "${logfile}" &&
  236. updateStep "3a" "done" 32
  237. } || { # catch
  238. printf "$(date +%FT%T%:z):\t3aIMAGEMAGICKbinary\tERROR\n" >> "${logfile}" &&
  239. updateStep "3a" "failed" 24 &&
  240. exit
  241. }
  242. else
  243. printf "$(date +%FT%T%:z):\t3aPIMAGEMAGICKbinary\tNOT FOUND\n" >> "${logfile}"
  244. updateStep "3a" "not found" 32
  245. fi
  246. printf "$(date +%FT%T%:z):\t3IMAGEMAGICK\tDONE\n" >> "${logfile}"
  247. }
  248. function 4RCLONE_SCRIPT ()
  249. {
  250. printf "$(date +%FT%T%:z):\t4RCLONE_SCRIPT\tSTART\n" >> "${logfile}"
  251. # 4a. Remove RCLONE_SCRIPT
  252. printf "$(date +%FT%T%:z):\t4aRCLONE_SCRIPTfiles\tSTART\n" >> "${logfile}"
  253. updateStep "4a" "in progress" 32
  254. if [ -f ~/scripts/rclone_script/rclone_script.sh ]
  255. then
  256. { # try
  257. sudo rm -f ~/scripts/rclone_script/rclone_script-install.* >> "${logfile}" &&
  258. sudo rm -f ~/scripts/rclone_script/rclone_script.* >> "${logfile}" &&
  259. printf "$(date +%FT%T%:z):\t4aRCLONE_SCRIPTfiles\tDONE\n" >> "${logfile}" &&
  260. updateStep "4a" "done" 40
  261. } || { # catch
  262. printf "$(date +%FT%T%:z):\t4aRCLONE_SCRIPTfiles\tERROR\n" >> "${logfile}" &&
  263. updateStep "4a" "failed" 32 &&
  264. exit
  265. }
  266. else
  267. printf "$(date +%FT%T%:z):\t4aRCLONE_SCRIPTfiles\tNOT FOUND\n" >> "${logfile}"
  268. updateStep "4a" "not found" 40
  269. fi
  270. # 4b. Remove RCLONE_SCRIPT menu item
  271. printf "$(date +%FT%T%:z):\t4bRCLONE_SCRIPTMenuItem\tSTART\n" >> "${logfile}"
  272. updateStep "4b" "in progress" 40
  273. local found=0
  274. if [[ $(xmlstarlet sel -t -v "count(/gameList/game[path='./rclone_script-menu.sh'])" ~/.emulationstation/gamelists/retropie/gamelist.xml) -ne 0 ]]
  275. then
  276. found=$(($found + 1))
  277. printf "$(date +%FT%T%:z):\t4bRCLONE_SCRIPTMenuItem\tFOUND\n" >> "${logfile}"
  278. xmlstarlet ed \
  279. --inplace \
  280. --delete "//game[path='./rclone_script-menu.sh']" \
  281. ~/.emulationstation/gamelists/retropie/gamelist.xml
  282. printf "$(date +%FT%T%:z):\t4bRCLONE_SCRIPTMenuItem\tREMOVED\n" >> "${logfile}"
  283. else
  284. printf "$(date +%FT%T%:z):\t4bRCLONE_SCRIPTMenuItem\tNOT FOUND\n" >> "${logfile}"
  285. fi
  286. if [ -f ~/RetroPie/retropiemenu/rclone_script-menu.sh ]
  287. then
  288. found=$(($found + 1))
  289. printf "$(date +%FT%T%:z):\t4bRCLONE_SCRIPTMenuItemScript\tFOUND\n" >> "${logfile}"
  290. sudo rm ~/RetroPie/retropiemenu/rclone_script-menu.sh >> "${logfile}"
  291. printf "$(date +%FT%T%:z):\t4bRCLONE_SCRIPTMenuItemScript\tREMOVED\n" >> "${logfile}"
  292. else
  293. printf "$(date +%FT%T%:z):\t4bRCLONE_SCRIPTMenuItemScript\tNOT FOUND\n" >> "${logfile}"
  294. fi
  295. case $found in
  296. 0) updateStep "4b" "not found" 48 ;;
  297. 1) updateStep "4b" "done" 48 ;;
  298. 2) updateStep "4b" "done" 48 ;;
  299. esac
  300. printf "$(date +%FT%T%:z):\t4RCLONE_SCRIPT\tDONE\n" >> "${logfile}"
  301. }
  302. function 5RUNCOMMAND ()
  303. {
  304. printf "$(date +%FT%T%:z):\t5RUNCOMMAND\tSTART\n" >> "${logfile}"
  305. # 5a. Remove call from RUNCOMMAND-ONSTART
  306. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONSTART\tSTART\n" >> "${logfile}"
  307. updateStep "5a" "in progress" 48
  308. if [[ $(grep -c "~/scripts/rclone_script/rclone_script.sh" /opt/retropie/configs/all/runcommand-onstart.sh) -gt 0 ]]
  309. then
  310. { #try
  311. sed -i "/~\/scripts\/rclone_script\/rclone_script.sh /d" /opt/retropie/configs/all/runcommand-onstart.sh &&
  312. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONSTART\tDONE\n" >> "${logfile}" &&
  313. updateStep "5a" "done" 56
  314. } || { # catch
  315. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONSTART\tERROR\n" >> "${logfile}" &&
  316. updateStep "5a" "failed" 48
  317. }
  318. else
  319. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONSTART\tNOT FOUND\n" >> "${logfile}"
  320. updateStep "5a" "not found" 56
  321. fi
  322. # 5b. Remove call from RUNCOMMAND-ONEND
  323. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONEND\tSTART\n" >> "${logfile}"
  324. updateStep "5b" "in progress" 56
  325. if [[ $(grep -c "~/scripts/rclone_script/rclone_script.sh" /opt/retropie/configs/all/runcommand-onend.sh) -gt 0 ]]
  326. then
  327. { #try
  328. sed -i "/~\/scripts\/rclone_script\/rclone_script.sh /d" /opt/retropie/configs/all/runcommand-onend.sh &&
  329. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONEND\tDONE\n" >> "${logfile}" &&
  330. updateStep "5b" "done" 64
  331. } || { # catch
  332. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONEND\tERROR\n" >> "${logfile}" &&
  333. updateStep "5b" "failed" 56
  334. }
  335. else
  336. printf "$(date +%FT%T%:z):\t5RUNCOMMAND-ONEND\tNOT FOUND\n" >> "${logfile}"
  337. updateStep "5b" "not found" 64
  338. fi
  339. printf "$(date +%FT%T%:z):\t5RUNCOMMAND\tDONE\n" >> "${logfile}"
  340. }
  341. function 6LocalSAVEFILEDirectory ()
  342. {
  343. printf "$(date +%FT%T%:z):\t6LocalSAVEFILEDirectory\tSTART\n" >> "${logfile}"
  344. # 6a. Move savefiles to default
  345. printf "$(date +%FT%T%:z):\t6a moveFilesToDefault\tSTART\n" >> "${logfile}"
  346. updateStep "6a" "in progress" 64
  347. #counter=1
  348. #while [ $counter -le 10000 ]
  349. #do
  350. # echo "." > ~/RetroPie/saves/gba/datei_${counter}.srm
  351. # ((counter++))
  352. #done
  353. # start copy task in background, pipe numbered output into COPY.TXT and to LOGFILE
  354. $(cp -v -r ~/RetroPie/saves/* ~/RetroPie/roms | cat -n | tee copy.txt | cat >> "${logfile}") &
  355. # show content of COPY.TXT
  356. dialog \
  357. --backtitle "${backtitle}" \
  358. --title "Move savefiles to default" \
  359. --ascii-lines \
  360. --colors \
  361. --no-collapse \
  362. --cr-wrap \
  363. --tailbox copy.txt 40 120
  364. wait
  365. rm copy.txt
  366. #rm ~/RetroPie/saves/gba/datei*
  367. #rm ~/RetroPie/roms/gba/datei*
  368. updateStep "6a" "done" 72
  369. # 6b. Remove local SAVEFILE directory
  370. }
  371. ########
  372. # MAIN #
  373. ########
  374. uninstaller