@@ -67,9 +67,9 @@ initOS() {
67
67
}
68
68
69
69
initDownloadTool () {
70
- if type " curl" > /dev/null; then
70
+ if command -v " curl" > /dev/null 2>&1 ; then
71
71
DOWNLOAD_TOOL=" curl"
72
- elif type " wget" > /dev/null; then
72
+ elif command -v " wget" > /dev/null 2>&1 ; then
73
73
DOWNLOAD_TOOL=" wget"
74
74
else
75
75
fail " You need curl or wget as download tool. Please install it first before continuing"
@@ -80,52 +80,49 @@ initDownloadTool() {
80
80
checkLatestVersion () {
81
81
# Use the GitHub releases webpage to find the latest version for this project
82
82
# so we don't get rate-limited.
83
- local tag
84
- local regex=" [0-9][A-Za-z0-9\.-]*"
85
- local latest_url=" https://github.com/${PROJECT_OWNER} /${PROJECT_NAME} /releases/latest"
83
+ CHECKLATESTVERSION_REGEX=" [0-9][A-Za-z0-9\.-]*"
84
+ CHECKLATESTVERSION_LATEST_URL=" https://github.com/${PROJECT_OWNER} /${PROJECT_NAME} /releases/latest"
86
85
if [ " $DOWNLOAD_TOOL " = " curl" ]; then
87
- tag =$( curl -SsL $latest_url | grep -o " <title>Release $regex · ${PROJECT_OWNER} /${PROJECT_NAME} " | grep -o " $regex " )
86
+ CHECKLATESTVERSION_TAG =$( curl -SsL $CHECKLATESTVERSION_LATEST_URL | grep -o " <title>Release $CHECKLATESTVERSION_REGEX · ${PROJECT_OWNER} /${PROJECT_NAME} " | grep -o " $CHECKLATESTVERSION_REGEX " )
88
87
elif [ " $DOWNLOAD_TOOL " = " wget" ]; then
89
- tag =$( wget -q -O - $latest_url | grep -o " <title>Release $regex · ${PROJECT_OWNER} /${PROJECT_NAME} " | grep -o " $regex " )
88
+ CHECKLATESTVERSION_TAG =$( wget -q -O - $CHECKLATESTVERSION_LATEST_URL | grep -o " <title>Release $CHECKLATESTVERSION_REGEX · ${PROJECT_OWNER} /${PROJECT_NAME} " | grep -o " $CHECKLATESTVERSION_REGEX " )
90
89
fi
91
- if [ " x$tag " = " x" ]; then
90
+ if [ " x$CHECKLATESTVERSION_TAG " = " x" ]; then
92
91
echo " Cannot determine latest tag."
93
92
exit 1
94
93
fi
95
- eval " $1 ='$tag '"
94
+ eval " $1 ='$CHECKLATESTVERSION_TAG '"
96
95
}
97
96
98
97
get () {
99
- local url=" $2 "
100
- local body
101
- local httpStatusCode
102
- echo " Getting $url "
98
+ GET_URL=" $2 "
99
+ echo " Getting $GET_URL "
103
100
if [ " $DOWNLOAD_TOOL " = " curl" ]; then
104
- httpResponse =$( curl -sL --write-out HTTPSTATUS:%{http_code} " $url " )
105
- httpStatusCode =$( echo $httpResponse | tr -d ' \n' | sed -e ' s/.*HTTPSTATUS://' )
106
- body =$( echo " $httpResponse " | sed -e ' s/HTTPSTATUS\:.*//g' )
101
+ GET_HTTP_RESPONSE =$( curl -sL --write-out ' HTTPSTATUS:%{http_code}' " $GET_URL " )
102
+ GET_HTTP_STATUS_CODE =$( echo $GET_HTTP_RESPONSE | tr -d ' \n' | sed -e ' s/.*HTTPSTATUS://' )
103
+ GET_BODY =$( echo " $GET_HTTP_RESPONSE " | sed -e ' s/HTTPSTATUS\:.*//g' )
107
104
elif [ " $DOWNLOAD_TOOL " = " wget" ]; then
108
- tmpFile =$( mktemp)
109
- body =$( wget --server-response --content-on-error -q -O - " $url " 2> $tmpFile || true)
110
- httpStatusCode =$( cat $tmpFile | awk ' /^ HTTP/{print $2}' )
105
+ TMP_FILE =$( mktemp)
106
+ GET_BODY =$( wget --server-response --content-on-error -q -O - " $GET_URL " 2> $TMP_FILE || true)
107
+ GET_HTTP_STATUS_CODE =$( cat $TMP_FILE | awk ' /^ HTTP/{print $2}' )
111
108
fi
112
- if [ " $httpStatusCode " != 200 ]; then
113
- echo " Request failed with HTTP status code $httpStatusCode "
114
- fail " Body: $body "
109
+ if [ " $GET_HTTP_STATUS_CODE " != 200 ]; then
110
+ echo " Request failed with HTTP status code $GET_HTTP_STATUS_CODE "
111
+ fail " Body: $GET_BODY "
115
112
fi
116
- eval " $1 ='$body '"
113
+ eval " $1 ='$GET_BODY '"
117
114
}
118
115
119
116
getFile () {
120
- local url =" $1 "
121
- local filePath =" $2 "
117
+ GETFILE_URL =" $1 "
118
+ GETFILE_FILE_PATH =" $2 "
122
119
if [ " $DOWNLOAD_TOOL " = " curl" ]; then
123
- httpStatusCode =$( curl -s -w ' %{http_code}' -L " $url " -o " $filePath " )
120
+ GETFILE_HTTP_STATUS_CODE =$( curl -s -w ' %{http_code}' -L " $GETFILE_URL " -o " $GETFILE_FILE_PATH " )
124
121
elif [ " $DOWNLOAD_TOOL " = " wget" ]; then
125
- body =$( wget --server-response --content-on-error -q -O " $filePath " " $url " )
126
- httpStatusCode =$( cat $tmpFile | awk ' /^ HTTP/{print $2}' )
122
+ GETFILE_BODY =$( wget --server-response --content-on-error -q -O " $GETFILE_FILE_PATH " " $GETFILE_URL " )
123
+ GETFILE_HTTP_STATUS_CODE =$( cat $TMP_FILE | awk ' /^ HTTP/{print $2}' )
127
124
fi
128
- echo " $httpStatusCode "
125
+ echo " $GETFILE_HTTP_STATUS_CODE "
129
126
}
130
127
131
128
downloadFile () {
@@ -177,11 +174,11 @@ installFile() {
177
174
}
178
175
179
176
bye () {
180
- result =$?
181
- if [ " $result " != " 0" ]; then
177
+ BYE_RESULT =$?
178
+ if [ " $BYE_RESULT " != " 0" ]; then
182
179
echo " Failed to install $PROJECT_NAME "
183
180
fi
184
- exit $result
181
+ exit $BYE_RESULT
185
182
}
186
183
187
184
testVersion () {
0 commit comments