Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
92 lines (83 loc) · 2.9 KB
/
Copy pathinstall.sh
File metadata and controls
92 lines (83 loc) · 2.9 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
#!/bin/sh
set -eu
fail() {
printf 'prtui: %s\n' "$*" >&2
exit 1
}
main() {
version=latest
directory="$HOME/.local/bin"
while [ "$#" -gt 0 ]; do
case "$1" in
--nightly|--head) version=nightly; shift ;;
--version|--install-dir)
[ "$#" -ge 2 ] && [ -n "$2" ] || fail "$1 requires a value"
case "$1" in
--version) version=$2 ;;
--install-dir) directory=$2 ;;
esac
shift 2
;;
-h|--help)
printf 'Usage: install.sh [--nightly | --version VERSION] [--install-dir DIR]\n'
return
;;
*) fail "unknown option: $1" ;;
esac
done
command -v curl >/dev/null 2>&1 || fail 'curl is required'
command -v tar >/dev/null 2>&1 || fail 'tar is required'
case "$(uname -s)" in
Darwin) platform=apple-darwin ;;
Linux) platform=unknown-linux-musl ;;
*) fail 'supported systems are macOS and Linux' ;;
esac
case "$(uname -m)" in
arm64|aarch64) architecture=aarch64 ;;
x86_64|amd64) architecture=x86_64 ;;
*) fail 'supported architectures are ARM64 and x86_64' ;;
esac
if command -v sha256sum >/dev/null 2>&1; then
checksum=sha256sum
elif command -v shasum >/dev/null 2>&1; then
checksum='shasum -a 256'
else
fail 'sha256sum or shasum is required'
fi
repository=https://github.com/tale/prtui
if [ "$version" = latest ]; then
latest=$(curl -fsSL -o /dev/null -w '%{url_effective}' "$repository/releases/latest")
version=${latest##*/}
fi
case "$version" in
nightly) tag=nightly ;;
*) tag="v${version#v}" ;;
esac
version=${tag#v}
case "$version" in
''|*[!a-zA-Z0-9.+-]*) fail "invalid release version: $version" ;;
esac
temporary=$(mktemp -d)
staging=
trap 'rm -rf "$temporary"; if [ -n "$staging" ]; then rm -f "$staging"; fi' EXIT
trap 'exit 1' HUP INT TERM
name="prtui-$tag-$architecture-$platform"
url="$repository/releases/download/$tag/$name.tar.gz"
printf 'Downloading prtui %s for %s-%s\n' "$version" "$architecture" "$platform"
curl -fsSL "$url" -o "$temporary/$name.tar.gz"
curl -fsSL "$url.sha256" -o "$temporary/$name.tar.gz.sha256"
(cd "$temporary" && $checksum -c "$name.tar.gz.sha256")
tar xzf "$temporary/$name.tar.gz" -C "$temporary" "$name/prtui"
mkdir -p "$directory"
[ ! -d "$directory/prtui" ] || fail "$directory/prtui is a directory"
staging=$(mktemp "$directory/.prtui.XXXXXX")
install -m 755 "$temporary/$name/prtui" "$staging"
mv -f "$staging" "$directory/prtui"
staging=
printf 'Installed prtui to %s/prtui\n' "$directory"
case ":$PATH:" in
*":$directory:"*) ;;
*) printf 'Add %s to your PATH.\n' "$directory" ;;
esac
}
main "$@"