@@ -40,6 +40,7 @@ initArch() {
40
40
armv6* ) ARCH=" ARMv6" ;;
41
41
armv7* ) ARCH=" ARMv7" ;;
42
42
aarch64) ARCH=" ARM64" ;;
43
+ arm64) ARCH=" ARM64" ;;
43
44
x86) ARCH=" 32bit" ;;
44
45
x86_64) ARCH=" 64bit" ;;
45
46
i686) ARCH=" 32bit" ;;
@@ -48,6 +49,15 @@ initArch() {
48
49
echo " ARCH=$ARCH "
49
50
}
50
51
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
+
51
61
initOS () {
52
62
OS=$( uname -s)
53
63
case " $OS " in
@@ -70,6 +80,7 @@ initDownloadTool() {
70
80
echo " Using $DOWNLOAD_TOOL as download tool"
71
81
}
72
82
83
+ # checkLatestVersion() sets the CHECKLATESTVERSION_TAG variable to the latest version
73
84
checkLatestVersion () {
74
85
# Use the GitHub releases webpage to find the latest version for this project
75
86
# so we don't get rate-limited.
@@ -84,26 +95,6 @@ checkLatestVersion() {
84
95
echo " Cannot determine latest tag."
85
96
exit 1
86
97
fi
87
- eval " $1 ='$CHECKLATESTVERSION_TAG '"
88
- }
89
-
90
- get () {
91
- GET_URL=" $2 "
92
- echo " Getting $GET_URL "
93
- if [ " $DOWNLOAD_TOOL " = " curl" ]; then
94
- GET_HTTP_RESPONSE=$( curl -sL --write-out ' HTTPSTATUS:%{http_code}' " $GET_URL " )
95
- GET_HTTP_STATUS_CODE=$( echo " $GET_HTTP_RESPONSE " | tr -d ' \n' | sed -e ' s/.*HTTPSTATUS://' )
96
- GET_BODY=$( echo " $GET_HTTP_RESPONSE " | sed -e ' s/HTTPSTATUS\:.*//g' )
97
- elif [ " $DOWNLOAD_TOOL " = " wget" ]; then
98
- TMP_FILE=$( mktemp)
99
- GET_BODY=$( wget --server-response --content-on-error -q -O - " $GET_URL " 2> " $TMP_FILE " || true)
100
- GET_HTTP_STATUS_CODE=$( awk ' /^ HTTP/{print $2}' " $TMP_FILE " )
101
- fi
102
- if [ " $GET_HTTP_STATUS_CODE " != 200 ]; then
103
- echo " Request failed with HTTP status code $GET_HTTP_STATUS_CODE "
104
- fail " Body: $GET_BODY "
105
- fi
106
- eval " $1 ='$GET_BODY '"
107
98
}
108
99
109
100
getFile () {
@@ -120,44 +111,75 @@ getFile() {
120
111
121
112
downloadFile () {
122
113
if [ -z " $1 " ]; then
123
- checkLatestVersion TAG
114
+ checkLatestVersion
115
+ TAG=" $CHECKLATESTVERSION_TAG "
124
116
else
125
117
TAG=$1
126
118
fi
127
119
# arduino-lint_0.4.0-rc1_Linux_64bit.[tar.gz, zip]
120
+ APPLICATION_DIST_PREFIX=" ${PROJECT_NAME} _${TAG} _"
128
121
if [ " $OS " = " Windows" ]; then
129
- APPLICATION_DIST= " ${PROJECT_NAME} _ ${TAG} _ ${OS} _ ${ARCH} .zip"
122
+ APPLICATION_DIST_EXTENSION= " .zip"
130
123
else
131
- APPLICATION_DIST= " ${PROJECT_NAME} _ ${TAG} _ ${OS} _ ${ARCH} .tar.gz"
124
+ APPLICATION_DIST_EXTENSION= " .tar.gz"
132
125
fi
126
+ APPLICATION_DIST=" ${APPLICATION_DIST_PREFIX}${OS} _${ARCH}${APPLICATION_DIST_EXTENSION} "
133
127
134
128
# Support specifying nightly build versions (e.g., "nightly-latest") via the script argument.
135
129
case " $TAG " in
136
130
nightly* )
137
- DOWNLOAD_URL =" https://downloads.arduino.cc/${PROJECT_NAME} /nightly/${APPLICATION_DIST} "
131
+ DOWNLOAD_URL_PREFIX =" https://downloads.arduino.cc/${PROJECT_NAME} /nightly/"
138
132
;;
139
133
* )
140
- DOWNLOAD_URL =" https://downloads.arduino.cc/${PROJECT_NAME} /${APPLICATION_DIST} "
134
+ DOWNLOAD_URL_PREFIX =" https://downloads.arduino.cc/${PROJECT_NAME} /"
141
135
;;
142
136
esac
137
+ DOWNLOAD_URL=" ${DOWNLOAD_URL_PREFIX}${APPLICATION_DIST} "
143
138
144
139
INSTALLATION_TMP_FILE=" /tmp/$APPLICATION_DIST "
145
140
echo " Downloading $DOWNLOAD_URL "
146
141
httpStatusCode=$( getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE " )
147
142
if [ " $httpStatusCode " -ne 200 ]; then
148
- echo " Did not find a release for your system: $OS $ARCH "
149
- echo " Trying to find a release using the GitHub API."
150
- LATEST_RELEASE_URL=" https://api.github.com/repos/${PROJECT_OWNER} /$PROJECT_NAME /releases/tags/$TAG "
151
- echo " LATEST_RELEASE_URL=$LATEST_RELEASE_URL "
152
- get LATEST_RELEASE_JSON " $LATEST_RELEASE_URL "
153
- # || true forces this command to not catch error if grep does not find anything
154
- DOWNLOAD_URL=$( echo " $LATEST_RELEASE_JSON " | grep ' browser_' | cut -d\" -f4 | grep " $APPLICATION_DIST " ) || true
155
- if [ -z " $DOWNLOAD_URL " ]; then
156
- echo " Sorry, we dont have a dist for your system: $OS $ARCH "
157
- fail " You can request one here: https://github.com/${PROJECT_OWNER} /$PROJECT_NAME /issues"
158
- else
143
+ if [ -n " $FALLBACK_ARCH " ]; then
144
+ echo " $OS $ARCH release not currently available. Checking for alternative $OS $FALLBACK_ARCH release for your system."
145
+ FALLBACK_APPLICATION_DIST=" ${APPLICATION_DIST_PREFIX}${OS} _${FALLBACK_ARCH}${APPLICATION_DIST_EXTENSION} "
146
+ DOWNLOAD_URL=" ${DOWNLOAD_URL_PREFIX}${FALLBACK_APPLICATION_DIST} "
159
147
echo " Downloading $DOWNLOAD_URL "
160
- getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE "
148
+ httpStatusCode=$( getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE " )
149
+ fi
150
+
151
+ if [ " $httpStatusCode " -ne 200 ]; then
152
+ echo " Did not find a release for your system: $OS $ARCH "
153
+ echo " Trying to find a release using the GitHub API."
154
+
155
+ LATEST_RELEASE_URL=" https://api.github.com/repos/${PROJECT_OWNER} /$PROJECT_NAME /releases/tags/$TAG "
156
+ if [ " $DOWNLOAD_TOOL " = " curl" ]; then
157
+ HTTP_RESPONSE=$( curl -sL --write-out ' HTTPSTATUS:%{http_code}' " $LATEST_RELEASE_URL " )
158
+ HTTP_STATUS_CODE=$( echo " $HTTP_RESPONSE " | tr -d ' \n' | sed -e ' s/.*HTTPSTATUS://' )
159
+ BODY=$( echo " $HTTP_RESPONSE " | sed -e ' s/HTTPSTATUS\:.*//g' )
160
+ elif [ " $DOWNLOAD_TOOL " = " wget" ]; then
161
+ TMP_FILE=$( mktemp)
162
+ BODY=$( wget --server-response --content-on-error -q -O - " $LATEST_RELEASE_URL " 2> " $TMP_FILE " || true)
163
+ HTTP_STATUS_CODE=$( awk ' /^ HTTP/{print $2}' " $TMP_FILE " )
164
+ fi
165
+ if [ " $HTTP_STATUS_CODE " != 200 ]; then
166
+ echo " Request failed with HTTP status code $HTTP_STATUS_CODE "
167
+ fail " Body: $BODY "
168
+ fi
169
+
170
+ # || true forces this command to not catch error if grep does not find anything
171
+ DOWNLOAD_URL=$( echo " $BODY " | grep ' browser_' | cut -d\" -f4 | grep " $APPLICATION_DIST " ) || true
172
+ if [ -z " $DOWNLOAD_URL " ]; then
173
+ DOWNLOAD_URL=$( echo " $BODY " | grep ' browser_' | cut -d\" -f4 | grep " $FALLBACK_APPLICATION_DIST " ) || true
174
+ fi
175
+
176
+ if [ -z " $DOWNLOAD_URL " ]; then
177
+ echo " Sorry, we dont have a dist for your system: $OS $ARCH "
178
+ fail " You can request one here: https://github.com/${PROJECT_OWNER} /$PROJECT_NAME /issues"
179
+ else
180
+ echo " Downloading $DOWNLOAD_URL "
181
+ getFile " $DOWNLOAD_URL " " $INSTALLATION_TMP_FILE "
182
+ fi
161
183
fi
162
184
fi
163
185
}
@@ -214,6 +236,7 @@ initDestination
214
236
set -e
215
237
initArch
216
238
initOS
239
+ initFallbackArch
217
240
initDownloadTool
218
241
downloadFile " $1 "
219
242
installFile
0 commit comments