update_retrodriven.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 original version of this script from:
  14. # https://github.com/MiSTer-devel/Updater_script_MiSTer
  15. # Version RetroDriven - Changes for updating cores from @RetroDriven
  16. # Version 2.1.2 - 2019-08-16 - Minor refactoring by frederic-mahe, thank you very much.
  17. # Version 2.1.1 - 2019-06-10 - Testing Internet connectivity with github.com instead of google.com.
  18. # Version 2.1 - 2019-02-23 - 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.
  19. # Version 2.1 - 2019-02-23 - Code review by frederic-mahe, now the script is more standardized and elegant, thank you very much; ALLOW_INSECURE_SSH renamed to ALLOW_INSECURE_SSL.
  20. # 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.
  21. # Version 1.0 - 2019-01-07 - First commit
  22. # ========= OPTIONS ==================
  23. URL="https://github.com"
  24. SCRIPT_URL="${URL}/RetroDriven/MiSTer_UnofficialCores/tree/master/Updater/mister_updater_retrodriven.sh"
  25. CURL_RETRY="--connect-timeout 15 --max-time 120 --retry 3 --retry-delay 5 --silent"
  26. # ========= ADVANCED OPTIONS =========
  27. # ALLOW_INSECURE_SSL="true" will check if SSL certificate verification (see https://curl.haxx.se/docs/sslcerts.html )
  28. # is working (CA certificates installed) and when it's working it will use this feature for safe curl HTTPS downloads,
  29. # otherwise it will use --insecure option for disabling SSL certificate verification.
  30. # If CA certificates aren't installed it's advised to install them (i.e. using security_fixes.sh).
  31. # ALLOW_INSECURE_SSL="false" will never use --insecure option and if CA certificates aren't installed
  32. # any download will fail.
  33. ALLOW_INSECURE_SSL="true"
  34. # ========= CODE STARTS HERE =========
  35. # get the name of the script, or of the parent script if called through a 'curl ... | bash -'
  36. ORIGINAL_SCRIPT_PATH="${0}"
  37. [[ "${ORIGINAL_SCRIPT_PATH}" == "bash" ]] && \
  38. ORIGINAL_SCRIPT_PATH="$(ps -o comm,pid | awk -v PPID=${PPID} '$2 == PPID {print $1}')"
  39. # ini file can contain user defined variables (as bash commands)
  40. # Load and execute the content of the ini file, if there is one
  41. INI_PATH="${ORIGINAL_SCRIPT_PATH%.*}.ini"
  42. if [[ -f "${INI_PATH}" ]] ; then
  43. TMP=$(mktemp)
  44. # preventively eliminate DOS-specific format and exit command
  45. dos2unix < "${INI_PATH}" 2> /dev/null | grep -v "^exit" > ${TMP}
  46. source ${TMP}
  47. rm -f ${TMP}
  48. fi
  49. # test network and https by pinging the target website
  50. SSL_SECURITY_OPTION=""
  51. curl ${CURL_RETRY} "${URL}" > /dev/null 2>&1
  52. case $? in
  53. 0)
  54. ;;
  55. 60)
  56. if [[ "${ALLOW_INSECURE_SSL}" == "true" ]]
  57. then
  58. SSL_SECURITY_OPTION="--insecure"
  59. else
  60. echo "CA certificates need"
  61. echo "to be fixed for"
  62. echo "using SSL certificate"
  63. echo "verification."
  64. echo "Please fix them i.e."
  65. echo "using security_fixes.sh"
  66. exit 2
  67. fi
  68. ;;
  69. *)
  70. echo "No Internet connection"
  71. exit 1
  72. ;;
  73. esac
  74. # download and execute the latest mister_updater.sh
  75. echo "Downloading and executing"
  76. echo "${SCRIPT_URL/*\//}"
  77. echo ""
  78. curl \
  79. ${CURL_RETRY} \
  80. ${SSL_SECURITY_OPTION} \
  81. --fail \
  82. --location \
  83. "${SCRIPT_URL}?raw=true" | \
  84. bash -
  85. exit 0