-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·53 lines (45 loc) · 1.61 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.61 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
#!/bin/sh
# gw installer — downloads the prebuilt binary from GitHub releases.
# curl -fsSL https://raw.githubusercontent.com/liu1700/gw/main/install.sh | sh
# Options via env:
# GW_INSTALL_DIR target directory (default: ~/.local/bin)
# GW_VERSION tag to install, e.g. v0.2.0 (default: latest release)
set -eu
REPO="liu1700/gw"
DIR="${GW_INSTALL_DIR:-$HOME/.local/bin}"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
darwin|linux) ;;
*) echo "gw: unsupported OS: $OS (darwin and linux only for now)" >&2; exit 1 ;;
esac
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH=amd64 ;;
aarch64|arm64) ARCH=arm64 ;;
*) echo "gw: unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
if [ -z "${GW_VERSION:-}" ]; then
GW_VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name"' | head -1 | cut -d'"' -f4)
fi
[ -n "$GW_VERSION" ] || { echo "gw: could not determine latest release" >&2; exit 1; }
URL="https://github.com/$REPO/releases/download/$GW_VERSION/gw_${GW_VERSION#v}_${OS}_${ARCH}.tar.gz"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
echo "gw: downloading $URL"
curl -fsSL "$URL" | tar -xz -C "$TMP" gw
mkdir -p "$DIR"
install -m 0755 "$TMP/gw" "$DIR/gw"
echo "gw: installed $("$DIR/gw" version) to $DIR/gw"
case ":$PATH:" in
*":$DIR:"*) ;;
*)
rc="$HOME/.profile"
case "${SHELL:-}" in
*/zsh) rc="$HOME/.zshrc" ;;
*/bash) rc="$HOME/.bashrc" ;;
esac
echo "gw: note — $DIR is not on your PATH. To fix it permanently, run:"
echo " echo 'export PATH=\"$DIR:\$PATH\"' >> \"$rc\" && export PATH=\"$DIR:\$PATH\""
;;
esac