-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·144 lines (121 loc) · 3.4 KB
/
installer.sh
File metadata and controls
executable file
·144 lines (121 loc) · 3.4 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
#!/bin/sh
set -e
_main() {
if _should_install_pkgx; then
_install_pkgx "$@"
elif [ $# -eq 0 ]; then
echo /usr/local/bin/"$(pkgx --version) already installed" >&2
echo /usr/local/bin/"$(pkgm --version) already installed" >&2
exit
fi
if [ $# -gt 0 ]; then
pkgx "$@"
else
if type eval >/dev/null 2>&1; then
if ! [ "$major_version" ]; then
major_version=$(pkgx --version | cut -d' ' -f2 | cut -d. -f1)
fi
if [ $major_version -lt 2 ]; then
eval "$(pkgx --shellcode)" 2>/dev/null
fi
fi
if ! _is_ci; then
echo "now type: pkgx --help" >&2
fi
fi
}
_prep() {
if test -n "$VERBOSE" -o -n "$GITHUB_ACTIONS" -a -n "$RUNNER_DEBUG"; then
set -x
fi
if test -d /usr/local/bin -a ! -w /usr/local/bin; then
SUDO="sudo"
elif test -d /usr/local -a ! -w /usr/local; then
SUDO="sudo"
elif test -d /usr -a ! -w /usr; then
SUDO="sudo"
fi
}
_is_ci() {
[ -n "$CI" ] && [ $CI != 0 ]
}
_install_pkgx() {
if _is_ci; then
progress="--no-progress-meter"
else
progress="--progress-bar"
fi
tmpdir="$(mktemp -d)"
if [ $# -eq 0 ]; then
if [ -f /usr/local/bin/pkgx ]; then
echo "upgrading: /usr/local/bin/pkgx" >&2
else
echo "installing: /usr/local/bin/pkgx" >&2
fi
# using a named pipe to prevent curl progress output trumping the sudo password prompt
pipe="$tmpdir/pipe"
mkfifo "$pipe"
curl $progress --fail --proto '=https' "https://pkgx.sh/$(uname)/$(uname -m)".tgz > "$pipe" &
$SUDO sh -c "
mkdir -p /usr/local/bin
tar xz --directory /usr/local/bin < '$pipe'
if [ ! -f /usr/local/bin/pkgm ]; then
echo '#!/usr/bin/env -S pkgx -q! pkgm' > /usr/local/bin/pkgm
chmod +x /usr/local/bin/pkgm
fi
if [ ! -f /usr/local/bin/mash ]; then
echo '#!/usr/bin/env -S pkgx -q! mash' > /usr/local/bin/mash
chmod +x /usr/local/bin/mash
fi
" &
wait
rm -r "$tmpdir"
if [ "$(command -v pkgx 2>&1)" != /usr/local/bin/pkgx ]; then
echo "warning: active pkgx is not /usr/local/bin/pkgx" >&2
export PATH="/usr/local/bin:$PATH" # so we can exec if required
fi
# tell the user what version we just installed
pkgx --version
pkgx pkgm@latest --version
pkgx mash@latest --version
else
curl $progress --fail --proto '=https' \
"https://pkgx.sh/$(uname)/$(uname -m)".tgz \
| tar xz --directory "$tmpdir"
export PATH="$tmpdir:$PATH"
export PKGX_DIR="$tmpdir"
fi
unset tmpdir pipe
}
_pkgx_is_old() {
if [ "$PKGX_UPDATE" = no ]; then
return 1
else
new_version=$(curl -Ssf https://pkgx.sh/VERSION)
old_version=$(/usr/local/bin/pkgx --version || echo pkgx 0)
old_version=$(echo $old_version | cut -d' ' -f2)
major_version=$(echo $new_version | cut -d. -f1)
/usr/local/bin/pkgx --silent semverator gt $new_version $old_version
fi
}
_pkgm_is_old() {
if [ "$PKGX_UPDATE" = no ]; then
return 1
else
new_version=$(curl -Ssf https://pkgxdev.github.io/pkgm/version.txt)
old_version=$(pkgm --version || echo pkgm 0)
old_version=$(echo $old_version | cut -d' ' -f2)
/usr/local/bin/pkgx --silent semverator gt $new_version $old_version
fi
}
_should_install_pkgx() {
if [ ! -f /usr/local/bin/pkgx ]; then
return 0
elif _pkgx_is_old >/dev/null 2>&1 || _pkgm_is_old >/dev/null 2>&1; then
return 0
else
return 1
fi
}
_prep
_main "$@"