-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·123 lines (104 loc) · 3.33 KB
/
install.sh
File metadata and controls
executable file
·123 lines (104 loc) · 3.33 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
#!/bin/sh
set -e
REPO="chinmaymk/acli"
BINARY_NAME="acli"
INSTALL_DIR="/usr/local/bin"
# Allow overriding the install directory
if [ -n "$ACLI_INSTALL_DIR" ]; then
INSTALL_DIR="$ACLI_INSTALL_DIR"
fi
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*)
echo "Unsupported operating system: $(uname -s)" >&2
exit 1
;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*)
echo "Unsupported architecture: $(uname -m)" >&2
exit 1
;;
esac
}
get_latest_version() {
if command -v curl >/dev/null 2>&1; then
curl -sI "https://github.com/${REPO}/releases/latest" | grep -i "^location:" | sed 's#.*/tag/##' | tr -d '\r\n'
elif command -v wget >/dev/null 2>&1; then
wget --spider --max-redirect=0 "https://github.com/${REPO}/releases/latest" 2>&1 | grep "Location:" | sed 's#.*/tag/##' | tr -d '\r\n'
else
echo "Error: curl or wget is required" >&2
exit 1
fi
}
download() {
url="$1"
output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$output" "$url"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$output" "$url"
fi
}
main() {
os="$(detect_os)"
arch="$(detect_arch)"
echo "Detected platform: ${os}/${arch}"
# Determine version
if [ -n "$ACLI_VERSION" ]; then
version="$ACLI_VERSION"
else
echo "Fetching latest version..."
version="$(get_latest_version)"
if [ -z "$version" ]; then
echo "Error: could not determine latest version. Set ACLI_VERSION to install a specific version." >&2
exit 1
fi
fi
echo "Installing acli ${version}..."
# Strip leading 'v' from version for archive name (goreleaser uses version without 'v' prefix)
version_num="${version#v}"
# Build download URL — goreleaser produces tar.gz (linux/mac) and zip (windows)
if [ "$os" = "windows" ]; then
filename="${BINARY_NAME}_${version_num}_${os}_${arch}.zip"
else
filename="${BINARY_NAME}_${version_num}_${os}_${arch}.tar.gz"
fi
url="https://github.com/${REPO}/releases/download/${version}/${filename}"
echo "Downloading ${url}..."
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
download "$url" "${tmpdir}/${filename}"
# Extract the binary from the archive
if [ "$os" = "windows" ]; then
if command -v unzip >/dev/null 2>&1; then
unzip -q "${tmpdir}/${filename}" -d "${tmpdir}"
else
echo "Error: unzip is required to extract the archive" >&2
exit 1
fi
binary="${BINARY_NAME}.exe"
target="${INSTALL_DIR}/${BINARY_NAME}.exe"
else
tar -xzf "${tmpdir}/${filename}" -C "${tmpdir}"
binary="${BINARY_NAME}"
target="${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${tmpdir}/${binary}"
fi
# Install the binary
if [ -w "$INSTALL_DIR" ]; then
mv "${tmpdir}/${binary}" "$target"
else
echo "Installing to ${INSTALL_DIR} (requires sudo)..."
sudo mv "${tmpdir}/${binary}" "$target"
fi
echo "acli ${version} installed to ${target}"
}
main