-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·342 lines (283 loc) · 9.1 KB
/
install.sh
File metadata and controls
executable file
·342 lines (283 loc) · 9.1 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/sh
# flux-pipelines installer script
# Requires uv to be installed and functional
set -u
APP_NAME="flux-pipelines"
ARTIFACTORY_URL="https://physicsx.jfrog.io/artifactory/api/pypi/px-pypi-release/simple"
FLUX_PIPELINES_INSTALLED=0
FLUX_PIPELINES_VERSION=""
INSTALL_PREFIX=""
NETRC_FILE="${NETRC:-$HOME/.netrc}"
# Some Linux distributions don't set HOME
# https://github.com/astral-sh/uv/issues/6965#issuecomment-2915796022
get_home() {
if [ -n "${HOME:-}" ]; then
echo "$HOME"
elif [ -n "${USER:-}" ]; then
getent passwd "$USER" | cut -d: -f6
else
getent passwd "$(id -un)" | cut -d: -f6
fi
}
# The HOME reference to show in user output. If `$HOME` isn't set, we show the absolute path instead.
get_home_expression() {
if [ -n "${HOME:-}" ]; then
# shellcheck disable=SC2016
echo '$HOME'
elif [ -n "${USER:-}" ]; then
getent passwd "$USER" | cut -d: -f6
else
getent passwd "$(id -un)" | cut -d: -f6
fi
}
# Receipt system variables
INFERRED_HOME=$(get_home)
# shellcheck disable=SC2034
INFERRED_HOME_EXPRESSION=$(get_home_expression)
RECEIPT_HOME="${XDG_CONFIG_HOME:-$INFERRED_HOME/.config}/flux-pipelines"
usage() {
cat <<EOF
install.sh
The installer for $APP_NAME
REQUIREMENTS:
- uv tool: curl -LsSf https://astral.sh/uv/install.sh | sh
- curl tool (usually pre-installed on most systems)
- .netrc file configured with PhysicsX Artifactory credentials:
Default location: ~/.netrc
Custom location: Set NETRC environment variable
File format:
machine physicsx.jfrog.io
login <your-username>
password <your-api-token>
Make sure to set proper permissions: chmod 600 ~/.netrc
USAGE:
install.sh [OPTIONS]
OPTIONS:
-h, --help
Print help information
EOF
}
info() {
local green
local reset
green=$(tput setaf 2 2>/dev/null || echo '')
reset=$(tput sgr0 2>/dev/null || echo '')
echo "${green}✓${reset} $1"
}
warn() {
local yellow
local reset
yellow=$(tput setaf 3 2>/dev/null || echo '')
reset=$(tput sgr0 2>/dev/null || echo '')
echo "${yellow}⚠${reset} $1"
}
notice() {
local blue
local reset
blue=$(tput setaf 4 2>/dev/null || echo '')
reset=$(tput sgr0 2>/dev/null || echo '')
echo "${blue}ℹ${reset} $1"
}
err() {
local red
local reset
red=$(tput setaf 1 2>/dev/null || echo '')
reset=$(tput sgr0 2>/dev/null || echo '')
echo "${red}ERROR${reset}: $1" >&2
exit 1
}
check_cmd() {
command -v "$1" >/dev/null 2>&1
return $?
}
need_cmd() {
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
fi
}
create_receipt() {
local version="$1"
local timestamp
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Create receipt directory if it doesn't exist
if ! mkdir -p "$RECEIPT_HOME"; then
# Don't fail installation if receipt creation fails
warn "Unable to create receipt directory at $RECEIPT_HOME"
return 0
fi
# Create JSON receipt
local receipt_file="$RECEIPT_HOME/$APP_NAME-receipt.json"
cat >"$receipt_file" <<EOF
{
"install_prefix": "$INSTALL_PREFIX",
"package_name": "physicsx.flux-pipelines",
"binaries": ["flux_pipelines"],
"installed_version": "$version",
"installation_timestamp": "$timestamp",
"artifactory_url": "$ARTIFACTORY_URL"
}
EOF
if [ $? -eq 0 ]; then
info "Installation receipt saved to $receipt_file"
else
warn "Failed to create installation receipt"
fi
}
check_uv() {
# Check if uv command exists
if ! check_cmd uv; then
err "uv is required but not found in PATH. Install uv first: curl -LsSf https://astral.sh/uv/install.sh | sh"
fi
# Test that uv is functional
if ! uv --version >/dev/null 2>&1; then
err "uv command found but not functional. Please reinstall uv: curl -LsSf https://astral.sh/uv/install.sh | sh"
fi
local uv_version
uv_version=$(uv --version 2>/dev/null | head -n 1)
info "uv is available: $uv_version"
# Set the install prefix now that we know uv is functional
INSTALL_PREFIX=$(uv tool dir --bin 2>/dev/null || echo "uv-tool")
}
check_curl() {
# Check if curl command exists
if ! check_cmd curl; then
err "curl is required but not found in PATH. Install curl using your system package manager (apt, yum, brew, etc.)"
fi
# Test that curl is functional
if ! curl --version >/dev/null 2>&1; then
err "curl command found but not functional. Please reinstall curl using your system package manager"
fi
local curl_version
curl_version=$(curl --version 2>/dev/null | head -n 1)
info "curl is available: $curl_version"
}
check_artifactory_credentials() {
# Check if .netrc exists
if [ ! -f "$NETRC_FILE" ]; then
err ".netrc file not found at $NETRC_FILE. Please create it with PhysicsX Artifactory credentials:
machine physicsx.jfrog.io
login <your-username>
password <your-api-token>
Make sure to set proper permissions: chmod 600 ~/.netrc"
fi
# Test access to PhysicsX Artifactory index
local http_status
reserve_status_block 1
info "Checking Artifactory credentials..."
clear_status_block
# Use curl to test access with --netrc-file, capture HTTP status
http_status=$(curl --netrc-file "$NETRC_FILE" --location --silent --head --write-out '%{http_code}' --output /dev/null "$ARTIFACTORY_URL" 2>/dev/null)
case "$http_status" in
200)
info "PhysicsX Artifactory access verified"
;;
302 | 301)
info "PhysicsX Artifactory access verified (redirected)"
;;
401 | 403)
err "Authentication failed for PhysicsX Artifactory. Please check your ~/.netrc credentials:
machine physicsx.jfrog.io
login <your-username>
password <your-api-token>
Make sure your username and API token are correct."
;;
000)
err "Failed to connect to PhysicsX Artifactory. Please check your network connection and try again."
;;
*)
err "Unexpected response from PhysicsX Artifactory (HTTP $http_status). Please try again or contact support."
;;
esac
}
check_flux_pipelines() {
if check_cmd flux_pipelines; then
if flux_pipelines --version >/dev/null 2>&1; then
FLUX_PIPELINES_VERSION=$(flux_pipelines --version 2>/dev/null | head -n 1)
FLUX_PIPELINES_INSTALLED=1
info "flux-pipelines is already installed: $FLUX_PIPELINES_VERSION"
else
notice "flux-pipelines found but not functional - will reinstall"
FLUX_PIPELINES_INSTALLED=0
fi
else
info "flux-pipelines is not currently installed - will perform fresh installation"
FLUX_PIPELINES_INSTALLED=0
fi
}
# Hide cursor for clean output
hide_cursor() {
tput civis 2>/dev/null
}
reserve_status_block() {
local reserve_lines=$1
i=0
while [ $i -lt $reserve_lines ]; do
printf '\n'
i=$((i + 1))
done
if [ $reserve_lines -gt 0 ]; then
tput cuu "$reserve_lines"
fi
tput sc 2>/dev/null
}
clear_status_block() {
tput rc 2>/dev/null
tput ed 2>/dev/null
}
install_flux_pipelines() {
local install_command
# Determine installation type and command
if [ "$FLUX_PIPELINES_INSTALLED" = "1" ]; then
info "Updating flux-pipelines..."
else
info "Installing flux-pipelines..."
fi
install_command="uv tool install --force physicsx.flux-pipelines --upgrade"
reserve_status_block 6
# Set environment variables and run installation
if UV_INDEX="$ARTIFACTORY_URL" NETRC="$NETRC_FILE" $install_command; then
clear_status_block
# Verify installation succeeded
if flux_pipelines --version >/dev/null 2>&1; then
local new_version
new_version=$(flux_pipelines --version 2>/dev/null | head -n 1)
info "flux-pipelines installation completed: $new_version"
# Create installation receipt
create_receipt "$new_version"
else
err "Installation appeared to succeed but flux-pipelines is not functional. Please check your PATH or try running the installer again."
fi
else
err "Installation failed. Please check your network connection and Artifactory credentials, then try again."
fi
}
main() {
# Parse arguments
for arg in "$@"; do
case "$arg" in
--help | -h)
usage
exit 0
;;
*)
if [ "${arg%%--*}" = "" ]; then
err "unknown option $arg"
fi
;;
esac
done
info "Checking requirements for $APP_NAME installation..."
# Check that uv is available and functional
check_uv
# Check that curl is available and functional
check_curl
# Check that Artifactory credentials are configured and working
check_artifactory_credentials
# Check current installation status of flux-pipelines
check_flux_pipelines
info "All requirements satisfied!"
# Perform the installation
install_flux_pipelines
info "$APP_NAME installation completed successfully! 🎉"
}
main "$@"