forked from zifeo/whiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.sh
executable file
·118 lines (97 loc) · 3.13 KB
/
installer.sh
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
#!/bin/sh
set -e -u
ORG=zifeo
REPO=whiz
EXT=tar.gz
NAME=whiz
EXE=whiz
INSTALLER_URL="https://raw.githubusercontent.com/$ORG/$REPO/main/installer.sh"
RELEASE_URL="https://github.com/$ORG/$REPO/releases"
LATEST_VERSION=$(curl "$RELEASE_URL/latest" -s -L -I -o /dev/null -w '%{url_effective}')
LATEST_VERSION="${LATEST_VERSION##*v}"
PLATFORM="${PLATFORM:-}"
TMP_DIR=$(mktemp -d)
OUT_DIR="${OUT_DIR:-/usr/local/bin}"
VERSION="${VERSION:-$LATEST_VERSION}"
MACHINE=$(uname -m)
if [ "${PLATFORM:-x}" = "x" ]; then
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
"linux")
case "$MACHINE" in
"arm64"* | "aarch64"* ) PLATFORM='aarch64-unknown-linux-gnu' ;;
*"64") PLATFORM='x86_64-unknown-linux-gnu' ;;
esac
;;
"darwin")
case "$MACHINE" in
"arm64"* | "aarch64"* ) PLATFORM='aarch64-apple-darwin' ;;
*"64") PLATFORM='x86_64-apple-darwin' ;;
esac
;;
"msys"*|"cygwin"*|"mingw"*|*"_nt"*|"win"*)
case "$MACHINE" in
*"64") PLATFORM='x86_64-pc-windows-msvc' ;;
esac
;;
esac
if [ "${PLATFORM:-x}" = "x" ]; then
cat >&2 <<EOF
/!\\ We couldn't automatically detect your operating system. /!\\
To continue with installation, please choose from one of the following values:
- aarch64-unknown-linux-gnu
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- aarch64-apple-darwin
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
Then set the PLATFORM environment variable, and re-run this script:
$ curl -fsSL $INSTALLER_URL | PLATFORM=x86_64-unknown-linux-musl bash
EOF
exit 1
fi
printf "Detected platform: %s\n" "$PLATFORM"
fi
printf "Detected version: %s\n" "$VERSION"
ASSET="$NAME-v$VERSION-$PLATFORM"
DOWNLOAD_URL="$RELEASE_URL/download/v$VERSION/$ASSET.$EXT"
if curl --fail --silent --location --output "$TMP_DIR/$ASSET.$EXT" "$DOWNLOAD_URL"; then
printf "Downloaded successfully: %s\n" "$ASSET.$EXT"
else
cat >&2 <<EOF
/!\\ The asset $ASSET.$EXT doesn't exist. /!\\
To continue with installation, please make sure the release exists in:
$RELEASE_URL
Then set the PLATFORM and VERSION environment variables, and re-run this script:
$ curl -fsSL $INSTALLER_URL | PLATFORM=x86_64-unknown-linux-musl VERSION=0.1.10 bash
EOF
exit 1
fi
tar -C "$TMP_DIR" -xzf "$TMP_DIR/$ASSET.$EXT" "$EXE"
chmod +x "$TMP_DIR/$EXE"
if [ "${OUT_DIR}" = "." ]; then
mv "$TMP_DIR/$EXE" .
printf "\n\n%s has been extracted to your current directory\n" "$EXE"
else
cat <<EOF
$EXE will be moved to $OUT_DIR
Set the OUT_DIR environment variable to change the installation directory:
$ curl -fsSL $INSTALLER_URL | OUT_DIR=. bash
EOF
if [ -w "${OUT_DIR}" ]; then
read -p "Press enter to continue (or cancel with Ctrl+C):"
mv "$TMP_DIR/$EXE" "$OUT_DIR"
else
printf "Sudo is required to run \"sudo mv %s %s\":\n" "$TMP_DIR/$EXE" "$OUT_DIR"
sudo mv "$TMP_DIR/$EXE" "$OUT_DIR"
fi
fi
rm -r "$TMP_DIR"
OUT_DIR=$(realpath $OUT_DIR)
if [[ ":$PATH:" != *":$OUT_DIR:"* ]]; then
cat <<EOF
The installation directory is not in your PATH, consider adding it:
$ export PATH="\$PATH:$OUT_DIR"
Or moving the executable to another directory in your PATH:
$ sudo mv $EXE /usr/local/bin
EOF
fi