-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·70 lines (59 loc) · 1.83 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·70 lines (59 loc) · 1.83 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
#!/bin/sh
# Installer for the initializ CLI.
# curl -fsSL https://raw.githubusercontent.com/initializ/cli/main/install.sh | sh
# Env overrides:
# VERSION=vX.Y.Z install a specific release (default: latest)
# INSTALL_DIR=path install destination (default: /usr/local/bin)
set -eu
REPO="initializ/cli"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux | darwin) ;;
*)
echo "unsupported OS: $os — download manually from https://github.com/$REPO/releases" >&2
exit 1
;;
esac
arch=$(uname -m)
case "$arch" in
x86_64 | amd64) arch=amd64 ;;
arm64 | aarch64) arch=arm64 ;;
*)
echo "unsupported architecture: $arch" >&2
exit 1
;;
esac
version="${VERSION:-}"
if [ -z "$version" ]; then
version=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" |
grep '"tag_name"' | head -1 | cut -d '"' -f 4)
fi
if [ -z "$version" ]; then
echo "could not determine the latest version" >&2
exit 1
fi
archive="initializ_${os}_${arch}.tar.gz"
base="https://github.com/$REPO/releases/download/$version"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
echo "Downloading initializ $version ($os/$arch)..." >&2
curl -fsSL "$base/$archive" -o "$tmp/$archive"
curl -fsSL "$base/checksums.txt" -o "$tmp/checksums.txt"
if command -v sha256sum >/dev/null 2>&1; then
sha_cmd="sha256sum"
else
sha_cmd="shasum -a 256"
fi
(cd "$tmp" && grep " $archive\$" checksums.txt | $sha_cmd -c - >/dev/null) || {
echo "checksum verification failed for $archive" >&2
exit 1
}
tar -xzf "$tmp/$archive" -C "$tmp"
if [ -w "$INSTALL_DIR" ]; then
install "$tmp/initializ" "$INSTALL_DIR/initializ"
else
echo "Installing to $INSTALL_DIR (requires sudo)..." >&2
sudo install "$tmp/initializ" "$INSTALL_DIR/initializ"
fi
echo "Installed initializ $version to $INSTALL_DIR/initializ" >&2