@@ -67,9 +67,9 @@ initOS() {
6767}
6868
6969initDownloadTool () {
70- if type " curl" > /dev/null; then
70+ if command -v " curl" > /dev/null 2>&1 ; then
7171 DOWNLOAD_TOOL=" curl"
72- elif type " wget" > /dev/null; then
72+ elif command -v " wget" > /dev/null 2>&1 ; then
7373 DOWNLOAD_TOOL=" wget"
7474 else
7575 fail " You need curl or wget as download tool. Please install it first before continuing"
@@ -80,52 +80,49 @@ initDownloadTool() {
8080checkLatestVersion () {
8181 # Use the GitHub releases webpage to find the latest version for this project
8282 # 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"
8685 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 " )
8887 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 " )
9089 fi
91- if [ " x$tag " = " x" ]; then
90+ if [ " x$CHECKLATESTVERSION_TAG " = " x" ]; then
9291 echo " Cannot determine latest tag."
9392 exit 1
9493 fi
95- eval " $1 ='$tag '"
94+ eval " $1 ='$CHECKLATESTVERSION_TAG '"
9695}
9796
9897get () {
99- local url=" $2 "
100- local body
101- local httpStatusCode
102- echo " Getting $url "
98+ GET_URL=" $2 "
99+ echo " Getting $GET_URL "
103100 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' )
107104 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}' )
111108 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 "
115112 fi
116- eval " $1 ='$body '"
113+ eval " $1 ='$GET_BODY '"
117114}
118115
119116getFile () {
120- local url =" $1 "
121- local filePath =" $2 "
117+ GETFILE_URL =" $1 "
118+ GETFILE_FILE_PATH =" $2 "
122119 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 " )
124121 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}' )
127124 fi
128- echo " $httpStatusCode "
125+ echo " $GETFILE_HTTP_STATUS_CODE "
129126}
130127
131128downloadFile () {
@@ -177,11 +174,11 @@ installFile() {
177174}
178175
179176bye () {
180- result =$?
181- if [ " $result " != " 0" ]; then
177+ BYE_RESULT =$?
178+ if [ " $BYE_RESULT " != " 0" ]; then
182179 echo " Failed to install $PROJECT_NAME "
183180 fi
184- exit $result
181+ exit $BYE_RESULT
185182}
186183
187184testVersion () {
0 commit comments