-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·143 lines (120 loc) · 3.95 KB
/
install.sh
File metadata and controls
executable file
·143 lines (120 loc) · 3.95 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
# Status Panel installer
# Usage: curl -sSfL https://github.com/trydirect/status/master/install.sh | sh
#
# Environment variables:
# VERSION - Pin a specific version (e.g. "v0.1.4"). Default: latest release.
# INSTALL_DIR - Installation directory. Default: /usr/local/bin
set -eu
REPO="trydirect/status"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
main() {
detect_platform
resolve_version
download_binary
verify_checksum
install_binary
echo ""
echo "status ${VERSION} installed to ${INSTALL_DIR}/status"
echo "Run 'status --help' to get started."
}
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) ;;
*)
echo "Error: unsupported OS: $OS (only Linux is supported)" >&2
exit 1
;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
*)
echo "Error: unsupported architecture: $ARCH (only x86_64 is supported)" >&2
exit 1
;;
esac
ASSET_NAME="status-linux-${ARCH}-musl"
}
resolve_version() {
if [ -n "${VERSION:-}" ]; then
# Ensure version starts with 'v'
case "$VERSION" in
v*) ;;
*) VERSION="v${VERSION}" ;;
esac
return
fi
echo "Fetching latest release..."
VERSION=$(
curl -sSf "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/'
)
if [ -z "$VERSION" ]; then
echo "Error: could not determine latest version" >&2
exit 1
fi
echo "Latest version: ${VERSION}"
}
download_binary() {
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET_NAME}"
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET_NAME}.sha256"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
echo "Downloading ${ASSET_NAME} ${VERSION}..."
curl -sSfL -o "${TMPDIR}/${ASSET_NAME}" "$DOWNLOAD_URL"
echo "Downloading checksum..."
curl -sSfL -o "${TMPDIR}/${ASSET_NAME}.sha256" "$CHECKSUM_URL" || {
echo "Warning: checksum file not available, skipping verification" >&2
SKIP_CHECKSUM=1
}
}
verify_checksum() {
if [ "${SKIP_CHECKSUM:-0}" = "1" ]; then
return
fi
echo "Verifying SHA256 checksum..."
cd "$TMPDIR"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "${ASSET_NAME}.sha256"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 -c "${ASSET_NAME}.sha256"
else
echo "Warning: no sha256sum or shasum found, skipping verification" >&2
fi
cd - >/dev/null
}
install_binary() {
chmod +x "${TMPDIR}/${ASSET_NAME}"
# Ensure INSTALL_DIR exists
if [ ! -d "$INSTALL_DIR" ]; then
if mkdir -p "$INSTALL_DIR" 2>/dev/null; then
:
else
if command -v sudo >/dev/null 2>&1; then
echo "Creating installation directory ${INSTALL_DIR} with sudo..."
sudo mkdir -p "$INSTALL_DIR"
else
echo "Error: installation directory ${INSTALL_DIR} does not exist and could not be created without sudo." >&2
echo "Please create it manually or set INSTALL_DIR to a writable directory you own." >&2
exit 1
fi
fi
fi
# Use sudo if we can't write to INSTALL_DIR
if [ -w "$INSTALL_DIR" ]; then
mv "${TMPDIR}/${ASSET_NAME}" "${INSTALL_DIR}/status"
else
if command -v sudo >/dev/null 2>&1; then
echo "Elevated permissions required to install to ${INSTALL_DIR}"
sudo mv "${TMPDIR}/${ASSET_NAME}" "${INSTALL_DIR}/status"
else
echo "Error: cannot write to ${INSTALL_DIR} and sudo is not available." >&2
echo "Please install manually or choose a different INSTALL_DIR." >&2
exit 1
fi
fi
}
main