-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·65 lines (50 loc) · 1.44 KB
/
install.sh
File metadata and controls
executable file
·65 lines (50 loc) · 1.44 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
#!/usr/bin/env bash
set -euo pipefail
REPO="coder11125/patchwork"
BINARY="patchwork"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
GITHUB_URL="https://github.com/${REPO}"
info() { echo "==> $*"; }
err_exit(){ echo "!!> $*" >&2; exit 1; }
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
*) err_exit "unsupported OS: $(uname -s)" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) err_exit "unsupported arch: $(uname -m)" ;;
esac
}
latest_release() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}
main() {
local version="${1:-}"
local os arch dest
os=$(detect_os)
arch=$(detect_arch)
dest="${INSTALL_DIR}/${BINARY}"
info "Detected ${os}/${arch}"
if [ -z "$version" ]; then
version=$(latest_release)
fi
info "Installing ${BINARY} ${version}"
local filename="${BINARY}-${os}-${arch}"
local download_url="${GITHUB_URL}/releases/download/${version}/${filename}"
info "Downloading ${download_url}"
if curl -fsSL -o "$dest" "$download_url" 2>/dev/null; then
chmod 0755 "$dest"
elif sudo curl -fsSL -o "$dest" "$download_url" 2>/dev/null; then
sudo chmod 0755 "$dest"
else
err_exit "download failed"
fi
info "Installed to ${dest}"
info "Run '${BINARY} --help' to get started"
}
main "$@"