-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·199 lines (174 loc) · 6.48 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·199 lines (174 loc) · 6.48 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
198
199
#!/usr/bin/env bash
set -euo pipefail
readonly DEFAULT_RELEASE_BASE_URL="https://github.com/jmix-framework/jmix-cli/releases/latest/download"
readonly RELEASE_BASE_URL="${JMIX_CLI_RELEASE_BASE_URL:-$DEFAULT_RELEASE_BASE_URL}"
readonly INSTALL_ROOT="${JMIX_CLI_INSTALL_ROOT:-${XDG_DATA_HOME:-$HOME/.local/share}/jmix-cli}"
readonly BIN_DIR="${JMIX_CLI_BIN_DIR:-$HOME/.local/bin}"
interactive_output=false
if [[ -t 1 && -t 2 && "${TERM:-dumb}" != "dumb" && -z "${CI:-}" ]]; then
interactive_output=true
fi
status() {
local color="$1"
shift
if [[ "$interactive_output" == true && -z "${NO_COLOR:-}" ]]; then
printf '\033[1;%sm%s\033[0m\n' "$color" "$*"
else
printf '%s\n' "$*"
fi
}
fail() {
echo "Jmix CLI installer: $*" >&2
exit 1
}
require_command() {
command -v "$1" >/dev/null 2>&1 || fail "'$1' is required."
}
case "$(uname -s)" in
Darwin) platform="macos" ;;
Linux) platform="linux" ;;
*) fail "unsupported operating system: $(uname -s)" ;;
esac
case "$(uname -m)" in
arm64 | aarch64) architecture="arm64" ;;
x86_64 | amd64) architecture="x64" ;;
*) fail "unsupported architecture: $(uname -m)" ;;
esac
require_command curl
require_command tar
archive_name="jmix-cli-$platform-$architecture.tar.gz"
checksum_name="$archive_name.sha256"
temp_dir="$(mktemp -d "${TMPDIR:-/tmp}/jmix-cli-install.XXXXXX")"
cleanup() {
rm -rf "$temp_dir"
}
trap cleanup EXIT HUP INT TERM
download_asset() {
local name="$1"
local destination="$2"
local base="${RELEASE_BASE_URL%/}"
status 36 "Downloading $name..."
case "$base" in
http://* | https://* | file://*)
local progress_options=(-s)
if [[ "$interactive_output" == true ]]; then
progress_options=(--progress-bar)
fi
curl -fSL "${progress_options[@]}" "$base/$name" -o "$destination"
;;
*)
cp "$base/$name" "$destination"
;;
esac
}
archive_file="$temp_dir/$archive_name"
checksum_file="$temp_dir/$checksum_name"
download_asset "$archive_name" "$archive_file"
download_asset "$checksum_name" "$checksum_file"
status 36 "Verifying $archive_name..."
expected_checksum="$(awk 'NR == 1 { print tolower($1) }' "$checksum_file")"
[[ "$expected_checksum" =~ ^[[:xdigit:]]{64}$ ]] || fail "invalid checksum file for $archive_name."
if command -v sha256sum >/dev/null 2>&1; then
actual_checksum="$(sha256sum "$archive_file" | awk '{ print tolower($1) }')"
elif command -v shasum >/dev/null 2>&1; then
actual_checksum="$(shasum -a 256 "$archive_file" | awk '{ print tolower($1) }')"
else
fail "'sha256sum' or 'shasum' is required to verify the download."
fi
[[ "$actual_checksum" == "$expected_checksum" ]] || fail "checksum verification failed for $archive_name."
versions_dir="$INSTALL_ROOT/versions"
version_dir="$versions_dir/$expected_checksum"
case "$platform" in
macos)
image_name="jmix.app"
launcher_relative="Contents/MacOS/jmix"
;;
linux)
image_name="jmix"
launcher_relative="bin/jmix"
;;
esac
launcher="$version_dir/$launcher_relative"
# Marks a complete installation; the CLI keeps and prunes versions by this file.
readonly INSTALL_MARKER=".jmix-installed"
installed=false
if [[ -x "$launcher" && -f "$version_dir/$INSTALL_MARKER" ]]; then
echo "Jmix CLI is already up to date."
else
[[ ! -e "$version_dir" ]] || fail "incomplete installation found at $version_dir."
extract_dir="$temp_dir/extracted"
mkdir -p "$extract_dir" "$versions_dir"
status 36 "Extracting $archive_name..."
tar -xzf "$archive_file" -C "$extract_dir"
[[ -x "$extract_dir/$image_name/$launcher_relative" ]] || fail "release archive has an unexpected layout."
: > "$extract_dir/$image_name/$INSTALL_MARKER"
mv "$extract_dir/$image_name" "$version_dir"
installed=true
fi
# Timestamps inside the archive are fixed, so record the install time here.
touch "$version_dir/$INSTALL_MARKER"
mkdir -p "$BIN_DIR"
command_path="$BIN_DIR/jmix"
versions_real="$(cd "$versions_dir" && pwd -P)"
if [[ -L "$command_path" ]]; then
current_target="$(readlink "$command_path")"
# Self-update writes the resolved path, so compare real locations too.
current_real="$(cd "$(dirname "$current_target")" 2>/dev/null && pwd -P || true)"
case "$current_target" in
"$launcher") ;;
"$versions_dir"/*) ln -sfn "$launcher" "$command_path" ;;
*)
case "${current_real:-}" in
"$versions_real"/*) ln -sfn "$launcher" "$command_path" ;;
*) fail "$command_path already exists and is not managed by this installer." ;;
esac
;;
esac
elif [[ -e "$command_path" ]]; then
fail "$command_path already exists and is not managed by this installer."
else
ln -s "$launcher" "$command_path"
fi
mkdir -p "$INSTALL_ROOT"
# Recorded after the command exists, so a rejected install leaves no metadata.
# The CLI cannot otherwise know a custom bin directory.
printf '%s\n' "$BIN_DIR" > "$INSTALL_ROOT/bin-dir"
if [[ "$installed" == true ]]; then
status 32 "Installed Jmix CLI at $command_path"
fi
case ":$PATH:" in
*":$BIN_DIR:"*) ;;
*)
path_command="export PATH=\"\$HOME/.local/bin:\$PATH\""
shell_profile=""
if [[ "$BIN_DIR" == "$HOME/.local/bin" && "${JMIX_CLI_SKIP_PATH_UPDATE:-0}" != "1" ]]; then
case "${SHELL:-}" in
*/bash | bash) shell_profile="$HOME/.bashrc" ;;
*/zsh | zsh) shell_profile="$HOME/.zshrc" ;;
*/ash | ash | */dash | dash | */ksh | ksh | */sh | sh | "") shell_profile="$HOME/.profile" ;;
esac
if [[ -n "$shell_profile" ]]; then
if grep -Fqx "$path_command" "$shell_profile" 2>/dev/null; then
echo "$BIN_DIR is already configured in $shell_profile."
elif printf '\n%s\n' "$path_command" >> "$shell_profile"; then
echo "Added $BIN_DIR to PATH in $shell_profile."
fi
fi
fi
if [[ "$BIN_DIR" == "$HOME/.local/bin" ]]; then
echo "Restart your shell or run: $path_command"
else
echo "Add $BIN_DIR to PATH to use 'jmix' in future shells."
fi
;;
esac
if [[ "${JMIX_CLI_NO_RUN:-0}" == "1" ]]; then
exit 0
fi
status 36 "Starting the Jmix project wizard..."
cleanup
trap - EXIT HUP INT TERM
if { exec 3</dev/tty; } 2>/dev/null; then
exec "$command_path" "$@" <&3 3<&-
fi
exec "$command_path" "$@"