Skip to content

Commit ea1c4aa

Browse files
committed
test install script
1 parent 6a0d6ac commit ea1c4aa

2 files changed

Lines changed: 83 additions & 1 deletion

File tree

.github/workflows/action-self-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
os:
2727
- ubuntu-latest
2828
- macos-latest
29-
- windows-latest
29+
# - windows-latest
3030

3131
steps:
3232
- name: Checkout

install.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
REPO="${REPO:-pnstack/safe-clean}"
5+
VERSION="${VERSION:-latest}"
6+
BIN_NAME="${BIN_NAME:-safe-clean}"
7+
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
8+
9+
detect_asset() {
10+
local os
11+
local arch
12+
13+
os="$(uname -s)"
14+
arch="$(uname -m)"
15+
16+
case "$os" in
17+
Linux)
18+
case "$arch" in
19+
x86_64 | amd64)
20+
echo "safe-clean-linux-x86_64.tar.gz"
21+
;;
22+
*)
23+
echo "Unsupported Linux arch: $arch" >&2
24+
exit 1
25+
;;
26+
esac
27+
;;
28+
Darwin)
29+
case "$arch" in
30+
x86_64 | amd64)
31+
echo "safe-clean-macos-x86_64.tar.gz"
32+
;;
33+
arm64 | aarch64)
34+
echo "safe-clean-macos-aarch64.tar.gz"
35+
;;
36+
*)
37+
echo "Unsupported macOS arch: $arch" >&2
38+
exit 1
39+
;;
40+
esac
41+
;;
42+
*)
43+
echo "Unsupported OS: $os" >&2
44+
exit 1
45+
;;
46+
esac
47+
}
48+
49+
ASSET="$(detect_asset)"
50+
51+
if [ "$VERSION" = "latest" ]; then
52+
URL="https://github.com/${REPO}/releases/latest/download/${ASSET}"
53+
else
54+
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}"
55+
fi
56+
57+
TMP_DIR="$(mktemp -d)"
58+
trap 'rm -rf "$TMP_DIR"' EXIT
59+
60+
mkdir -p "$INSTALL_DIR"
61+
62+
echo "Installing ${BIN_NAME} from ${URL}"
63+
curl -fsSL "$URL" -o "$TMP_DIR/$ASSET"
64+
65+
tar -xzf "$TMP_DIR/$ASSET" -C "$TMP_DIR"
66+
67+
if [ ! -f "$TMP_DIR/$BIN_NAME" ]; then
68+
echo "Binary not found in archive: $BIN_NAME" >&2
69+
exit 1
70+
fi
71+
72+
install -m 755 "$TMP_DIR/$BIN_NAME" "$INSTALL_DIR/$BIN_NAME"
73+
74+
echo "Installed: $INSTALL_DIR/$BIN_NAME"
75+
76+
if ! command -v "$BIN_NAME" >/dev/null 2>&1; then
77+
echo ""
78+
echo "Add this to your shell profile:"
79+
echo "export PATH=\"\$HOME/.local/bin:\$PATH\""
80+
fi
81+
82+
"$INSTALL_DIR/$BIN_NAME" --help >/dev/null || true

0 commit comments

Comments
 (0)