Update_RetroDriven.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 2019 Alessandro "Locutus73" Miele
  13. # You can download the latest version of this script from:
  14. # https://github.com/RetroDriven/MiSTer_UnofficialCores
  15. # RetroDriven v1.0 - Changed Script as needed
  16. # ========= OPTIONS ==================
  17. URL="https://github.com"
  18. SCRIPT_URL="${URL}/RetroDriven/MiSTer_UnofficialCores/blob/master/Scripts/Updater_RetroDriven.sh"
  19. CURL_RETRY="--connect-timeout 15 --max-time 120 --retry 3 --retry-delay 5 --silent"
  20. # ========= ADVANCED OPTIONS =========
  21. # ALLOW_INSECURE_SSL="true" will check if SSL certificate verification (see https://curl.haxx.se/docs/sslcerts.html )
  22. # is working (CA certificates installed) and when it's working it will use this feature for safe curl HTTPS downloads,
  23. # otherwise it will use --insecure option for disabling SSL certificate verification.
  24. # If CA certificates aren't installed it's advised to install them (i.e. using security_fixes.sh).
  25. # ALLOW_INSECURE_SSL="false" will never use --insecure option and if CA certificates aren't installed
  26. # any download will fail.
  27. ALLOW_INSECURE_SSL="true"
  28. # ========= CODE STARTS HERE =========
  29. # get the name of the script, or of the parent script if called through a 'curl ... | bash -'
  30. ORIGINAL_SCRIPT_PATH="${0}"
  31. [[ "${ORIGINAL_SCRIPT_PATH}" == "bash" ]] && \
  32. ORIGINAL_SCRIPT_PATH="$(ps -o comm,pid | awk -v PPID=${PPID} '$2 == PPID {print $1}')"
  33. # ini file can contain user defined variables (as bash commands)
  34. # Load and execute the content of the ini file, if there is one
  35. INI_PATH="${ORIGINAL_SCRIPT_PATH%.*}.ini"
  36. if [[ -f "${INI_PATH}" ]] ; then
  37. TMP=$(mktemp)
  38. # preventively eliminate DOS-specific format and exit command
  39. dos2unix < "${INI_PATH}" 2> /dev/null | grep -v "^exit" > ${TMP}
  40. source ${TMP}
  41. rm -f ${TMP}
  42. fi
  43. # test network and https by pinging the target website
  44. SSL_SECURITY_OPTION=""
  45. curl ${CURL_RETRY} "${URL}" > /dev/null 2>&1
  46. case $? in
  47. 0)
  48. ;;
  49. 60)
  50. if [[ "${ALLOW_INSECURE_SSL}" == "true" ]]
  51. then
  52. SSL_SECURITY_OPTION="--insecure"
  53. else
  54. echo "CA certificates need"
  55. echo "to be fixed for"
  56. echo "using SSL certificate"
  57. echo "verification."
  58. echo "Please fix them i.e."
  59. echo "using security_fixes.sh"
  60. exit 2
  61. fi
  62. ;;
  63. *)
  64. echo "No Internet connection"
  65. exit 1
  66. ;;
  67. esac
  68. # download and execute the latest mister_updater.sh
  69. echo "Downloading and executing"
  70. echo "${SCRIPT_URL/*\//}"
  71. echo ""
  72. curl \
  73. ${CURL_RETRY} \
  74. ${SSL_SECURITY_OPTION} \
  75. --fail \
  76. --location \
  77. "${SCRIPT_URL}?raw=true" | \
  78. bash -
  79. exit 0