-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathinstaller.sh
executable file
·194 lines (166 loc) · 4.69 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
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
#!/bin/sh
set -e
_main() {
if _should_install_pkgx; then
_install_pkgx "$@"
_install_pre_reqs
elif [ $# -eq 0 ]; then
echo "$(pkgx --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_pre_reqs() {
if _is_ci; then
apt() {
# we should use apt-get not apt in CI
# weird shit ref: https://askubuntu.com/a/668859
export DEBIAN_FRONTEND=noninteractive
cmd=$1
shift
$SUDO apt-get $cmd --yes -qq -o=Dpkg::Use-Pty=0 $@
}
else
apt() {
case "$1" in
update)
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
;;
install)
echo " apt-get" "$@" >&2
;;
esac
}
yum() {
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
echo " yum" "$@" >&2
}
pacman() {
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
echo " pacman" "$@" >&2
}
fi
if test -f /etc/debian_version; then
apt update
# minimal but required or networking doesn’t work
# https://packages.debian.org/buster/all/netbase/filelist
A="netbase"
# difficult to pkg in our opinion
B=libudev-dev
# ca-certs needed until we bundle our own root cert
C=ca-certificates
case $(cat /etc/debian_version) in
jessie/sid|8.*|stretch/sid|9.*)
apt install libc-dev libstdc++-4.8-dev libgcc-4.7-dev $A $B $C;;
buster/sid|10.*)
apt install libc-dev libstdc++-8-dev libgcc-8-dev $A $B $C;;
bullseye/sid|11.*)
apt install libc-dev libstdc++-10-dev libgcc-9-dev $A $B $C;;
bookworm/sid|12.*|*)
apt install libc-dev libstdc++-11-dev libgcc-11-dev $A $B $C;;
esac
elif test -f /etc/fedora-release; then
$SUDO yum --assumeyes install libatomic
elif test -f /etc/arch-release; then
# installing gcc isn't my favorite thing, but even clang depends on it
# on archlinux. it provides libgcc. since we use it for testing, the risk
# to our builds is very low.
$SUDO pacman --noconfirm -Sy gcc libatomic_ops libxcrypt-compat
fi
}
_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 --silent --fail --proto '=https' -o "$tmpdir/pkgm" \
https://pkgxdev.github.io/pkgm/pkgm.ts
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'
install -m 755 "$tmpdir/pkgm" /usr/local/bin
" &
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
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
}
_should_install_pkgx() {
if [ ! -f /usr/local/bin/pkgx ]; then
return 0
elif _pkgx_is_old >/dev/null 2>&1; then
return 0
else
return 1
fi
}
_prep
if [ "$PKGX_INSTALL_PREREQS" != 1 ]; then
_main "$@"
else
_install_pre_reqs
fi