Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch_configlet: retry if curl request fails #424

Merged
merged 3 commits into from
Mar 12, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions bin/fetch_configlet
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,31 @@ esac
VERSION="$(get_version)"
URL="${RELEASES}/download/${VERSION}/configlet-${OS}-${ARCH}.${EXT}"

fetch_archive() {
local file_info=$1
for delay in {0..4}; do
sleep "$delay"
curl --silent --location "$URL" -o "$localfile"
if file "$localfile" 2>&1 | grep -q "$file_info"; then
# fetched successfully
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just rely on curl's exit status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errexit is on, so the script will die on non-zero.
Anyway the problem is that a small text file is fetched, not the (g)zip content we're expecting.

return 0
fi
done
echo "Cannot fetch $URL" >&2
return 1
}

case "$EXT" in
(*zip)
curl -s --location "$URL" -o bin/latest-configlet.zip
unzip bin/latest-configlet.zip -d bin/
rm bin/latest-configlet.zip
localfile=bin/latest-configlet.zip
fetch_archive "Zip archive data"
unzip "$localfile" -d bin/
;;
(*)
localfile=bin/latest-configlet.tgz
fetch_archive "gzip compressed data"
tar xzf "$localfile" -C bin/
;;
(*) curl -s --location "$URL" | tar xz -C bin/ ;;
esac

rm -f "$localfile"