Skip to content

Commit 6c87d78

Browse files
committed
more robust self-update by using exec-spawned process
1 parent abb5f4c commit 6c87d78

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

kscript

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
## note: always use a patch release even if it's 0
4-
KSCRIPT_VERSION=1.5.0
4+
KSCRIPT_VERSION=1.5.1
55

66
## make sure that all requirements (java, kotlinc, maven) to run kscript are met
77
assertInPath(){ if [ -z "$(which $1)" ]; then echo "[ERROR] Could not locate '$1'" 1>&2; exit 1; fi }
@@ -94,12 +94,19 @@ if [[ "$1" == "--self-update" ]]; then
9494
## choose update strategy depending on installation type
9595
if [[ -z "$(which kscript | grep .sdkman)" ]]; then
9696
echo "Installing latest version of kscript..."
97-
kurl https://git.io/v9R73 > $(which kscript) && chmod u+x $(which kscript)
97+
kurl https://git.io/v9R73 > $(which kscript).tmp && chmod u+x $(which kscript).tmp
98+
99+
# Create and spawn update script (see this may not work https://stackoverflow.com/questions/8595751/is-this-a-valid-self-update-approach-for-a-bash-script)
100+
cat > ${KSCRIPT_CACHE_DIR}/self_update.sh <<EOF
101+
mv "$(which kscript).tmp" "$(which kscript)"
102+
echo "You're now running kscript "$(kscript --help 2>&1| grep Version | cut -f2- | tr -d ':')
103+
EOF
104+
exec /bin/bash ${KSCRIPT_CACHE_DIR}/self_update.sh
105+
98106
else
99107
sdkman_auto_answer=true && sdk install kscript
100108
fi
101109

102-
echo "You're now running kscript "$(kscript --help 2>&1| grep Version | cut -f2- | tr -d ':')
103110
exit 0
104111
fi
105112

0 commit comments

Comments
 (0)