-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·145 lines (128 loc) · 4 KB
/
install.sh
File metadata and controls
executable file
·145 lines (128 loc) · 4 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
144
145
#!/bin/sh
set -e
do_install() {
REPO="safedep/gryph"
BINARY="gryph"
# Prefer $HOME/.local/bin if it exists and is in PATH.
INSTALL_DIR="/usr/local/bin"
if [ -n "$HOME" ]; then
local_bin="$HOME/.local/bin"
case ":${PATH}:" in
*":${local_bin}:"*)
INSTALL_DIR="$local_bin"
mkdir -p "$INSTALL_DIR"
;;
esac
fi
# Detect OS and architecture.
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) os="Linux" ;;
Darwin) os="Darwin" ;;
MINGW* | MSYS* | CYGWIN*) os="Windows" ;;
*)
echo "Error: unsupported operating system: $OS" >&2
exit 1
;;
esac
case "$ARCH" in
x86_64 | amd64) arch="x86_64" ;;
aarch64 | arm64) arch="arm64" ;;
i386 | i686) arch="i386" ;;
*)
echo "Error: unsupported architecture: $ARCH" >&2
exit 1
;;
esac
# macOS ships a universal binary.
if [ "$os" = "Darwin" ]; then
arch="all"
fi
if [ "$os" = "Windows" ]; then
BINARY="gryph.exe"
fi
# Verify install directory exists.
if [ ! -d "$INSTALL_DIR" ]; then
echo "Error: install directory ${INSTALL_DIR} does not exist" >&2
echo "Create it with: sudo mkdir -p ${INSTALL_DIR}" >&2
exit 1
fi
# Fetch latest release tag via redirect (avoids JSON parsing).
echo "Fetching latest release..."
tag=$(curl -fsSI -o /dev/null -w '%{redirect_url}' "https://github.com/${REPO}/releases/latest" | sed 's|.*/||')
if [ -z "$tag" ]; then
echo "Error: could not determine latest release" >&2
exit 1
fi
echo "Latest release: $tag"
# Build download URL.
# Assets follow the pattern: gryph_{OS}_{arch}.{tar.gz|zip}
if [ "$os" = "Windows" ]; then
asset="gryph_${os}_${arch}.zip"
else
asset="gryph_${os}_${arch}.tar.gz"
fi
url="https://github.com/${REPO}/releases/download/${tag}/${asset}"
# Download archive and checksums.
echo "Downloading ${asset}..."
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
checksums_url="https://github.com/${REPO}/releases/download/${tag}/checksums.txt"
if ! curl -fsSL -o "${tmpdir}/${asset}" "$url"; then
echo "Error: archive not available for ${os}/${arch}" >&2
echo "Check available assets at https://github.com/${REPO}/releases/tag/${tag}" >&2
exit 1
fi
if ! curl -fsSL -o "${tmpdir}/checksums.txt" "$checksums_url"; then
echo "Warning: could not download checksums.txt, skipping verification" >&2
else
# Verify SHA-256 checksum.
expected=$(grep " ${asset}$" "${tmpdir}/checksums.txt" | cut -d' ' -f1)
if [ -z "$expected" ]; then
echo "Warning: no checksum found for ${asset}, skipping verification" >&2
else
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "${tmpdir}/${asset}" | cut -d' ' -f1)
elif command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "${tmpdir}/${asset}" | cut -d' ' -f1)
else
echo "Warning: no sha256sum or shasum found, skipping verification" >&2
actual="$expected"
fi
if [ "$actual" != "$expected" ]; then
echo "Error: checksum mismatch for ${asset}" >&2
echo " expected: $expected" >&2
echo " actual: $actual" >&2
exit 1
fi
echo "Checksum verified."
fi
fi
if [ "$os" = "Windows" ]; then
unzip -q -o "${tmpdir}/${asset}" "${BINARY}" -d "${tmpdir}"
else
tar -xzf "${tmpdir}/${asset}" -C "${tmpdir}" "${BINARY}"
fi
if [ ! -f "${tmpdir}/${BINARY}" ]; then
echo "Error: ${BINARY} not found in archive" >&2
exit 1
fi
# Install.
if [ -w "$INSTALL_DIR" ]; then
install -m 755 "${tmpdir}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
else
echo "Installing to ${INSTALL_DIR} (requires sudo)..."
sudo install -m 755 "${tmpdir}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
fi
echo "Installed gryph ${tag} to ${INSTALL_DIR}/${BINARY}"
# Verify the install directory is in PATH.
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo "Warning: ${INSTALL_DIR} is not in your PATH. Add it with:" >&2
echo " export PATH=\"${INSTALL_DIR}:\$PATH\"" >&2
;;
esac
}
do_install