-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·109 lines (94 loc) · 3.36 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·109 lines (94 loc) · 3.36 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
105
106
107
108
109
#!/usr/bin/env bash
#
# Piper installer — downloads a prebuilt piper binary into your PATH.
# No Node, no Go, no compiler required.
#
# curl -fsSL https://raw.githubusercontent.com/djalmaaraujo/piper/main/install.sh | bash
#
# Env overrides:
# PIPER_INSTALL_DIR target dir (default: /usr/local/bin, falls back to ~/.local/bin)
# PIPER_VERSION release tag to install (default: latest)
set -euo pipefail
REPO="djalmaaraujo/piper"
VERSION="${PIPER_VERSION:-latest}"
# --- detect platform ---------------------------------------------------------
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Darwin) goos="darwin" ;;
Linux) goos="linux" ;;
*) echo "Error: unsupported OS '$os'. On Windows, download the .zip from the Releases page." >&2; exit 1 ;;
esac
case "$arch" in
x86_64|amd64) goarch="amd64" ;;
arm64|aarch64) goarch="arm64" ;;
*) echo "Error: unsupported architecture '$arch'." >&2; exit 1 ;;
esac
ASSET="piper_${goos}_${goarch}.tar.gz"
if [ "$VERSION" = "latest" ]; then
BASE="https://github.com/${REPO}/releases/latest/download"
else
BASE="https://github.com/${REPO}/releases/download/${VERSION}"
fi
URL="${BASE}/${ASSET}"
CHECKSUMS_URL="${BASE}/checksums.txt"
# --- choose a writable install dir -------------------------------------------
choose_dir() {
if [ -n "${PIPER_INSTALL_DIR:-}" ]; then echo "$PIPER_INSTALL_DIR"; return; fi
if [ -w "/usr/local/bin" ]; then echo "/usr/local/bin"; return; fi
echo "$HOME/.local/bin"
}
INSTALL_DIR="$(choose_dir)"
mkdir -p "$INSTALL_DIR"
# --- download + extract ------------------------------------------------------
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
fetch() { # fetch <url> <dest>
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$1" -o "$2"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$2" "$1"
else
echo "Error: need curl or wget." >&2; exit 1
fi
}
echo "Downloading ${ASSET} (${VERSION})..."
fetch "$URL" "$tmp/$ASSET"
# --- verify checksum ---------------------------------------------------------
# The release ships a checksums.txt; verify the archive before trusting it.
if fetch "$CHECKSUMS_URL" "$tmp/checksums.txt" 2>/dev/null; then
expected="$(grep " ${ASSET}\$" "$tmp/checksums.txt" | awk '{print $1}')"
if [ -z "$expected" ]; then
echo "Error: ${ASSET} not found in checksums.txt." >&2; exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual="$(sha256sum "$tmp/$ASSET" | awk '{print $1}')"
elif command -v shasum >/dev/null 2>&1; then
actual="$(shasum -a 256 "$tmp/$ASSET" | awk '{print $1}')"
else
echo "Error: need sha256sum or shasum to verify the download." >&2; exit 1
fi
if [ "$expected" != "$actual" ]; then
echo "Error: checksum mismatch for ${ASSET}." >&2
echo " expected $expected" >&2
echo " actual $actual" >&2
exit 1
fi
echo "✓ Checksum verified"
else
echo "Error: could not download checksums.txt to verify the release." >&2; exit 1
fi
tar -xzf "$tmp/$ASSET" -C "$tmp"
install -m 0755 "$tmp/piper" "$INSTALL_DIR/piper"
echo "✓ Installed piper to ${INSTALL_DIR}/piper"
# --- PATH hint ---------------------------------------------------------------
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "⚠ ${INSTALL_DIR} is not on your PATH. Add to your shell profile:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
echo ""
echo "Try it: piper echo hello"