-
Notifications
You must be signed in to change notification settings - Fork 12
/
installer.sh
executable file
·160 lines (132 loc) · 4 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
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
#!/bin/sh
set -e -u
ORG=metatypedev
REPO=metatype
EXT=tar.gz
NAME=meta-cli
EXE=meta
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:-$HOME/.metatype/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"
if [ -n "${META_THIN+x}" ]; then
printf "Detected \$META_THIN\n"
ASSET="$NAME-thin-v$VERSION-$PLATFORM"
else
ASSET="$NAME-v$VERSION-$PLATFORM"
fi
DOWNLOAD_URL="$RELEASE_URL/download/v$VERSION/$ASSET.$EXT"
echo $DOWNLOAD_URL
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 [ ! -d "${OUT_DIR}" ]; then
mkdir -p "$OUT_DIR"
fi
if [ -w "${OUT_DIR}" ]; then
read -p "Press enter to continue (or cancel with Ctrl+C):"
mv "$TMP_DIR/$EXE" "$OUT_DIR"
else
echo "$OUT_DIR is not writable."
exit 1
fi
fi
rm -r "$TMP_DIR"
SHELL_TYPE=$(basename "$SHELL")
case $SHELL_TYPE in
bash|zsh|ksh)
SHELL_CONFIG="$HOME/.$SHELL_TYPE"rc
;;
fish)
SHELL_CONFIG="$HOME/.config/fish/config.fish"
;;
*)
SHELL_CONFIG=""
esac
if [ -n "$SHELL_CONFIG" ]; then
printf "\nDetected shell: %s\n" "$SHELL_TYPE"
read -p "Do you want to append the new PATH to your configuration ($SHELL_CONFIG)? (y/n): " answer
answer=$(echo "$answer" | tr "[:upper:]" "[:lower:]")
case $SHELL_TYPE in
bash|zsh|ksh)
APPEND_CMD="export PATH=\"$OUT_DIR:\$PATH\""
;;
fish)
APPEND_CMD="fish_add_path $OUT_DIR"
;;
esac
if [ "$answer" = "y" ] || [ "$answer" = "yes" ]; then
echo "$APPEND_CMD" >> "$SHELL_CONFIG"
printf "Path added to %s\nRun 'source %s' to apply changes." "$SHELL_CONFIG" "$SHELL_CONFIG"
else
cat <<EOF
Consider adding $OUT_DIR to your PATH if it is not already configured.
$ $APPEND_CMD
EOF
fi
else
printf "\nConsider adding %s to your PATH if it is not already configured." "$OUT_DIR"
fi