dotconf/private_dot_config/private_mgmt/fns/bin_from.bash

36 lines
1 KiB
Bash
Raw Normal View History

2026-03-25 10:50:18 -05:00
# shellcheck shell=bash
bin_from() {
name="$1"
url="$2"
flag="$3"
if [[ -z "$name" || -z "$url" ]]; then
diag "$(red "error: missing name ($name) or url ($url)!")"
exit 1
fi
if [[ "$url" == *.tar.gz || "$url" == *.tgz ]]; then
dir=$(mktemp -d)
if curl -sSL "$url" | tar -C "$dir" -xz 2>&1 | grep -q 'not in gzip format'; then
diag "$(red "error: file from $url not in gzip format")"
exit 1
fi
file=$(find "$dir" -type f -name "$name")
elif [[ "$url" == *.tar.xz ]]; then
dir=$(mktemp -d)
curl -sSL "$url" | tar -C "$dir" -xJ
file=$(find "$dir" -type f -name "$name")
elif [[ "$url" == *.zip ]]; then
zip=$(mktemp --suffix=.zip)
dir=$(mktemp -d)
curl -sSL "$url" > "$zip"
unzip -qq "$zip" -d "$dir"
file=$(find "$dir" -type f -name "$name")
else
file="$(mktemp)"
curl -sSLo "$file" "$url" || diag "$(red "error from url [$url]")"
fi
install_bin "$name" "$file" "$url" "$flag"
}