| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- #!/bin/bash
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- # Copyright 2018-2019 Alessandro "Locutus73" Miele
- # You can download the latest version of this script from:
- # https://github.com/RetroDriven/MiSTer_UnofficialCores
- : '
- ###### Disclaimer / Legal Information ######
- By downloading ROM injected Core/RBF files you are agreeing to the following:
- * You are responsible for checking your local laws regarding the use of the ROMs associated with the injected Core/RBF files.
- * You are authorized/licensed to own/use the ROMs associated with the injected Core/RBF files that you download.
- * You will not distribute any of these files without the appropriate permissions.
- * You own the original Arcade PCB for each ROM injected Core/RBF file that you download.
- * I take no responsibility for any data loss or anything, use the script at your own risk.
- '
- # v1.3 - Adjusted Script and INI File for RetroDriven Core Filtering
- # v1.2 - Removed Cores from GitHub. Adjusted script to account for this change
- # v1.0 - Changed original Script from Locutus73 as needed
- #========= USER OPTIONS =========
- #Base directory for all script’s tasks, "/media/fat" for SD root, "/media/usb0" for USB drive root.
- BASE_PATH="/media/fat"
- #Directory where RetroDriven Cores are downloaded
- declare -A CORE_CATEGORY_PATHS
- CORE_CATEGORY_PATHS["arcade-cores"]="$BASE_PATH/_RetroDriven"
- DELETE_OLD_FILES="true"
- DOWNLOAD_NEW_CORES="true"
- REMOVE_ARCADE_PREFIX="true"
- #EXPERIMENTAL: specifies if the update process must be done with parallel processing; use it at your own risk!
- PARALLEL_UPDATE="false"
- #========= ADVANCED OPTIONS =========
- #ALLOW_INSECURE_SSL="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).
- #ALLOW_INSECURE_SSL="false" will never use --insecure option and if CA certificates aren't installed
- #any download will fail.
- ALLOW_INSECURE_SSL="true"
- CURL_RETRY="--connect-timeout 15 --max-time 120 --retry 3 --retry-delay 5"
- SCRIPTS_PATH="Scripts"
- OLD_SCRIPTS_PATH="#Scripts"
- WORK_PATH="/media/fat/$SCRIPTS_PATH/.mister_updater"
- #Uncomment this if you want the script to sync the system date and time with a NTP server
- #NTP_SERVER="0.pool.ntp.org"
- AUTOREBOOT="false"
- REBOOT_PAUSE=0
- TEMP_PATH="/tmp"
- TO_BE_DELETED_EXTENSION="to_be_deleted"
- echo
- echo "*** NEWS: RetroDriven.com - Launching Soon! ***"
- echo
- sleep 3
- echo "*** RetroDriven Core Updater - A Festivus for the rest of Us! ***"
- echo
- sleep 3
- #========= CODE STARTS HERE =========
- ORIGINAL_SCRIPT_PATH="$0"
- if [ "$ORIGINAL_SCRIPT_PATH" == "bash" ]
- then
- ORIGINAL_SCRIPT_PATH=$(ps | grep "^ *$PPID " | grep -o "[^ ]*$")
- fi
- INI_PATH=${ORIGINAL_SCRIPT_PATH%.*}.ini
- if [ -f $INI_PATH ]
- then
- eval "$(cat $INI_PATH | tr -d '\r')"
- fi
- if [ -d "${BASE_PATH}/${OLD_SCRIPTS_PATH}" ] && [ ! -d "${BASE_PATH}/${SCRIPTS_PATH}" ]
- then
- mv "${BASE_PATH}/${OLD_SCRIPTS_PATH}" "${BASE_PATH}/${SCRIPTS_PATH}"
- echo "Moved"
- echo "${BASE_PATH}/${OLD_SCRIPTS_PATH}"
- echo "to"
- echo "${BASE_PATH}/${SCRIPTS_PATH}"
- echo "please relaunch the script."
- exit 3
- fi
- SSL_SECURITY_OPTION=""
- curl $CURL_RETRY -q https://retrodriven.com &>/dev/null
- case $? in
- 0)
- ;;
- 60)
- if [ "$ALLOW_INSECURE_SSL" == "true" ]
- then
- SSL_SECURITY_OPTION="--insecure"
- else
- echo "CA certificates need"
- echo "to be fixed for"
- echo "using SSL certificate"
- echo "verification."
- echo "Please fix them i.e."
- echo "using security_fixes.sh"
- exit 2
- fi
- ;;
- *)
- echo "No Internet connection"
- exit 1
- ;;
- esac
- ## sync with a public time server
- if [[ -n "${NTP_SERVER}" ]] ; then
- echo "Syncing date and time with"
- echo "${NTP_SERVER}"
- # (-b) force time reset, (-s) write output to syslog, (-u) use
- # unprivileged port for outgoing packets to workaround firewalls
- ntpdate -b -s -u "${NTP_SERVER}"
- echo
- fi
- mkdir -p "${CORE_CATEGORY_PATHS[@]}"
- declare -A NEW_CORE_CATEGORY_PATHS
- if [ "$DOWNLOAD_NEW_CORES" != "true" ] && [ "$DOWNLOAD_NEW_CORES" != "false" ] && [ "$DOWNLOAD_NEW_CORES" != "" ]
- then
- for idx in "${!CORE_CATEGORY_PATHS[@]}"; do
- 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")
- done
- mkdir -p "${NEW_CORE_CATEGORY_PATHS[@]}"
- fi
- CORE_URLS=$(curl $CURL_RETRY $SSL_SECURITY_OPTION -sLf "https://github.com/RetroDriven/MiSTer_UnofficialCores/wiki" | grep -io '\(https://retrodriven.com/Mister_Cores/[a-zA-Z0-9./_-]*\)\|\(user-content-[a-z-]*\)')
- #CORE_CATEGORY="-"
- SD_INSTALLER_PATH=""
- REBOOT_NEEDED="false"
- #CORE_CATEGORIES_FILTER=""
- CORE_CATEGORY="zzz"
- CORE_CATEGORIES_FILTER="zzz"
- CORE_CATEGORIES_FILTER=""
- if [ "$REPOSITORIES_FILTER" != "" ]
- then
- CORE_CATEGORIES_FILTER="^\($( echo "$REPOSITORIES_FILTER" | sed 's/[ ]\{1,\}/\\)\\|\\(/g' )\)$"
- REPOSITORIES_FILTER="\(Main_MiSTer\)\|\(Menu_MiSTer\)\|\(SD-Installer-Win64_MiSTer\)\|\($( echo "$REPOSITORIES_FILTER" | sed 's/[ ]\{1,\}/\\)\\|\\([\/_-]/g' )\)"
- fi
- GOOD_CORES=""
- if [ "$GOOD_CORES_URL" != "" ]
- then
- GOOD_CORES=$(curl $CURL_RETRY $SSL_SECURITY_OPTION -sLf "$GOOD_CORES_URL")
- fi
- function checkCoreURL {
- echo "Checking $(echo $CORE_URL | sed 's/.*\///g' | sed 's/_MiSTer//gI')"
- [ "${SSH_CLIENT}" != "" ] && echo "URL: $CORE_URL"
- CORE_URL+="/releases/"
-
- RELEASE_URLS=$(curl $CURL_RETRY $SSL_SECURITY_OPTION -sLf "$CORE_URL" | grep -o '"[a-zA-Z0-9./_-]*_[0-9]\{8\}[a-zA-Z]\?\(\.rbf\|\.rar\)\?')
-
- MAX_VERSION=""
- MAX_RELEASE_URL=""
- GOOD_CORE_VERSION=""
- for RELEASE_URL in $RELEASE_URLS; do
- RELEASE_URL=$CORE_URL${RELEASE_URL#\"}
-
- if echo "$RELEASE_URL" | grep -q "SharpMZ"
- then
- RELEASE_URL=$(echo "$RELEASE_URL" | grep '\.rbf$')
- fi
- if echo "$RELEASE_URL" | grep -q "Atari800"
- then
- if [ "$CORE_CATEGORY" == "cores" ]
- then
- RELEASE_URL=$(echo "$RELEASE_URL" | grep '800_[0-9]\{8\}[a-zA-Z]\?\.rbf$')
- else
- RELEASE_URL=$(echo "$RELEASE_URL" | grep '5200_[0-9]\{8\}[a-zA-Z]\?\.rbf$')
- fi
- fi
- CURRENT_VERSION=$(echo "$RELEASE_URL" | grep -o '[0-9]\{8\}[a-zA-Z]\?')
-
- if [ "$GOOD_CORES" != "" ]
- then
- GOOD_CORE_VERSION=$(echo "$GOOD_CORES" | grep -wo "$(echo "$RELEASE_URL" | sed 's/.*\///g')" | grep -o '[0-9]\{8\}[a-zA-Z]\?')
- if [ "$GOOD_CORE_VERSION" != "" ]
- then
- MAX_VERSION=$CURRENT_VERSION
- MAX_RELEASE_URL=$RELEASE_URL
- break
- fi
- fi
-
- if [[ "$CURRENT_VERSION" > "$MAX_VERSION" ]]
- then
- MAX_VERSION=$CURRENT_VERSION
- MAX_RELEASE_URL=$RELEASE_URL
- fi
- done
-
- FILE_NAME=$(echo "$MAX_RELEASE_URL" | sed 's/.*\///g')
- if [ "$CORE_CATEGORY" == "arcade-cores" ] && [ $REMOVE_ARCADE_PREFIX == "true" ]
- then
- FILE_NAME=$(echo "$FILE_NAME" | sed 's/Arcade-//gI')
- fi
- BASE_FILE_NAME=$(echo "$FILE_NAME" | sed 's/_[0-9]\{8\}.*//g')
-
- CURRENT_DIRS="${CORE_CATEGORY_PATHS[$CORE_CATEGORY]}"
- if [ "${NEW_CORE_CATEGORY_PATHS[$CORE_CATEGORY]}" != "" ]
- then
- CURRENT_DIRS=("$CURRENT_DIRS" "${NEW_CORE_CATEGORY_PATHS[$CORE_CATEGORY]}")
- fi
- if [ "$CURRENT_DIRS" == "" ]
- then
- CURRENT_DIRS=("$BASE_PATH")
- fi
- if [ "$BASE_FILE_NAME" == "MiSTer" ] || [ "$BASE_FILE_NAME" == "menu" ] || { echo "$CORE_URL" | grep -q "SD-Installer"; }
- then
- mkdir -p "$WORK_PATH"
- CURRENT_DIRS=("$WORK_PATH")
- fi
-
- CURRENT_LOCAL_VERSION=""
- MAX_LOCAL_VERSION=""
- for CURRENT_DIR in "${CURRENT_DIRS[@]}"
- do
- for CURRENT_FILE in "$CURRENT_DIR/$BASE_FILE_NAME"*
- do
- if [ -f "$CURRENT_FILE" ]
- then
- if echo "$CURRENT_FILE" | grep -q "$BASE_FILE_NAME\_[0-9]\{8\}[a-zA-Z]\?\(\.rbf\|\.rar\)\?$"
- then
- CURRENT_LOCAL_VERSION=$(echo "$CURRENT_FILE" | grep -o '[0-9]\{8\}[a-zA-Z]\?')
- if [ "$GOOD_CORE_VERSION" != "" ]
- then
- if [ "$CURRENT_LOCAL_VERSION" == "$GOOD_CORE_VERSION" ]
- then
- MAX_LOCAL_VERSION=$CURRENT_LOCAL_VERSION
- else
- if [ "$MAX_LOCAL_VERSION" == "" ]
- then
- MAX_LOCAL_VERSION="00000000"
- fi
- if [ $DELETE_OLD_FILES == "true" ]
- then
- mv "${CURRENT_FILE}" "${CURRENT_FILE}.${TO_BE_DELETED_EXTENSION}" > /dev/null 2>&1
- fi
- fi
- else
- if [[ "$CURRENT_LOCAL_VERSION" > "$MAX_LOCAL_VERSION" ]]
- then
- MAX_LOCAL_VERSION=$CURRENT_LOCAL_VERSION
- fi
- if [[ "$MAX_VERSION" > "$CURRENT_LOCAL_VERSION" ]] && [ $DELETE_OLD_FILES == "true" ]
- then
- # echo "Moving $(echo ${CURRENT_FILE} | sed 's/.*\///g')"
- mv "${CURRENT_FILE}" "${CURRENT_FILE}.${TO_BE_DELETED_EXTENSION}" > /dev/null 2>&1
- fi
- fi
-
- fi
- fi
- done
- if [ "$MAX_LOCAL_VERSION" != "" ]
- then
- break
- fi
- done
-
- if [[ "$MAX_VERSION" > "$MAX_LOCAL_VERSION" ]]
- then
- if [ "$DOWNLOAD_NEW_CORES" != "false" ] || [ "$MAX_LOCAL_VERSION" != "" ] || [ "$BASE_FILE_NAME" == "MiSTer" ] || [ "$BASE_FILE_NAME" == "menu" ] || { echo "$CORE_URL" | grep -q "SD-Installer"; }
- then
- echo "Downloading $FILE_NAME"
- [ "${SSH_CLIENT}" != "" ] && echo "URL: $MAX_RELEASE_URL"
- if curl $CURL_RETRY $SSL_SECURITY_OPTION -L "$MAX_RELEASE_URL" -o "$CURRENT_DIR/$FILE_NAME"
- then
- if [ ${DELETE_OLD_FILES} == "true" ]
- then
- echo "Deleting old ${BASE_FILE_NAME} files"
- rm "${CURRENT_DIR}/${BASE_FILE_NAME}"*.${TO_BE_DELETED_EXTENSION} > /dev/null 2>&1
- fi
- if [ $BASE_FILE_NAME == "MiSTer" ] || [ $BASE_FILE_NAME == "menu" ]
- then
- DESTINATION_FILE=$(echo "$MAX_RELEASE_URL" | sed 's/.*\///g' | sed 's/_[0-9]\{8\}[a-zA-Z]\{0,1\}//g')
- echo "Moving $DESTINATION_FILE"
- rm "/media/fat/$DESTINATION_FILE" > /dev/null 2>&1
- mv "$CURRENT_DIR/$FILE_NAME" "/media/fat/$DESTINATION_FILE"
- touch "$CURRENT_DIR/$FILE_NAME"
- REBOOT_NEEDED="true"
- fi
- if echo "$CORE_URL" | grep -q "SD-Installer"
- then
- SD_INSTALLER_PATH="$CURRENT_DIR/$FILE_NAME"
- fi
- if [ "$CORE_CATEGORY" == "arcade-cores" ]
- then
- OLD_IFS="$IFS"
- IFS="|"
- for ARCADE_ALT_PATH in $ARCADE_ALT_PATHS
- do
- for ARCADE_ALT_DIR in "$ARCADE_ALT_PATH/_$BASE_FILE_NAME"*
- do
- if [ -d "$ARCADE_ALT_DIR" ]
- then
- echo "Updating $(echo $ARCADE_ALT_DIR | sed 's/.*\///g')"
- if [ $DELETE_OLD_FILES == "true" ]
- then
- for ARCADE_HACK_CORE in "$ARCADE_ALT_DIR/"*.rbf
- do
- if [ -f "$ARCADE_HACK_CORE" ] && { echo "$ARCADE_HACK_CORE" | grep -q "$BASE_FILE_NAME\_[0-9]\{8\}[a-zA-Z]\?\.rbf$"; }
- then
- rm "$ARCADE_HACK_CORE" > /dev/null 2>&1
- fi
- done
- fi
- cp "$CURRENT_DIR/$FILE_NAME" "$ARCADE_ALT_DIR/"
- fi
- done
- done
- IFS="$OLD_IFS"
- fi
- else
- echo "${FILE_NAME} download failed"
- rm "${CURRENT_DIR}/${FILE_NAME}" > /dev/null 2>&1
- if [ ${DELETE_OLD_FILES} == "true" ]
- then
- echo "Restoring old ${BASE_FILE_NAME} files"
- for FILE_TO_BE_RESTORED in "${CURRENT_DIR}/${BASE_FILE_NAME}"*.${TO_BE_DELETED_EXTENSION}
- do
- mv "${FILE_TO_BE_RESTORED}" "${FILE_TO_BE_RESTORED%.${TO_BE_DELETED_EXTENSION}}" > /dev/null 2>&1
- done
- fi
- fi
- sync
- else
- echo "New core: $FILE_NAME"
- fi
- else
- echo "Core is up to date!"
- fi
-
- echo ""
- }
- for CORE_URL in $CORE_URLS; do
- if [[ $CORE_URL == https://* ]]
- then
- if [ "$REPOSITORIES_FILTER" == "" ] || { echo "$CORE_URL" | grep -qi "$REPOSITORIES_FILTER"; } || { echo "$CORE_CATEGORY" | grep -qi "$CORE_CATEGORIES_FILTER"; }
- then
- if echo "$CORE_URL" | grep -qE "(SD-Installer)|(/Main_MiSTer$)|(/Menu_MiSTer$)"
- then
- checkCoreURL
- else
- [ "$PARALLEL_UPDATE" == "true" ] && { echo "$(checkCoreURL)"$'\n' & } || checkCoreURL
- fi
- fi
- else
- CORE_CATEGORY=$(echo "$CORE_URL" | sed 's/user-content-//g')
- if [ "$CORE_CATEGORY" == "" ]
- then
- CORE_CATEGORY="-" || { echo "$CORE_URL" | grep -qi "$REPOSITORIES_FILTER"; } || { echo "$CORE_CATEGORY" | grep -qi "$CORE_CATEGORIES_FILTER";}
- fi
- if [ "$CORE_CATEGORY" == "computer-cores" ]
- then
- CORE_CATEGORY="cores"
- fi
- fi
- done
- wait
- echo "*** All RetroDriven Cores have been Updated! ***"
- echo
- #echo "** Please visit RetroDriven.com for all of your MiSTer and Retro News and Updates! ***"
- echo
- #sleep 3
- if [ $REBOOT_NEEDED == "true" ]
- then
- if [ $AUTOREBOOT == "true" ]
- then
- echo "Rebooting in $REBOOT_PAUSE seconds"
- sleep $REBOOT_PAUSE
- reboot now
- else
- echo "You should reboot"
- fi
- fi
- exit 0
|