@@ -40,6 +40,7 @@ initArch() {
4040 armv6* ) ARCH=" ARMv6" ;;
4141 armv7* ) ARCH=" ARMv7" ;;
4242 aarch64) ARCH=" ARM64" ;;
43+ arm64) ARCH=" ARM64" ;;
4344 x86) ARCH=" 32bit" ;;
4445 x86_64) ARCH=" 64bit" ;;
4546 i686) ARCH=" 32bit" ;;
@@ -48,6 +49,15 @@ initArch() {
4849 echo " ARCH=$ARCH "
4950}
5051
52+ initFallbackArch () {
53+ case " ${OS} _${ARCH} " in
54+ macOS_ARM64)
55+ # Rosetta 2 allows applications built for x86-64 hosts to run on the ARM 64-bit M1 processor
56+ FALLBACK_ARCH=' 64bit'
57+ ;;
58+ esac
59+ }
60+
5161initOS () {
5262 OS=$( uname -s)
5363 case " $OS " in
@@ -106,52 +116,69 @@ downloadFile() {
106116 TAG=$1
107117 fi
108118 # arduino-lint_0.4.0-rc1_Linux_64bit.[tar.gz, zip]
119+ APPLICATION_DIST_PREFIX=" ${PROJECT_NAME} _${TAG} _"
109120 if [ " $OS " = " Windows" ]; then
110- APPLICATION_DIST= " ${PROJECT_NAME} _ ${TAG} _ ${OS} _ ${ARCH} .zip"
121+ APPLICATION_DIST_EXTENSION= " .zip"
111122 else
112- APPLICATION_DIST= " ${PROJECT_NAME} _ ${TAG} _ ${OS} _ ${ARCH} .tar.gz"
123+ APPLICATION_DIST_EXTENSION= " .tar.gz"
113124 fi
125+ APPLICATION_DIST=" ${APPLICATION_DIST_PREFIX}${OS} _${ARCH}${APPLICATION_DIST_EXTENSION} "
114126
115127 # Support specifying nightly build versions (e.g., "nightly-latest") via the script argument.
116128 case " $TAG " in
117129 nightly* )
118- DOWNLOAD_URL =" https://downloads.arduino.cc/${PROJECT_NAME} /nightly/${APPLICATION_DIST} "
130+ DOWNLOAD_URL_PREFIX =" https://downloads.arduino.cc/${PROJECT_NAME} /nightly/"
119131 ;;
120132 * )
121- DOWNLOAD_URL =" https://downloads.arduino.cc/${PROJECT_NAME} /${APPLICATION_DIST} "
133+ DOWNLOAD_URL_PREFIX =" https://downloads.arduino.cc/${PROJECT_NAME} /"
122134 ;;
123135 esac
136+ DOWNLOAD_URL=" ${DOWNLOAD_URL_PREFIX}${APPLICATION_DIST} "
124137
125138 INSTALLATION_TMP_FILE=" /tmp/$APPLICATION_DIST "
126139 echo " Downloading $DOWNLOAD_URL "
127140 httpStatusCode=$( getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE " )
128141 if [ " $httpStatusCode " -ne 200 ]; then
129- echo " Did not find a release for your system: $OS $ARCH "
130- echo " Trying to find a release using the GitHub API."
131-
132- LATEST_RELEASE_URL=" https://api.github.com/repos/${PROJECT_OWNER} /$PROJECT_NAME /releases/tags/$TAG "
133- if [ " $DOWNLOAD_TOOL " = " curl" ]; then
134- HTTP_RESPONSE=$( curl -sL --write-out ' HTTPSTATUS:%{http_code}' " $LATEST_RELEASE_URL " )
135- HTTP_STATUS_CODE=$( echo " $HTTP_RESPONSE " | tr -d ' \n' | sed -e ' s/.*HTTPSTATUS://' )
136- BODY=$( echo " $HTTP_RESPONSE " | sed -e ' s/HTTPSTATUS\:.*//g' )
137- elif [ " $DOWNLOAD_TOOL " = " wget" ]; then
138- TMP_FILE=$( mktemp)
139- BODY=$( wget --server-response --content-on-error -q -O - " $LATEST_RELEASE_URL " 2> " $TMP_FILE " || true)
140- HTTP_STATUS_CODE=$( awk ' /^ HTTP/{print $2}' " $TMP_FILE " )
141- fi
142- if [ " $HTTP_STATUS_CODE " != 200 ]; then
143- echo " Request failed with HTTP status code $HTTP_STATUS_CODE "
144- fail " Body: $BODY "
142+ if [ -n " $FALLBACK_ARCH " ]; then
143+ echo " $OS $ARCH release not currently available. Checking for alternative $OS $FALLBACK_ARCH release for your system."
144+ FALLBACK_APPLICATION_DIST=" ${APPLICATION_DIST_PREFIX}${OS} _${FALLBACK_ARCH}${APPLICATION_DIST_EXTENSION} "
145+ DOWNLOAD_URL=" ${DOWNLOAD_URL_PREFIX}${FALLBACK_APPLICATION_DIST} "
146+ echo " Downloading $DOWNLOAD_URL "
147+ httpStatusCode=$( getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE " )
145148 fi
146149
147- # || true forces this command to not catch error if grep does not find anything
148- DOWNLOAD_URL=$( echo " $BODY " | grep ' browser_' | cut -d\" -f4 | grep " $APPLICATION_DIST " ) || true
149- if [ -z " $DOWNLOAD_URL " ]; then
150- echo " Sorry, we dont have a dist for your system: $OS $ARCH "
151- fail " You can request one here: https://github.com/${PROJECT_OWNER} /$PROJECT_NAME /issues"
152- else
153- echo " Downloading $DOWNLOAD_URL "
154- getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE "
150+ if [ " $httpStatusCode " -ne 200 ]; then
151+ echo " Did not find a release for your system: $OS $ARCH "
152+ echo " Trying to find a release using the GitHub API."
153+
154+ LATEST_RELEASE_URL=" https://api.github.com/repos/${PROJECT_OWNER} /$PROJECT_NAME /releases/tags/$TAG "
155+ if [ " $DOWNLOAD_TOOL " = " curl" ]; then
156+ HTTP_RESPONSE=$( curl -sL --write-out ' HTTPSTATUS:%{http_code}' " $LATEST_RELEASE_URL " )
157+ HTTP_STATUS_CODE=$( echo " $HTTP_RESPONSE " | tr -d ' \n' | sed -e ' s/.*HTTPSTATUS://' )
158+ BODY=$( echo " $HTTP_RESPONSE " | sed -e ' s/HTTPSTATUS\:.*//g' )
159+ elif [ " $DOWNLOAD_TOOL " = " wget" ]; then
160+ TMP_FILE=$( mktemp)
161+ BODY=$( wget --server-response --content-on-error -q -O - " $LATEST_RELEASE_URL " 2> " $TMP_FILE " || true)
162+ HTTP_STATUS_CODE=$( awk ' /^ HTTP/{print $2}' " $TMP_FILE " )
163+ fi
164+ if [ " $HTTP_STATUS_CODE " != 200 ]; then
165+ echo " Request failed with HTTP status code $HTTP_STATUS_CODE "
166+ fail " Body: $BODY "
167+ fi
168+
169+ # || true forces this command to not catch error if grep does not find anything
170+ DOWNLOAD_URL=$( echo " $BODY " | grep ' browser_' | cut -d\" -f4 | grep " $APPLICATION_DIST " ) || true
171+ if [ -z " $DOWNLOAD_URL " ]; then
172+ DOWNLOAD_URL=$( echo " $BODY " | grep ' browser_' | cut -d\" -f4 | grep " $FALLBACK_APPLICATION_DIST " ) || true
173+ fi
174+
175+ if [ -z " $DOWNLOAD_URL " ]; then
176+ echo " Sorry, we dont have a dist for your system: $OS $ARCH "
177+ fail " You can request one here: https://github.com/${PROJECT_OWNER} /$PROJECT_NAME /issues"
178+ else
179+ echo " Downloading $DOWNLOAD_URL "
180+ getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE "
181+ fi
155182 fi
156183 fi
157184}
@@ -208,6 +235,7 @@ initDestination
208235set -e
209236initArch
210237initOS
238+ initFallbackArch
211239initDownloadTool
212240downloadFile " $1 "
213241installFile
0 commit comments