-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathpixiw
executable file
·75 lines (63 loc) · 2.14 KB
/
pixiw
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
#!/bin/sh
set -euf
[ "${DEBUG-}" != true ] || set -x
# requires at least pixi 0.44.0
# environment parameters:
# PIXI_INSTALLER_URL - custom pixi installer
# URL_MIRROR_github_com - custom mirror for github.com
# run directly if already under pixi environment
[ -z "${PIXI_EXE-}" ] || exec "${PIXI_EXE-}" "$@"
__check_pixi() {
__pixi="${1-}"
command -v -- "${__pixi-}" >/dev/null || return 1 # check runnable
if "$__pixi" workspace requires-pixi verify 2>/dev/null; then
return 0
else
case $? in
# 2: less than 0.44.0
# 4: verify fail
2 | 4) return 1 ;;
*) exit $? ;; # unknown error
esac
fi
}
__download_to_stdin() {
if hash wget 2>/dev/null; then
wget -qO- "$1"
elif hash curl 2>/dev/null; then
curl -sfSL --compressed "$1"
else
echo echo "\"[ERROR] you need either 'curl' or 'wget' installed.\" >&2"
echo exit 1
fi
}
__install_pixi() (
# require curl, posix sh and sed commands
if [ -n "${URL_MIRROR_github_com-}" ] && ! hash sed 2>/dev/null; then
echo "[WARN] you do not have 'sed' installed to use URL_MIRROR_github_com, ignore the mirror." >&2
unset URL_MIRROR_github_com
fi
: "${PIXI_INSTALLER_URL:=https://raw.githubusercontent.com/prefix-dev/pixi/main/install/install.sh}"
if [ -n "${URL_MIRROR_github_com-}" ]; then
__download_to_stdin "${PIXI_INSTALLER_URL-}" | sed "s|https://github.com/|$URL_MIRROR_github_com|g"
else
__download_to_stdin "${PIXI_INSTALLER_URL-}"
fi | PIXI_VERSION='' PIXI_HOME='' PIXI_NO_PATH_UPDATE=true /bin/sh -s
)
pixi_prj_rc="${0%/*}/.pixi/rc.sh"
# shellcheck source=/dev/null
[ ! -r "$pixi_prj_rc" ] || PIXIW_INSTALL=1 PIXI_PROJECT_ROOT="${0%/*}" . "$pixi_prj_rc"
# search pixi from $PATH
! __check_pixi pixi || exec pixi "$@"
if ! __check_pixi "${HOME:-}/.pixi/bin/pixi"; then
if __install_pixi; then
if ! __check_pixi "${HOME:-}/.pixi/bin/pixi"; then
echo "[ERROR] After install/update, pixi version still does not meet the requirement $("${HOME:-}/.pixi/bin/pixi" workspace requires-pixi get)." >&2
exit 1
fi
else
echo "[ERROR] Fail to install/update pixi" >&2
exit 1
fi
fi
exec "${HOME:-}/.pixi/bin/pixi" "$@"