Skip to content

Commit

Permalink
fetch: if failure, tell us what url failed
Browse files Browse the repository at this point in the history
setup-rust, setup-util-1password: use fetch
  • Loading branch information
balupton committed Sep 1, 2023
1 parent 235e520 commit a35d4be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions commands/fetch
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ function fetch() (
# =====================================
# Helpers

function log_failure {
local status="$?"
echo-style --error="Failed to fetch the URL:" ' ' --code="$option_url" >/dev/stderr
return "$status"
}

# -I, --head Show document info only
# -m, --max-time <seconds> Maximum time allowed for the transfer
# -o, --output <file> Write to file instead of stdout
Expand All @@ -78,7 +84,7 @@ function fetch() (
--write-out '%{http_code}'
)
setup-util-curl --quiet
curl "${args[@]}" --location "$option_url"
curl "${args[@]}" --location "$option_url" || log_failure
}

function fetch_ok {
Expand All @@ -90,12 +96,12 @@ function fetch() (
function fetch_contents {
if command-exists curl; then
# use echo-wait to fix [curl: (23) Failure writing output to destination] when piping to ripgrep
curl -fsSL "$option_url" | echo-wait
curl -fsSL "$option_url" | echo-wait || log_failure
elif command-exists wget; then
wget "$option_url" -O -
wget "$option_url" -O - || log_failure
else
get-installer --first-success --invoke --quiet -- curl wget
fetch "$option_url"
fetch_contents
fi
}

Expand Down
2 changes: 1 addition & 1 deletion commands/setup-rust
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function setup_rust() (
# https://rust-lang.github.io/rustup/installation/other.html
# rustup: Unable to run interactively. Run with -y to accept defaults, --help for additional options
echo-segment --h2="Install rustup"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --quiet --no-modify-path -y
fetch 'https://sh.rustup.rs' | sh -s -- --quiet --no-modify-path -y
echo-segment --g2="Install rustup"
fi

Expand Down
8 changes: 4 additions & 4 deletions commands/setup-util-1password
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ function setup_util_1password() (
function do_apt_keys {
sudo-helper --reason="$sudo_reason" \
-- mkdir -p /etc/debsig/policies/AC2D62742012EA22 /usr/share/debsig/keyrings/AC2D62742012EA22
curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | sudo-helper --reason="$sudo_reason" \
fetch 'https://downloads.1password.com/linux/debian/debsig/1password.pol' | sudo-helper --reason="$sudo_reason" \
-- tee /etc/debsig/policies/AC2D62742012EA22/1password.pol
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo-helper --reason="$sudo_reason" \
fetch 'https://downloads.1password.com/linux/keys/1password.asc' | sudo-helper --reason="$sudo_reason" \
-- gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg
}
function do_rpm_keys {
sudo-helper --reason="$sudo_reason" \
-- rpm --import https://downloads.1password.com/linux/keys/1password.asc
-- rpm --import 'https://downloads.1password.com/linux/keys/1password.asc'
cat <<-EOF | sudo-helper --reason="$sudo_reason" -- tee /etc/yum.repos.d/1password.repo
[1password]
name=1Password Beta Channel
Expand All @@ -59,7 +59,7 @@ function setup_util_1password() (
EOF
}
function do_gpg_keys {
curl -sS https://downloads.1password.com/linux/keys/1password.asc | gpg --import
fetch 'https://downloads.1password.com/linux/keys/1password.asc' | gpg --import
}
function do_build {
# linux 1password expects it to be inside [/opt/1Password/]
Expand Down

0 comments on commit a35d4be

Please sign in to comment.