From 9201b435dfde4268d391b6eddbccc6566c8fe50c Mon Sep 17 00:00:00 2001 From: Nathan Fritzer Date: Wed, 7 May 2025 22:04:59 -0600 Subject: [PATCH] fix: stop all running darling servers on uninstall fix: quotes are needed with test UNIX util fix: privilage checking --- tools/shutdown-user.sh | 19 +++++++++++++++---- tools/uninstall | 9 ++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tools/shutdown-user.sh b/tools/shutdown-user.sh index e95b4d697..072a6e244 100755 --- a/tools/shutdown-user.sh +++ b/tools/shutdown-user.sh @@ -1,15 +1,26 @@ +#!/bin/sh + +if [ "$(whoami)" != "root" ] +then + echo "$0 must be run as root, invoking sudo" + exec sudo su -c "$0" "$@" +fi + echo "Seeing if Darling is currently running" -PID=`pgrep launchd` +# Sometimes `pgrep launchd` doesn't work when `pgrep -f launchd` does. Not sure +# if we want to include arguments (and capture rare, but possible false +# positives). +PID=$(pgrep -f launchd) -while [[ ! -z $PID ]] +while [ -n "$PID" ] do THISPID=$(echo $PID | head -n1) RUNNING_USER=$(ps -o uname= -p $THISPID | head -n1) echo "Darling currently running for $RUNNING_USER, shutting it down..." - sudo -u $RUNNING_USER darling shutdown + su --login "$RUNNING_USER" -c "darling shutdown" sleep 2 - PID=`pgrep launchd` + PID=$(pgrep -f launchd) done echo "No instances running now" diff --git a/tools/uninstall b/tools/uninstall index 1ba90233e..034bad65d 100755 --- a/tools/uninstall +++ b/tools/uninstall @@ -4,16 +4,15 @@ set +e if [ "$(whoami)" != "root" ] then echo "Uninstall must be run as root, invoking sudo" - sudo su -c "$0" - exit + exec sudo su -c "$0" "$@" fi -INSTALL_PREFIX="$(dirname "$(dirname "$(which darling)")")" - if command -v darling then - darling shutdown + $(dirname "$0")/shutdown-user.sh fi + +INSTALL_PREFIX="$(dirname "$(dirname "$(which darling)")")" if [ -d "${INSTALL_PREFIX}/libexec" ] then rm -rf "${INSTALL_PREFIX}/libexec/darling" -- 2.51.2