-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinstall.sh
More file actions
197 lines (173 loc) · 4.95 KB
/
install.sh
File metadata and controls
197 lines (173 loc) · 4.95 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
# gitlawb installer - downloads pre-built binaries from GitHub Releases.
#
# Usage:
# curl -fsSL https://gitlawb.com/install.sh | sh
# curl -fsSL https://gitlawb.com/install.sh | sh -s -- --version v0.3.9
set -euo pipefail
REPO="${GITLAWB_RELEASE_REPO:-Gitlawb/node}"
INSTALL_DIR="${GITLAWB_INSTALL_DIR:-$HOME/.local/bin}"
VERSION_ARG="latest"
usage() {
cat <<EOF
gitlawb installer
Options:
--version <tag> Install a specific release tag, for example v0.3.9.
-h, --help Show this help.
Environment:
GITLAWB_INSTALL_DIR Install directory (default: $HOME/.local/bin)
GITLAWB_RELEASE_REPO GitHub repo to download from (default: Gitlawb/node)
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
--version)
if [ "$#" -lt 2 ]; then
echo "error: --version requires a value" >&2
exit 1
fi
VERSION_ARG="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
VERSION_ARG="$1"
shift
;;
esac
done
OS=$(uname -s)
ARCH=$(uname -m)
case "$OS" in
Linux) OS_NAME="linux" ;;
Darwin) OS_NAME="darwin" ;;
*)
echo "error: unsupported OS: $OS" >&2
echo " please build from source: cargo install --git https://github.com/${REPO} gl" >&2
exit 1
;;
esac
case "$ARCH" in
x86_64) ARCH_NAME="x86_64" ;;
aarch64 | arm64) ARCH_NAME="aarch64" ;;
*)
echo "error: unsupported architecture: $ARCH" >&2
exit 1
;;
esac
case "${OS_NAME}-${ARCH_NAME}" in
linux-x86_64) TARGET="x86_64-unknown-linux-musl" ;;
linux-aarch64) TARGET="aarch64-unknown-linux-musl" ;;
darwin-x86_64) TARGET="x86_64-apple-darwin" ;;
darwin-aarch64) TARGET="aarch64-apple-darwin" ;;
esac
if [ "$VERSION_ARG" = "latest" ]; then
echo "Fetching latest release version..."
TAG=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
if [ -z "$TAG" ]; then
echo "error: could not determine latest release. Check https://github.com/${REPO}/releases" >&2
exit 1
fi
else
TAG="$VERSION_ARG"
fi
case "$TAG" in
v*) VERSION="${TAG#v}" ;;
*) VERSION="$TAG"; TAG="v$TAG" ;;
esac
PACKAGE_NAME="gitlawb-node-${VERSION}-${TARGET}"
ARCHIVE="${PACKAGE_NAME}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${TAG}/${ARCHIVE}"
CHECKSUM_URL="${DOWNLOAD_URL}.sha256"
echo "Installing gitlawb ${TAG} for ${OS_NAME}/${ARCH_NAME}"
echo " Archive: ${ARCHIVE}"
echo " Into: ${INSTALL_DIR}"
echo ""
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
echo "Downloading..."
if ! curl -fSL --progress-bar -o "$TMP_DIR/$ARCHIVE" "$DOWNLOAD_URL"; then
echo ""
echo "error: download failed: $DOWNLOAD_URL" >&2
echo " Check https://github.com/${REPO}/releases for available builds." >&2
exit 1
fi
if curl -fsSL -o "$TMP_DIR/$ARCHIVE.sha256" "$CHECKSUM_URL" 2>/dev/null; then
echo "Verifying checksum..."
EXPECTED=$(awk '{print $1}' "$TMP_DIR/$ARCHIVE.sha256")
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "$TMP_DIR/$ARCHIVE" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "$TMP_DIR/$ARCHIVE" | awk '{print $1}')
else
echo "warning: no sha256 tool found, skipping checksum verification"
ACTUAL="$EXPECTED"
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "error: checksum mismatch!" >&2
echo " expected: $EXPECTED" >&2
echo " actual: $ACTUAL" >&2
exit 1
fi
echo " checksum OK"
fi
echo "Extracting..."
tar -xzf "$TMP_DIR/$ARCHIVE" -C "$TMP_DIR"
PACKAGE_DIR="$TMP_DIR/$PACKAGE_NAME"
if [ ! -d "$PACKAGE_DIR" ]; then
PACKAGE_DIR=$(find "$TMP_DIR" -mindepth 1 -maxdepth 1 -type d | head -n 1)
fi
if [ ! -d "$PACKAGE_DIR" ]; then
echo "error: could not find extracted package directory" >&2
exit 1
fi
mkdir -p "$INSTALL_DIR"
INSTALLED=()
for BIN in gl git-remote-gitlawb gitlawb-node; do
if [ -f "$PACKAGE_DIR/$BIN" ]; then
install -m 755 "$PACKAGE_DIR/$BIN" "$INSTALL_DIR/$BIN.new"
mv -f "$INSTALL_DIR/$BIN.new" "$INSTALL_DIR/$BIN"
INSTALLED+=("$BIN")
fi
done
if [ "${#INSTALLED[@]}" -eq 0 ]; then
echo "error: no installable binaries found in $ARCHIVE" >&2
exit 1
fi
echo ""
echo "Installed gitlawb ${TAG}"
for BIN in "${INSTALLED[@]}"; do
echo " ${BIN} -> ${INSTALL_DIR}/${BIN}"
done
echo ""
if echo ":$PATH:" | grep -q ":${INSTALL_DIR}:"; then
echo "Run:"
echo " gl doctor"
echo " gl quickstart"
else
SHELL_NAME=$(basename "${SHELL:-bash}")
case "$SHELL_NAME" in
zsh) RC="$HOME/.zshrc" ;;
fish) RC="$HOME/.config/fish/config.fish" ;;
*) RC="$HOME/.bashrc" ;;
esac
echo "Add ${INSTALL_DIR} to your PATH:"
echo ""
if [ "$SHELL_NAME" = "fish" ]; then
echo " fish_add_path ${INSTALL_DIR}"
else
echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ${RC}"
echo " source ${RC}"
fi
echo ""
echo "Then run:"
echo " gl doctor"
echo " gl quickstart"
fi
echo ""
echo "Docs: https://docs.gitlawb.com"