forked from npsg02/safe-clean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·82 lines (67 loc) · 1.7 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·82 lines (67 loc) · 1.7 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
#!/usr/bin/env bash
set -euo pipefail
REPO="${REPO:-pnstack/safe-clean}"
VERSION="${VERSION:-latest}"
BIN_NAME="${BIN_NAME:-safe-clean}"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
detect_asset() {
local os
local arch
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux)
case "$arch" in
x86_64 | amd64)
echo "safe-clean-linux-x86_64.tar.gz"
;;
*)
echo "Unsupported Linux arch: $arch" >&2
exit 1
;;
esac
;;
Darwin)
case "$arch" in
x86_64 | amd64)
echo "safe-clean-macos-x86_64.tar.gz"
;;
arm64 | aarch64)
echo "safe-clean-macos-aarch64.tar.gz"
;;
*)
echo "Unsupported macOS arch: $arch" >&2
exit 1
;;
esac
;;
*)
echo "Unsupported OS: $os" >&2
exit 1
;;
esac
}
ASSET="$(detect_asset)"
if [ "$VERSION" = "latest" ]; then
URL="https://github.com/${REPO}/releases/latest/download/${ASSET}"
else
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}"
fi
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
mkdir -p "$INSTALL_DIR"
echo "Installing ${BIN_NAME} from ${URL}"
curl -fsSL "$URL" -o "$TMP_DIR/$ASSET"
tar -xzf "$TMP_DIR/$ASSET" -C "$TMP_DIR"
if [ ! -f "$TMP_DIR/$BIN_NAME" ]; then
echo "Binary not found in archive: $BIN_NAME" >&2
exit 1
fi
install -m 755 "$TMP_DIR/$BIN_NAME" "$INSTALL_DIR/$BIN_NAME"
echo "Installed: $INSTALL_DIR/$BIN_NAME"
if ! command -v "$BIN_NAME" >/dev/null 2>&1; then
echo ""
echo "Add this to your shell profile:"
echo "export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
"$INSTALL_DIR/$BIN_NAME" --help >/dev/null || true