diff --git a/scripts/update-app.sh b/scripts/update-app.sh index d40779c..06e0c1a 100755 --- a/scripts/update-app.sh +++ b/scripts/update-app.sh @@ -28,13 +28,24 @@ if ! ./gradlew :app:createDistributable -q; then fi # Stop the app (and its engine) only AFTER a good build exists. +# NEVER match our own lineage: pkill -f also matches any ancestor shell +# whose command line merely mentions this script's path. +_selfpids() { local p=$$; while [ "$p" -gt 1 ]; do echo "$p"; p=$(ps -o ppid= -p "$p" 2>/dev/null | tr -d ' '); [ -z "$p" ] && break; done; } +_killpat() { + local pat="$1" pid + for pid in $(pgrep -f "$pat" 2>/dev/null); do + case " $(_selfpids) " in *" $pid "*) continue;; esac + # also skip the pgrep call itself via its subshell parent already covered + kill "$pid" 2>/dev/null + done +} # Packaged runs appear as .../bin/shonar-desktop; dev runs as java MainKt. -pkill -f 'com.shonar.desktop.MainKt' 2>/dev/null -pkill -f 'shonar-desktop/bin/shonar-desktop' 2>/dev/null -pkill -f 'uvicorn shonar.main:app' 2>/dev/null +_killpat 'com.shonar.desktop.MainKt' +_killpat 'shonar-desktop/bin/shonar-desktop' +_killpat 'uvicorn shonar.main:app' sleep 2 # Last resort: anything still holding a SHONAR window. -pkill -f 'shonar-desktop' 2>/dev/null +_killpat 'shonar-desktop' sleep 2 bin="$repo/app/build/compose/binaries/main/app/shonar-desktop/bin/shonar-desktop"