Skip to content

Commit

Permalink
Support auto-updating in the script
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Mar 25, 2024
1 parent 92f4dfb commit 09ab26d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion etc/prefix1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

declare javaCmd portFile pidFile ttystate script tmpPipe dataHomeDir data stderr javaBundle
declare javaCmd portFile pidFile ttystate script tmpPipe dataHomeDir data stderr javaBundle pendingUpdate
declare -i doDownload minimumJava preferredJava pid port version buildId stdoutPid stderrPid continue pipePid argCount launchPid payloadSize jarSize
declare -a args signals sttyOptions

Expand All @@ -25,6 +25,7 @@ javaHome="$dataHomeDir/java"
javaBundle="jre"
javaDefault="${javaHome}/${preferredJava}-${javaBundle}"
continue=1
pendingUpdate="${dataHomeDir}/${name}/.pending"

[[ "$1" = "--download" ]] && doDownload=1 && shift
pid=$$
Expand All @@ -47,6 +48,16 @@ abort() {
touch "$failFile"
}

checkUpdates() {
if [ -s "${pendingUpdate}" ]
then
chmod +x "${pendingUpdate}"
mv "${invocation}" "${dataHomeDir}/${name}.old"
mv "${pendingUpdate}" "${invocation}"
exec "${invocation}" "${args[@]}"
fi
}

operatingSystem() {
case "$(uname -s)" in
Linux|GNU*) printf "linux" ;;
Expand Down Expand Up @@ -155,6 +166,7 @@ findJava() {
}

launch() {
checkUpdates
findJava
startTime="$(date +%s%3N)"
echo "$pid" > "$pidFile"
Expand Down

0 comments on commit 09ab26d

Please sign in to comment.