-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·128 lines (108 loc) · 3.58 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·128 lines (108 loc) · 3.58 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
#!/bin/sh
set -e
REPO="exploreomni/cli"
BINARY="omni"
main() {
os=$(detect_os)
arch=$(detect_arch)
if [ "$os" = "windows" ]; then
echo "Error: This install script does not support Windows." >&2
echo "Please download the binary from https://github.com/${REPO}/releases" >&2
exit 1
fi
version=$(fetch_latest_version)
if [ -z "$version" ]; then
echo "Error: Could not determine latest version." >&2
exit 1
fi
# Strip leading 'v' for archive name
version_num="${version#v}"
archive="${BINARY}_${version_num}_${os}_${arch}.tar.gz"
url="https://github.com/${REPO}/releases/download/${version}/${archive}"
checksums_url="https://github.com/${REPO}/releases/download/${version}/checksums.txt"
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
echo "Downloading ${BINARY} ${version} for ${os}/${arch}..."
download "$url" "${tmpdir}/${archive}"
download "$checksums_url" "${tmpdir}/checksums.txt"
echo "Verifying checksum..."
verify_checksum "${tmpdir}" "${archive}"
echo "Extracting..."
tar -xzf "${tmpdir}/${archive}" -C "${tmpdir}"
install_dir=$(select_install_dir)
echo "Installing to ${install_dir}/${BINARY}..."
mkdir -p "$install_dir"
mv "${tmpdir}/${BINARY}" "${install_dir}/${BINARY}"
chmod +x "${install_dir}/${BINARY}"
echo "Successfully installed ${BINARY} ${version} to ${install_dir}/${BINARY}"
}
detect_os() {
case "$(uname -s)" in
Darwin) echo "darwin" ;;
Linux) echo "linux" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) echo "Error: Unsupported OS: $(uname -s)" >&2; exit 1 ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
*) echo "Error: Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac
}
fetch_latest_version() {
url="https://api.github.com/repos/${REPO}/releases/latest"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/'
elif command -v wget >/dev/null 2>&1; then
wget -qO- "$url" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/'
else
echo "Error: curl or wget is required" >&2
exit 1
fi
}
download() {
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$2" "$1"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$2" "$1"
fi
}
verify_checksum() {
dir="$1"
file="$2"
expected=$(grep "$file" "${dir}/checksums.txt" | awk '{print $1}')
if [ -z "$expected" ]; then
echo "Error: Checksum not found for ${file}" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "${dir}/${file}" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "${dir}/${file}" | awk '{print $1}')
else
echo "Warning: No sha256 tool found, skipping checksum verification" >&2
return
fi
if [ "$expected" != "$actual" ]; then
echo "Error: Checksum mismatch for ${file}" >&2
echo " Expected: ${expected}" >&2
echo " Actual: ${actual}" >&2
exit 1
fi
}
select_install_dir() {
if [ -w /usr/local/bin ]; then
echo "/usr/local/bin"
else
dir="${HOME}/.local/bin"
mkdir -p "$dir"
echo "$dir"
case ":${PATH}:" in
*":${dir}:"*) ;;
*) echo "Warning: ${dir} is not in your PATH. Add it with: export PATH=\"${dir}:\$PATH\"" >&2 ;;
esac
fi
}
main