@@ -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
97109if _should_install_pkgx; then
98110 _install_pkgx " $@ "
111+ elif [ $# -eq 0 ]; then
112+ echo " pkgx already up-to-date" >&2
99113fi
100114
101115if _is_ci; then
0 commit comments