Fallback to wget in install script if curl isn't available(#1913)

This commit is contained in:
Trevor Gross 2024-05-20 20:20:24 -04:00 committed by GitHub
parent d3492e6ffe
commit 77f343e7b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,6 +51,17 @@ need() {
fi fi
} }
download() {
url="$1"
output="$2"
if command -v curl > /dev/null; then
curl --proto =https --tlsv1.2 -sSfL "$url" "-o$output"
else
wget --https-only --secure-protocol=TLSv1_2 --quiet "$url" "-O$output"
fi
}
force=false force=false
while test $# -gt 0; do while test $# -gt 0; do
case $1 in case $1 in
@ -74,12 +85,18 @@ while test $# -gt 0; do
shift shift
;; ;;
*) *)
say "error: unrecognized argument '$1'. Usage:"
help
exit 1
;; ;;
esac esac
shift shift
done done
need curl command -v curl > /dev/null 2>&1 ||
command -v wget > /dev/null 2>&1 ||
err "need wget or curl (command not found)"
need install need install
need mkdir need mkdir
need mktemp need mktemp
@ -100,8 +117,7 @@ fi
if [ -z "${tag-}" ]; then if [ -z "${tag-}" ]; then
tag=$( tag=$(
curl --proto =https --tlsv1.2 -sSf \ download https://api.github.com/repos/casey/just/releases/latest - |
https://api.github.com/repos/casey/just/releases/latest |
grep tag_name | grep tag_name |
cut -d'"' -f4 cut -d'"' -f4
) )
@ -145,10 +161,10 @@ say "Archive: $archive"
td=$(mktemp -d || mktemp -d -t tmp) td=$(mktemp -d || mktemp -d -t tmp)
if [ "$extension" = "zip" ]; then if [ "$extension" = "zip" ]; then
curl --proto =https --tlsv1.2 -sSfL "$archive" > "$td/just.zip" download "$archive" "$td/just.zip"
unzip -d "$td" "$td/just.zip" unzip -d "$td" "$td/just.zip"
else else
curl --proto =https --tlsv1.2 -sSfL "$archive" | tar -C "$td" -xz download "$archive" - | tar -C "$td" -xz
fi fi
if [ -e "$dest/just" ] && [ "$force" = false ]; then if [ -e "$dest/just" ] && [ "$force" = false ]; then