Skip to content

Commit b2944f2

Browse files
authored
Work even if active pkgx is not /usr/local/bin/pkgx (#203)
1 parent b5d42ce commit b2944f2

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

.github/workflows/ci.installer.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ jobs:
4040
container: debian:buster-slim
4141
steps:
4242
- uses: actions/checkout@v4
43+
- uses: actions/checkout@v4
44+
with:
45+
ref: curl
46+
path: bin
4347
- run: ./installer.sh
4448
env:
4549
PATH: ${{ github.workspace }}/bin:/usr/bin:/bin

installer.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ _install_pkgx() {
5454
tmpdir=$(mktemp -d)
5555

5656
if [ $# -eq 0 ]; then
57-
echo "Installing: /usr/local/bin/pkgx" >&2
57+
if [ -f /usr/local/bin/pkgx ]; then
58+
echo "upgrading: /usr/local/bin/pkgx" >&2
59+
else
60+
echo "installing: /usr/local/bin/pkgx" >&2
61+
fi
5862

5963
# using a named pipe to prevent curl progress output trumping the sudo password prompt
6064
pipe="$tmpdir/pipe"
@@ -69,33 +73,43 @@ _install_pkgx() {
6973

7074
rm -r "$tmpdir"
7175

72-
export PATH="/usr/local/bin:$PATH" # just in case
76+
if [ "$(command which pkgx)" != /usr/local/bin/pkgx ]; then
77+
echo "warning: active pkgx is not /usr/local/bin/pkgx" >&2
78+
export PATH="/usr/local/bin:$PATH" # so we can exec if required
79+
fi
80+
81+
# tell the user what version we just installed
82+
pkgx --version
83+
7384
else
7485
curl $progress --fail --proto '=https' \
7586
"https://pkgx.sh/$(uname)/$(uname -m)".tgz \
7687
| tar xz --directory "$tmpdir"
7788

7889
export PATH="$tmpdir:$PATH"
90+
export PKGX_DIR="$tmpdir"
7991
fi
8092

8193
unset tmpdir pipe
8294
}
8395

8496
_should_install_pkgx() {
85-
if [ -x /usr/local/bin/pkgx ] && [ -f /usr/local/bin/pkgx ]; then
97+
if [ ! -f /usr/local/bin/pkgx ]; then
98+
return 0
99+
else
86100
# if the installed version is less than the available version then upgrade
87101
/usr/local/bin/pkgx --silent semverator gt \
88102
$(curl -Ssf https://pkgx.sh/VERSION) \
89103
$(/usr/local/bin/pkgx --version | awk '{print $2}') >/dev/null 2>&1
90-
else
91-
return 0
92104
fi
93105
}
94106

95107
########################################################################### meat
96108

97109
if _should_install_pkgx; then
98110
_install_pkgx "$@"
111+
elif [ $# -eq 0 ]; then
112+
echo "pkgx already up-to-date" >&2
99113
fi
100114

101115
if _is_ci; then

0 commit comments

Comments
 (0)