mister_updater_retrodriven.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. #!/bin/bash
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation, either version 3 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. # Copyright 2018-2019 Alessandro "Locutus73" Miele
  13. # You can download the latest version of this script from:
  14. # https://github.com/MiSTer-devel/Updater_script_MiSTer
  15. # Version RetroDriven - Most of the script remained the same. Just remove stuff not needed.
  16. # Version 3.3.1 - 2019-09-07 - Improved core directories creation; added NeoGeo xml download/update to ADDITIONAL_REPOSITORIES.
  17. # Version 3.3 - 2019-08-21 - Implemented CREATE_CORES_DIRECTORIES; when "true" (default value), the updater will create the core directory (i.e. /media/fat/Amiga for Minimig core, /media/fat/SNES for SNES core) the first time the core is downloaded.
  18. # Version 3.2 - 2019-08-21 - Implemented GOOD_CORES_URL for having a list of curated "good" cores.
  19. # Version 3.1.1 - 2019-07-26 - The script is compatible with a possible renaming of "Cores" to "Computer Cores" in MiSTer Wiki Sidebar.
  20. # Version 3.1 - 2019-06-16 - Checking cURL download success and restoring old files when needed.
  21. # Version 3.0.2 - 2019-06-10 - Testing Internet connectivity with github.com instead of google.com; improved a regular expression for Debian repository parsing.
  22. # Version 3.0.1 - 2019-05-25 - Changed UPDATE_LINUX default value from "false" to "true".
  23. # Version 3.0 - 2019-05-18 - Added EXPERIMENTAL parallel processing for the update process when PARALLEL_UPDATE="true" (default value is "false"): use it at your own risk!
  24. # Version 2.3 - 2019-05-13 - Added cheats download/update from gamehacking.org when UPDATE_CHEATS="true" ("once" for just downloading them once); added UPDATE_LINUX option instead of uncommenting SD_INSTALLER_PATH (this method still works for ini compatibility).
  25. # Version 2.2.1 - 2019-05-06 - Removed https://github.com/MiSTer-devel/CIFS_MiSTer from ADDITIONAL_REPOSITORIES, now CIFS scripts are hosted in https://github.com/MiSTer-devel/Scripts_MiSTer.
  26. # Version 2.2 - 2019-05-01 - CURL RETRY OPTIONS by wesclemens, now the script has a timeout and retry logic to prevent spotty connections causing the update to lockup, thank you very much; review time sync test by frederic-mahe, thank you very much; now the scripts default path is /media/fat/Scripts, moving #Scripts directory there when needed.
  27. # Version 2.1.5 - 2019-04-03 - Improved date-time parsing for additional repositories.
  28. # Version 2.1.4 - 2019-04-01 - Implemented a safer Linux system updating strategy: linux.img is moved as the very last step in the process.
  29. # Version 2.1.3 - 2019-03-26 - Cosmetic change in ADDITIONAL_REPOSITORIES declaration; added commented (not active) fonts additional repository for reference.
  30. # Version 2.1.2 - 2019-03-03 - Corrected a bug in date-time parsing for additional repositories.
  31. # Version 2.1.1 - 2019-03-03 - Improved date-time parsing for additional repositories; added MiSTer_MidiLink installation scripts to ADDITIONAL_REPOSITORIES.
  32. # Version 2.1 - 2019-03-02 - Linux updating now supports subdirectories under /media/fat/linux.
  33. # Version 2.0.2 - 2019-02-23 - ALLOW_INSECURE_SSH renamed to ALLOW_INSECURE_SSL.
  34. # Version 2.0.1 - 2019-02-03 - Cosmetic changes.
  35. # Version 2.0 - 2019-02-02 - Added ALLOW_INSECURE_SSH option: "true" will check if SSL certificate verification (see https://curl.haxx.se/docs/sslcerts.html ) is working (CA certificates installed) and when it's working it will use this feature for safe curl HTTPS downloads, otherwise it will use --insecure option for disabling SSL certificate verification. If CA certificates aren't installed it's advised to install them (i.e. using security_fixes.sh). "false" will never use --insecure option and if CA certificates aren't installed any download will fail. The script will download and update the simple one line update.sh with a newer one (same ALLOW_INSECURE_SSH option) when needed.
  36. # Version 1.8.2 - 2019-01-21 - Changed ARCADE_HACKS_PATH to ARCADE_ALT_PATHS: not it supports a pipe "|" separated list of directories containing alternative arcade cores.
  37. # Version 1.8.1 - 2019-01-16 - Changed ADDITIONAL_REPOSITORIES in order to download inc files from scripts repositories; improved ADDITIONAL_REPOSITORIES extensions handling.
  38. # Version 1.8 - 2019-01-15 - Using /media/fat/#Scripts/.mister_updater as work directory, you can safely delete MiSTer_yyyymmdd, menu_yyyymmdd.rbf and release_yyyymmdd.rar from SD root now; using empty files as semaphores and corrected a minor bug about their target directories; improved user option comments.
  39. # Version 1.7.2 - 2019-01-09 - Cosmetic changes.
  40. # Version 1.7.1 - 2019-01-07 - unrar-nonfree is always downloaded in /media/fat/linux.
  41. # Version 1.7 - 2019-01-07 - Added support for an ini configuration file with the same name as the original script, i.e. mister_updater.ini or update.ini; added CIFS_MiSTer and Scripts_MiSTer additional repositories; improved additional repositories handling; added optional advanced NTP_SERVER option for syncing system date and time with a NTP server.
  42. # Version 1.6.2 - 2019-01-02 - Solved a bug that prevented updating MiSTer main executable, menu.rbf and Linux system when DOWNLOAD_NEW_CORES="false" and timestamped files were missing; improved REPOSITORIES_FILTER comments; code clean up by frederic-mahe (thank you very much).
  43. # Version 1.6.1 - 2018-12-30 - Improved date-time parsing for additional repositories; main MiSTer executable, menu.rbf and Linux system are always updated in /media/fat even if BASE_PATH is configured for another directory.
  44. # Version 1.6 - 2018-12-29 - Added REPOSITORIES_FILTER option (i.e. "C64 Minimig NES SNES"); additional repositories files (Filters and GameBoy palettes) online dates and times are checked against local files before downloading; added Internet connection test at the beginning of the script; improved ARCADE_HACKS_PATH file purging; solved a bug with DOWNLOAD_NEW_CORES and paths with spaces; added comments to user options.
  45. # Version 1.5 - 2018-12-27 - Reorganized user options; improved DOWNLOAD_NEW_CORES option handling for paths with spaces; added ARCADE_HACKS_PATH parameter for defining a directory containing arcade hacks to be updated, each arcade hack is a subdirectory with the name starting like the rbf core with an underscore prefix (i.e. /media/fat/_Arcade/_Arcade Hacks/_BurgerTime - hack/).
  46. # Version 1.4 - 2018-12-26 - Added DOWNLOAD_NEW_CORES option: true for downloading new cores in the standard directories as previous script releases, false for not downloading new cores at all, a string value, i.e. "NewCores", for downloading new cores in the "NewCores" subdirectory.
  47. # Version 1.3.6 - 2018-12-24 - Improved local file name parsing so that the script deletes and updates NES_20181113.rbf, but not NES_20181113_NN.rbf.
  48. # Version 1.3.5 - 2018-12-22 - Solved Atari 800XL/5200 and SharpMZ issues; replaced "reboot" with "reboot now"; shortened some of the script outputs.
  49. # Version 1.3.4 - 2018-12-22 - Shortened most of the script outputs in order to make them more friendly to the new MiSTer Script menu OSD; simplified missing directories creation (thanks frederic-mahe).
  50. # Version 1.3.3 - 2018-12-16 - Updating the bootloader before deleting linux.img, moved the Linux system update at the end of the script with an "atomic" approach (first extracting in a linux.update directory and then moving files).
  51. # Version 1.3.2 - 2018-12-16 - Deleting linux.img before updating the linux directory so that the extracted new file won't be overwritten.
  52. # Version 1.3.1 - 2018-12-16 - Disabled Linux updating as default behaviour.
  53. # Version 1.3 - 2018-12-16 - Added Kernel, Linux filesystem and bootloader updating functionality; added autoreboot option.
  54. # Version 1.2 - 2018-12-14 - Added support for distinct directories for computer cores, console cores, arcade cores and service cores; added an option for removing "Arcade-" prefix from arcade core names.
  55. # Version 1.1 - 2018-12-11 - Added support for additional repositories (i.e. Scaler filters and Game Boy palettes), renamed some variables.
  56. # Version 1.0 - 2018-12-11 - First commit.
  57. #========= USER OPTIONS =========
  58. #Base directory for all script’s tasks, "/media/fat" for SD root, "/media/usb0" for USB drive root.
  59. BASE_PATH="/media/fat"
  60. #Directories where all core categories will be downloaded.
  61. declare -A CORE_CATEGORY_PATHS
  62. #CORE_CATEGORY_PATHS["cores"]="$BASE_PATH/_Computer"
  63. #CORE_CATEGORY_PATHS["console-cores"]="$BASE_PATH/_Console"
  64. CORE_CATEGORY_PATHS["arcade-cores"]="$BASE_PATH/_RetroDriven"
  65. #CORE_CATEGORY_PATHS["service-cores"]="$BASE_PATH/_Utility"
  66. #Optional pipe "|" separated list of directories containing alternative arcade cores to be updated,
  67. #each alternative (hack/revision/whatever) arcade is a subdirectory with the name starting like the rbf core with an underscore prefix,
  68. #i.e. "/media/fat/_Arcade/_Arcade Hacks/_BurgerTime - hack/".
  69. #ARCADE_ALT_PATHS="${CORE_CATEGORY_PATHS["arcade-cores"]}/_Arcade Hacks|${CORE_CATEGORY_PATHS["arcade-cores"]}/_Arcade Revisions"
  70. #Specifies if old files (cores, main MiSTer executable, menu, SD-Installer, etc.) will be deleted as part of an update.
  71. DELETE_OLD_FILES="true"
  72. #Specifies what to do with new cores not installed locally:
  73. #true for downloading new cores in the standard directories (see CORE_CATEGORY_PATHS),
  74. #false for not downloading new cores at all,
  75. #a string value, i.e. "NewCores", for downloading new cores in the "NewCores" subdirectory.
  76. DOWNLOAD_NEW_CORES="true"
  77. #Specifies if the "Arcade-" prefix will be removed in local arcade cores.
  78. REMOVE_ARCADE_PREFIX="true"
  79. #A space separated list of filters for the online repositories;
  80. #each filter can be part of the repository name or a whole core category,
  81. #i.e. “C64 Minimig NES SNES arcade-cores” if you want the script to check only
  82. #for C64, Minimig, NES, SNES, and all arcade cores repositories making the whole
  83. #update process quicker;
  84. #if you use this option probably you want DOWNLOAD_NEW_CORES="true" so that you
  85. #can use this filter in order to setup a brand new empty SD with only the cores
  86. #you need, otherwise cores in the filter, but not on the SD won't be downloaded.
  87. REPOSITORIES_FILTER=""
  88. #Specifies if the cheats will be downloaded/updated from https://gamehacking.org/
  89. #"true" for checking for updates each time, "false" for disabling the function,
  90. #"once" for downloading cheats just once if not on the SD card (no further updating).
  91. UPDATE_CHEATS="false"
  92. #EXPERIMENTAL: specifies if the Kernel, the Linux filesystem and the bootloader will be updated; use it at your own risk!
  93. UPDATE_LINUX="false"
  94. #EXPERIMENTAL: specifies if the update process must be done with parallel processing; use it at your own risk!
  95. PARALLEL_UPDATE="false"
  96. #Specifies an optional URL with a text file containing a curated list of "good" cores.
  97. #If a core is specified there, it will be preferred over the latest "bleeding edge" core in its repository.
  98. #The text file can be something simple as "Genesis_20190712.rbf SNES_20190703.rbf".
  99. GOOD_CORES_URL=""
  100. #Specifies if the core directory (i.e. /media/fat/Amiga for Minimig core, /media/fat/SNES for SNES core) has to be created
  101. #the first time the core is downloaded.
  102. CREATE_CORES_DIRECTORIES="false"
  103. #========= ADVANCED OPTIONS =========
  104. #ALLOW_INSECURE_SSL="true" will check if SSL certificate verification (see https://curl.haxx.se/docs/sslcerts.html )
  105. #is working (CA certificates installed) and when it's working it will use this feature for safe curl HTTPS downloads,
  106. #otherwise it will use --insecure option for disabling SSL certificate verification.
  107. #If CA certificates aren't installed it's advised to install them (i.e. using security_fixes.sh).
  108. #ALLOW_INSECURE_SSL="false" will never use --insecure option and if CA certificates aren't installed
  109. #any download will fail.
  110. ALLOW_INSECURE_SSL="true"
  111. CURL_RETRY="--connect-timeout 15 --max-time 120 --retry 3 --retry-delay 5"
  112. SCRIPTS_PATH="Scripts"
  113. OLD_SCRIPTS_PATH="#Scripts"
  114. WORK_PATH="/media/fat/$SCRIPTS_PATH/.mister_updater"
  115. #Uncomment this if you want the script to sync the system date and time with a NTP server
  116. #NTP_SERVER="0.pool.ntp.org"
  117. AUTOREBOOT="false"
  118. REBOOT_PAUSE=0
  119. TEMP_PATH="/tmp"
  120. TO_BE_DELETED_EXTENSION="to_be_deleted"
  121. echo "RetroDriven Core Updater!"
  122. sleep 2
  123. echo
  124. echo Original script by Alessandro \"Locutus73\" Miele
  125. echo
  126. #========= CODE STARTS HERE =========
  127. ORIGINAL_SCRIPT_PATH="$0"
  128. if [ "$ORIGINAL_SCRIPT_PATH" == "bash" ]
  129. then
  130. ORIGINAL_SCRIPT_PATH=$(ps | grep "^ *$PPID " | grep -o "[^ ]*$")
  131. fi
  132. INI_PATH=${ORIGINAL_SCRIPT_PATH%.*}.ini
  133. if [ -f $INI_PATH ]
  134. then
  135. eval "$(cat $INI_PATH | tr -d '\r')"
  136. fi
  137. if [ -d "${BASE_PATH}/${OLD_SCRIPTS_PATH}" ] && [ ! -d "${BASE_PATH}/${SCRIPTS_PATH}" ]
  138. then
  139. mv "${BASE_PATH}/${OLD_SCRIPTS_PATH}" "${BASE_PATH}/${SCRIPTS_PATH}"
  140. echo "Moved"
  141. echo "${BASE_PATH}/${OLD_SCRIPTS_PATH}"
  142. echo "to"
  143. echo "${BASE_PATH}/${SCRIPTS_PATH}"
  144. echo "please relaunch the script."
  145. exit 3
  146. fi
  147. SSL_SECURITY_OPTION=""
  148. curl $CURL_RETRY -q https://github.com &>/dev/null
  149. case $? in
  150. 0)
  151. ;;
  152. 60)
  153. if [ "$ALLOW_INSECURE_SSL" == "true" ]
  154. then
  155. SSL_SECURITY_OPTION="--insecure"
  156. else
  157. echo "CA certificates need"
  158. echo "to be fixed for"
  159. echo "using SSL certificate"
  160. echo "verification."
  161. echo "Please fix them i.e."
  162. echo "using security_fixes.sh"
  163. exit 2
  164. fi
  165. ;;
  166. *)
  167. echo "No Internet connection"
  168. exit 1
  169. ;;
  170. esac
  171. ## sync with a public time server
  172. if [[ -n "${NTP_SERVER}" ]] ; then
  173. echo "Syncing date and time with"
  174. echo "${NTP_SERVER}"
  175. # (-b) force time reset, (-s) write output to syslog, (-u) use
  176. # unprivileged port for outgoing packets to workaround firewalls
  177. ntpdate -b -s -u "${NTP_SERVER}"
  178. echo
  179. fi
  180. mkdir -p "${CORE_CATEGORY_PATHS[@]}"
  181. declare -A NEW_CORE_CATEGORY_PATHS
  182. if [ "$DOWNLOAD_NEW_CORES" != "true" ] && [ "$DOWNLOAD_NEW_CORES" != "false" ] && [ "$DOWNLOAD_NEW_CORES" != "" ]
  183. then
  184. for idx in "${!CORE_CATEGORY_PATHS[@]}"; do
  185. NEW_CORE_CATEGORY_PATHS[$idx]=$(echo ${CORE_CATEGORY_PATHS[$idx]} | sed "s/$(echo $BASE_PATH | sed 's/\//\\\//g')/$(echo $BASE_PATH | sed 's/\//\\\//g')\/$DOWNLOAD_NEW_CORES/g")
  186. done
  187. mkdir -p "${NEW_CORE_CATEGORY_PATHS[@]}"
  188. fi
  189. CORE_URLS=$(curl $CURL_RETRY $SSL_SECURITY_OPTION -sLf "https://github.com/RetroDriven/MiSTer_UnofficialCores/wiki" | grep -io '\(https://github.com/RetroDriven/MiSTer_UnofficialCores/tree/master/Arcade_Cores/[a-zA-Z0-9./_-]*\)\|\(user-content-[a-z-]*\)')
  190. CORE_CATEGORY="-"
  191. SD_INSTALLER_PATH=""
  192. REBOOT_NEEDED="false"
  193. CORE_CATEGORIES_FILTER=""
  194. GOOD_CORES=""
  195. if [ "$GOOD_CORES_URL" != "" ]
  196. then
  197. GOOD_CORES=$(curl $CURL_RETRY $SSL_SECURITY_OPTION -sLf "$GOOD_CORES_URL")
  198. fi
  199. function checkCoreURL {
  200. echo "Checking $(echo $CORE_URL | sed 's/.*\///g' | sed 's/_MiSTer//gI')"
  201. [ "${SSH_CLIENT}" != "" ] && echo "URL: $CORE_URL"
  202. if echo "$CORE_URL" | grep -q "SD-Installer"
  203. then
  204. RELEASES_URL="$CORE_URL"
  205. else
  206. RELEASES_URL=https://github.com$(curl $CURL_RETRY $SSL_SECURITY_OPTION -sLf "$CORE_URL" | grep -o '/RetroDriven/[a-zA-Z0-9./_-]*/tree/master/[a-zA-Z0-9./_-]*/releases' | head -n1)
  207. fi
  208. RELEASE_URLS=$(curl $CURL_RETRY $SSL_SECURITY_OPTION -sLf "$RELEASES_URL" | grep -o '/RetroDriven/[a-zA-Z0-9./_-]*_[0-9]\{8\}[a-zA-Z]\?\(\.rbf\|\.rar\)\?')
  209. MAX_VERSION=""
  210. MAX_RELEASE_URL=""
  211. GOOD_CORE_VERSION=""
  212. for RELEASE_URL in $RELEASE_URLS; do
  213. if echo "$RELEASE_URL" | grep -q "SharpMZ"
  214. then
  215. RELEASE_URL=$(echo "$RELEASE_URL" | grep '\.rbf$')
  216. fi
  217. if echo "$RELEASE_URL" | grep -q "Atari800"
  218. then
  219. if [ "$CORE_CATEGORY" == "cores" ]
  220. then
  221. RELEASE_URL=$(echo "$RELEASE_URL" | grep '800_[0-9]\{8\}[a-zA-Z]\?\.rbf$')
  222. else
  223. RELEASE_URL=$(echo "$RELEASE_URL" | grep '5200_[0-9]\{8\}[a-zA-Z]\?\.rbf$')
  224. fi
  225. fi
  226. CURRENT_VERSION=$(echo "$RELEASE_URL" | grep -o '[0-9]\{8\}[a-zA-Z]\?')
  227. if [ "$GOOD_CORES" != "" ]
  228. then
  229. GOOD_CORE_VERSION=$(echo "$GOOD_CORES" | grep -wo "$(echo "$RELEASE_URL" | sed 's/.*\///g')" | grep -o '[0-9]\{8\}[a-zA-Z]\?')
  230. if [ "$GOOD_CORE_VERSION" != "" ]
  231. then
  232. MAX_VERSION=$CURRENT_VERSION
  233. MAX_RELEASE_URL=$RELEASE_URL
  234. break
  235. fi
  236. fi
  237. if [[ "$CURRENT_VERSION" > "$MAX_VERSION" ]]
  238. then
  239. MAX_VERSION=$CURRENT_VERSION
  240. MAX_RELEASE_URL=$RELEASE_URL
  241. fi
  242. done
  243. FILE_NAME=$(echo "$MAX_RELEASE_URL" | sed 's/.*\///g')
  244. if [ "$CORE_CATEGORY" == "arcade-cores" ] && [ $REMOVE_ARCADE_PREFIX == "true" ]
  245. then
  246. FILE_NAME=$(echo "$FILE_NAME" | sed 's/Arcade-//gI')
  247. fi
  248. BASE_FILE_NAME=$(echo "$FILE_NAME" | sed 's/_[0-9]\{8\}.*//g')
  249. CURRENT_DIRS="${CORE_CATEGORY_PATHS[$CORE_CATEGORY]}"
  250. if [ "${NEW_CORE_CATEGORY_PATHS[$CORE_CATEGORY]}" != "" ]
  251. then
  252. CURRENT_DIRS=("$CURRENT_DIRS" "${NEW_CORE_CATEGORY_PATHS[$CORE_CATEGORY]}")
  253. fi
  254. if [ "$CURRENT_DIRS" == "" ]
  255. then
  256. CURRENT_DIRS=("$BASE_PATH")
  257. fi
  258. if [ "$BASE_FILE_NAME" == "MiSTer" ] || [ "$BASE_FILE_NAME" == "menu" ] || { echo "$CORE_URL" | grep -q "SD-Installer"; }
  259. then
  260. mkdir -p "$WORK_PATH"
  261. CURRENT_DIRS=("$WORK_PATH")
  262. fi
  263. CURRENT_LOCAL_VERSION=""
  264. MAX_LOCAL_VERSION=""
  265. for CURRENT_DIR in "${CURRENT_DIRS[@]}"
  266. do
  267. for CURRENT_FILE in "$CURRENT_DIR/$BASE_FILE_NAME"*
  268. do
  269. if [ -f "$CURRENT_FILE" ]
  270. then
  271. if echo "$CURRENT_FILE" | grep -q "$BASE_FILE_NAME\_[0-9]\{8\}[a-zA-Z]\?\(\.rbf\|\.rar\)\?$"
  272. then
  273. CURRENT_LOCAL_VERSION=$(echo "$CURRENT_FILE" | grep -o '[0-9]\{8\}[a-zA-Z]\?')
  274. if [ "$GOOD_CORE_VERSION" != "" ]
  275. then
  276. if [ "$CURRENT_LOCAL_VERSION" == "$GOOD_CORE_VERSION" ]
  277. then
  278. MAX_LOCAL_VERSION=$CURRENT_LOCAL_VERSION
  279. else
  280. if [ "$MAX_LOCAL_VERSION" == "" ]
  281. then
  282. MAX_LOCAL_VERSION="00000000"
  283. fi
  284. if [ $DELETE_OLD_FILES == "true" ]
  285. then
  286. mv "${CURRENT_FILE}" "${CURRENT_FILE}.${TO_BE_DELETED_EXTENSION}" > /dev/null 2>&1
  287. fi
  288. fi
  289. else
  290. if [[ "$CURRENT_LOCAL_VERSION" > "$MAX_LOCAL_VERSION" ]]
  291. then
  292. MAX_LOCAL_VERSION=$CURRENT_LOCAL_VERSION
  293. fi
  294. if [[ "$MAX_VERSION" > "$CURRENT_LOCAL_VERSION" ]] && [ $DELETE_OLD_FILES == "true" ]
  295. then
  296. # echo "Moving $(echo ${CURRENT_FILE} | sed 's/.*\///g')"
  297. mv "${CURRENT_FILE}" "${CURRENT_FILE}.${TO_BE_DELETED_EXTENSION}" > /dev/null 2>&1
  298. fi
  299. fi
  300. fi
  301. fi
  302. done
  303. if [ "$MAX_LOCAL_VERSION" != "" ]
  304. then
  305. break
  306. fi
  307. done
  308. if [[ "$MAX_VERSION" > "$MAX_LOCAL_VERSION" ]]
  309. then
  310. if [ "$DOWNLOAD_NEW_CORES" != "false" ] || [ "$MAX_LOCAL_VERSION" != "" ] || [ "$BASE_FILE_NAME" == "MiSTer" ] || [ "$BASE_FILE_NAME" == "menu" ] || { echo "$CORE_URL" | grep -q "SD-Installer"; }
  311. then
  312. echo "Downloading $FILE_NAME"
  313. [ "${SSH_CLIENT}" != "" ] && echo "URL: https://github.com$MAX_RELEASE_URL?raw=true"
  314. if curl $CURL_RETRY $SSL_SECURITY_OPTION -L "https://github.com$MAX_RELEASE_URL?raw=true" -o "$CURRENT_DIR/$FILE_NAME"
  315. then
  316. if [ ${DELETE_OLD_FILES} == "true" ]
  317. then
  318. echo "Deleting old ${BASE_FILE_NAME} files"
  319. rm "${CURRENT_DIR}/${BASE_FILE_NAME}"*.${TO_BE_DELETED_EXTENSION} > /dev/null 2>&1
  320. fi
  321. if [ $BASE_FILE_NAME == "MiSTer" ] || [ $BASE_FILE_NAME == "menu" ]
  322. then
  323. DESTINATION_FILE=$(echo "$MAX_RELEASE_URL" | sed 's/.*\///g' | sed 's/_[0-9]\{8\}[a-zA-Z]\{0,1\}//g')
  324. echo "Moving $DESTINATION_FILE"
  325. rm "/media/fat/$DESTINATION_FILE" > /dev/null 2>&1
  326. mv "$CURRENT_DIR/$FILE_NAME" "/media/fat/$DESTINATION_FILE"
  327. touch "$CURRENT_DIR/$FILE_NAME"
  328. REBOOT_NEEDED="true"
  329. fi
  330. if echo "$CORE_URL" | grep -q "SD-Installer"
  331. then
  332. SD_INSTALLER_PATH="$CURRENT_DIR/$FILE_NAME"
  333. fi
  334. if [ "$CORE_CATEGORY" == "arcade-cores" ]
  335. then
  336. OLD_IFS="$IFS"
  337. IFS="|"
  338. for ARCADE_ALT_PATH in $ARCADE_ALT_PATHS
  339. do
  340. for ARCADE_ALT_DIR in "$ARCADE_ALT_PATH/_$BASE_FILE_NAME"*
  341. do
  342. if [ -d "$ARCADE_ALT_DIR" ]
  343. then
  344. echo "Updating $(echo $ARCADE_ALT_DIR | sed 's/.*\///g')"
  345. if [ $DELETE_OLD_FILES == "true" ]
  346. then
  347. for ARCADE_HACK_CORE in "$ARCADE_ALT_DIR/"*.rbf
  348. do
  349. if [ -f "$ARCADE_HACK_CORE" ] && { echo "$ARCADE_HACK_CORE" | grep -q "$BASE_FILE_NAME\_[0-9]\{8\}[a-zA-Z]\?\.rbf$"; }
  350. then
  351. rm "$ARCADE_HACK_CORE" > /dev/null 2>&1
  352. fi
  353. done
  354. fi
  355. cp "$CURRENT_DIR/$FILE_NAME" "$ARCADE_ALT_DIR/"
  356. fi
  357. done
  358. done
  359. IFS="$OLD_IFS"
  360. fi
  361. else
  362. echo "${FILE_NAME} download failed"
  363. rm "${CURRENT_DIR}/${FILE_NAME}" > /dev/null 2>&1
  364. if [ ${DELETE_OLD_FILES} == "true" ]
  365. then
  366. echo "Restoring old ${BASE_FILE_NAME} files"
  367. for FILE_TO_BE_RESTORED in "${CURRENT_DIR}/${BASE_FILE_NAME}"*.${TO_BE_DELETED_EXTENSION}
  368. do
  369. mv "${FILE_TO_BE_RESTORED}" "${FILE_TO_BE_RESTORED%.${TO_BE_DELETED_EXTENSION}}" > /dev/null 2>&1
  370. done
  371. fi
  372. fi
  373. sync
  374. else
  375. echo "New core: $FILE_NAME"
  376. fi
  377. else
  378. echo "Nothing to update"
  379. fi
  380. echo ""
  381. }
  382. for CORE_URL in $CORE_URLS; do
  383. if [[ $CORE_URL == https://* ]]
  384. then
  385. if [ "$REPOSITORIES_FILTER" == "" ] || { echo "$CORE_URL" | grep -qi "$REPOSITORIES_FILTER"; } || { echo "$CORE_CATEGORY" | grep -qi "$CORE_CATEGORIES_FILTER"; }
  386. then
  387. if echo "$CORE_URL" | grep -qE "(SD-Installer)|(/Main_MiSTer$)|(/Menu_MiSTer$)"
  388. then
  389. checkCoreURL
  390. else
  391. [ "$PARALLEL_UPDATE" == "true" ] && { echo "$(checkCoreURL)"$'\n' & } || checkCoreURL
  392. fi
  393. fi
  394. else
  395. CORE_CATEGORY=$(echo "$CORE_URL" | sed 's/user-content-//g')
  396. if [ "$CORE_CATEGORY" == "" ]
  397. then
  398. CORE_CATEGORY="-"
  399. fi
  400. if [ "$CORE_CATEGORY" == "computer-cores" ]
  401. then
  402. CORE_CATEGORY="cores"
  403. fi
  404. fi
  405. done
  406. wait
  407. echo "Done!"
  408. if [ $REBOOT_NEEDED == "true" ]
  409. then
  410. if [ $AUTOREBOOT == "true" ]
  411. then
  412. echo "Rebooting in $REBOOT_PAUSE seconds"
  413. sleep $REBOOT_PAUSE
  414. reboot now
  415. else
  416. echo "You should reboot"
  417. fi
  418. fi
  419. exit 0