-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·104 lines (84 loc) · 2.65 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·104 lines (84 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env sh
set -eu
REPO="${SETTUPPER_REPO:-devbaraus/settupper}"
VERSION="${SETTUPPER_VERSION:-}"
INSTALL_ROOT="${SETTUPPER_INSTALL_ROOT:-$HOME/.local}"
BIN_DIR="$INSTALL_ROOT/bin"
BINARY_NAME="settupper"
err() {
echo "error: $*" >&2
exit 1
}
need_cmd() {
command -v "$1" >/dev/null 2>&1 || err "$1 not found."
}
tmpdir=""
cleanup() {
if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then
rm -rf "$tmpdir"
fi
}
trap cleanup EXIT INT TERM
detect_platform() {
os="$(uname -s 2>/dev/null || true)"
arch="$(uname -m 2>/dev/null || true)"
case "$os" in
Linux) os_name="linux" ;;
Darwin) os_name="macos" ;;
*) err "unsupported operating system: ${os:-unknown}" ;;
esac
case "$arch" in
x86_64|amd64) arch_name="x86_64" ;;
arm64|aarch64) arch_name="aarch64" ;;
*) err "unsupported architecture: ${arch:-unknown}" ;;
esac
ARCHIVE="settupper-${os_name}-${arch_name}.tar.gz"
}
download() {
url="$1"
output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fL --retry 3 --proto '=https' --tlsv1.2 -o "$output" "$url"
elif command -v wget >/dev/null 2>&1; then
wget -O "$output" "$url"
else
err "curl or wget not found."
fi
}
latest_tag() {
if command -v curl >/dev/null 2>&1; then
latest_url="$(curl -fsIL -o /dev/null -w '%{url_effective}' "https://github.com/$REPO/releases/latest")"
elif command -v wget >/dev/null 2>&1; then
latest_url="$(wget --server-response --max-redirect=10 --spider "https://github.com/$REPO/releases/latest" 2>&1 | awk '/^ Location: / { url=$2 } END { print url }' | tr -d '\r')"
else
err "curl or wget not found."
fi
tag="${latest_url##*/}"
[ -n "$tag" ] && [ "$tag" != "latest" ] || err "could not determine the latest release at https://github.com/$REPO"
printf '%s\n' "$tag"
}
detect_platform
need_cmd tar
if [ -z "$VERSION" ]; then
VERSION="$(latest_tag)"
fi
tmpdir="$(mktemp -d)"
archive_path="$tmpdir/$ARCHIVE"
download_url="https://github.com/$REPO/releases/download/$VERSION/$ARCHIVE"
echo "Downloading settupper $VERSION ($ARCHIVE)..."
download "$download_url" "$archive_path"
tar -xzf "$archive_path" -C "$tmpdir"
[ -f "$tmpdir/$BINARY_NAME" ] || err "binary $BINARY_NAME not found in archive $ARCHIVE"
mkdir -p "$BIN_DIR"
install -m 0755 "$tmpdir/$BINARY_NAME" "$BIN_DIR/$BINARY_NAME"
echo
echo "Settupper installed at: $BIN_DIR/$BINARY_NAME"
case ":$PATH:" in
*":$BIN_DIR:"*)
echo "Run with: settupper"
;;
*)
echo "Add it to PATH to run with just 'settupper':"
echo " export PATH=\"$BIN_DIR:\$PATH\""
;;
esac