Skip to content

Commit 8045c2c

Browse files
authored
Allow redirect for curl and wget (#28)
1 parent ad18e39 commit 8045c2c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

example/hugow

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,18 @@ fi
6363
DOWNLOAD_COMMAND=""
6464
DOWNLOAD_OUTPUT=""
6565
DOWNLOAD_SILENT=""
66+
DOWNLOAD_REDIRECT=""
6667

6768
if command -v wget > /dev/null; then
6869
DOWNLOAD_COMMAND="wget"
6970
DOWNLOAD_OUTPUT="-O"
7071
DOWNLOAD_SILENT="-q"
72+
DOWNLOAD_REDIRECT=""
7173
elif command -v curl > /dev/null; then
7274
DOWNLOAD_COMMAND="curl"
7375
DOWNLOAD_OUTPUT="-o"
7476
DOWNLOAD_SILENT="-s"
77+
DOWNLOAD_REDIRECT="-L"
7578
else
7679
echo "Error: Unable to find 'wget' or 'curl' command."
7780
exit 1
@@ -190,7 +193,7 @@ download_version() {
190193

191194
if [ -n "$versionToDownload" ]; then
192195
if [ "$versionToDownload" = "LATEST" ]; then
193-
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
196+
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
194197
versionToDownload=`parse_json "$latest_release" "tag_name"`
195198
fi
196199

@@ -208,8 +211,8 @@ download_version() {
208211
local checksumName="checksum.txt"
209212
local checksumPath="$BASE_DIR/.hugo/${checksumName}"
210213

211-
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_OUTPUT "$tarballPath" "$binaryUrl" &
212-
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_OUTPUT "$checksumPath" "$checksumUrl" &
214+
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT $DOWNLOAD_OUTPUT "$tarballPath" "$binaryUrl" &
215+
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT $DOWNLOAD_OUTPUT "$checksumPath" "$checksumUrl" &
213216
wait
214217

215218
if [ -s "$tarballPath" -a -s "$checksumPath" ]; then
@@ -256,7 +259,7 @@ download_version() {
256259
# ----------------------------------------------------------------------------
257260
if [ "$upgrade" = true ]; then
258261
printf "downloading hugow binary ... "
259-
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_OUTPUT "hugow" "https://raw.githubusercontent.com/khos2ow/hugo-wrapper/master/hugow" &
262+
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT $DOWNLOAD_OUTPUT "hugow" "https://raw.githubusercontent.com/khos2ow/hugo-wrapper/master/hugow" &
260263
wait
261264
printf "[done]\n"
262265
chmod +x hugow
@@ -278,7 +281,7 @@ if [ -r "$BASE_DIR/.hugo/hugo" ]; then
278281
echo "hugo binary version $get_version already exists"
279282
fi
280283
elif [ $get_latest = true ]; then
281-
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
284+
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
282285
latest_version=`parse_json "$latest_release" "tag_name" | sed -ne 's/[^0-9]*\(\([0-9]*\.\)\{0,4\}[0-9]*[^.]\).*/\1/p'`
283286

284287
if [ "$latest_version" != "$current_binary_version" ]; then

hugow

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,18 @@ fi
6363
DOWNLOAD_COMMAND=""
6464
DOWNLOAD_OUTPUT=""
6565
DOWNLOAD_SILENT=""
66+
DOWNLOAD_REDIRECT=""
6667

6768
if command -v wget > /dev/null; then
6869
DOWNLOAD_COMMAND="wget"
6970
DOWNLOAD_OUTPUT="-O"
7071
DOWNLOAD_SILENT="-q"
72+
DOWNLOAD_REDIRECT=""
7173
elif command -v curl > /dev/null; then
7274
DOWNLOAD_COMMAND="curl"
7375
DOWNLOAD_OUTPUT="-o"
7476
DOWNLOAD_SILENT="-s"
77+
DOWNLOAD_REDIRECT="-L"
7578
else
7679
echo "Error: Unable to find 'wget' or 'curl' command."
7780
exit 1
@@ -190,7 +193,7 @@ download_version() {
190193

191194
if [ -n "$versionToDownload" ]; then
192195
if [ "$versionToDownload" = "LATEST" ]; then
193-
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
196+
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
194197
versionToDownload=`parse_json "$latest_release" "tag_name"`
195198
fi
196199

@@ -208,8 +211,8 @@ download_version() {
208211
local checksumName="checksum.txt"
209212
local checksumPath="$BASE_DIR/.hugo/${checksumName}"
210213

211-
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_OUTPUT "$tarballPath" "$binaryUrl" &
212-
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_OUTPUT "$checksumPath" "$checksumUrl" &
214+
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT $DOWNLOAD_OUTPUT "$tarballPath" "$binaryUrl" &
215+
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT $DOWNLOAD_OUTPUT "$checksumPath" "$checksumUrl" &
213216
wait
214217

215218
if [ -s "$tarballPath" -a -s "$checksumPath" ]; then
@@ -256,7 +259,7 @@ download_version() {
256259
# ----------------------------------------------------------------------------
257260
if [ "$upgrade" = true ]; then
258261
printf "downloading hugow binary ... "
259-
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_OUTPUT "hugow" "https://raw.githubusercontent.com/khos2ow/hugo-wrapper/master/hugow" &
262+
$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT $DOWNLOAD_OUTPUT "hugow" "https://raw.githubusercontent.com/khos2ow/hugo-wrapper/master/hugow" &
260263
wait
261264
printf "[done]\n"
262265
chmod +x hugow
@@ -278,7 +281,7 @@ if [ -r "$BASE_DIR/.hugo/hugo" ]; then
278281
echo "hugo binary version $get_version already exists"
279282
fi
280283
elif [ $get_latest = true ]; then
281-
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
284+
latest_release=`$DOWNLOAD_COMMAND $DOWNLOAD_SILENT $DOWNLOAD_REDIRECT ${DOWNLOAD_OUTPUT}- https://api.github.com/repos/gohugoio/hugo/releases/latest`
282285
latest_version=`parse_json "$latest_release" "tag_name" | sed -ne 's/[^0-9]*\(\([0-9]*\.\)\{0,4\}[0-9]*[^.]\).*/\1/p'`
283286

284287
if [ "$latest_version" != "$current_binary_version" ]; then

0 commit comments

Comments
 (0)