Skip to content

Commit 80d1a39

Browse files
committed
Improve install / uninstall scripts
The install script now properly removes any existing copies of forceFullDesktopBar before proceeding with the installation, and both scripts now use a better method for restarting the Dock.
1 parent 033c703 commit 80d1a39

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

install/install.sh

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,63 @@ if [[ $EUID -ne 0 ]]; then
55
exit 1
66
fi
77

8-
# Remove bootstrap.dylib if it exists, since it's no longer needed
9-
if test -f "/usr/local/forceFullDesktopBar/bootstrap.dylib"; then
10-
rm /usr/local/forceFullDesktopBar/bootstrap.dylib
8+
# Deactivate old launchctl if it's running
9+
10+
prevPID=$(pgrep forceFullDesktopBar)
11+
12+
if [ ! -z "$prevPID" ]; then
13+
launchctlInfo=`launchctl list | grep net.briankendall.forceFullDesktopBar`
14+
15+
if [ -z "$launchctlInfo" ]; then
16+
killall -QUIT forceFullDesktopBar
17+
else
18+
echo Removing old launch daemon...
19+
launchctl remove net.briankendall.forceFullDesktopBar
20+
fi
21+
22+
echo "Waiting for previous forceFullDesktopBar to terminate..."
23+
while s=`ps -p $prevPID -o stat=` && [[ "$s" && "$s" != 'Z' ]]; do
24+
sleep 0.1
25+
done
26+
27+
echo "Restarting Dock..."
28+
interactiveUID=`scutil <<< "show State:/Users/ConsoleUser" | awk '/UID :/ { print $3 }'`
29+
# The safe way to restart the Dock:
30+
launchctl asuser $interactiveUID launchctl stop com.apple.Dock.agent
31+
launchctl asuser $interactiveUID launchctl start com.apple.Dock.agent
1132
fi
1233

13-
# Copy files:
1434
mkdir -p /usr/local/forceFullDesktopBar
1535
if [ "$?" -ne 0 ]; then echo "Failed to create /usr/local/forceFullDesktopBar"; exit 1; fi
1636

17-
cp forceFullDesktopBar /usr/local/forceFullDesktopBar/
37+
# Remove previous files if they exist
38+
# Apparently it's important to delete the existing files first, otherwise the
39+
# new dylibs may not be properly injected after loading the launch daemon.
40+
41+
if [ -f "/usr/local/forceFullDesktopBar/bootstrap.dylib" ]; then
42+
rm /usr/local/forceFullDesktopBar/bootstrap.dylib
43+
fi
44+
45+
if [ -f "/usr/local/forceFullDesktopBar/dockInjection.dylib" ]; then
46+
rm /usr/local/forceFullDesktopBar/dockInjection.dylib
47+
fi
48+
49+
if [ -f "/usr/local/forceFullDesktopBar/forceFullDesktopBar" ]; then
50+
rm /usr/local/forceFullDesktopBar/forceFullDesktopBar
51+
fi
52+
53+
if [ -f "/Library/LaunchDaemons/net.briankendall.forceFullDesktopBar.plist" ]; then
54+
rm /Library/LaunchDaemons/net.briankendall.forceFullDesktopBar.plist
55+
fi
56+
57+
cp forceFullDesktopBar /usr/local/forceFullDesktopBar/forceFullDesktopBar
1858
if [ "$?" -ne 0 ]; then echo "Could not copy forceFullDesktopBar. Make sure you're running this script in the directory that contains: forceFullDesktopBar, dockInjection.dylib, net.briankendall.forceFullDesktopBar.plist "; exit 1; fi
1959

20-
cp dockInjection.dylib /usr/local/forceFullDesktopBar/
60+
cp dockInjection.dylib /usr/local/forceFullDesktopBar/dockInjection.dylib
2161
if [ "$?" -ne 0 ]; then echo "Could not copy dockInjection.dylib. Make sure you're running this script in the directory that contains: forceFullDesktopBar, dockInjection.dylib, net.briankendall.forceFullDesktopBar.plist "; exit 1; fi
2262

2363
# Copy and launch daemon using launchctl:
24-
cp net.briankendall.forceFullDesktopBar.plist /Library/LaunchDaemons/
64+
cp -f net.briankendall.forceFullDesktopBar.plist /Library/LaunchDaemons/net.briankendall.forceFullDesktopBar.plist
2565
if [ "$?" -ne 0 ]; then echo "Could not copy LaunchDaemon plist. Make sure you're running this script in the directory that contains: forceFullDesktopBar, dockInjection.dylib, net.briankendall.forceFullDesktopBar.plist "; exit 1; fi
2666

2767
chown root:wheel /Library/LaunchDaemons/net.briankendall.forceFullDesktopBar.plist

install/uninstall.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if [[ $EUID -ne 0 ]]; then
55
exit 1
66
fi
77

8+
interactiveUID=`scutil <<< "show State:/Users/ConsoleUser" | awk '/UID :/ { print $3 }'`
9+
810
if test -f "/usr/local/forceFullDesktopBar/bootstrap.dylib"; then
911
rm /usr/local/forceFullDesktopBar/bootstrap.dylib
1012
fi
@@ -15,8 +17,19 @@ rmdir /usr/local/forceFullDesktopBar
1517
rm /Library/LaunchDaemons/net.briankendall.forceFullDesktopBar.plist
1618
launchctl remove net.briankendall.forceFullDesktopBar
1719

18-
# Give app a moment to fully quit:
19-
sleep 0.5
20-
killall Dock
20+
# Wait for app to fully quit:
21+
22+
prevPID=$(pgrep forceFullDesktopBar)
23+
if [ ! -z "$prevPID" ]; then
24+
echo "Waiting for forceFullDesktopBar to terminate..."
25+
while s=`ps -p $prevPID -o stat=` && [[ "$s" && "$s" != 'Z' ]]; do
26+
sleep 0.1
27+
done
28+
fi
29+
30+
echo "Restarting Dock..."
31+
# The safe way to restart the Dock:
32+
launchctl asuser $interactiveUID launchctl stop com.apple.Dock.agent
33+
launchctl asuser $interactiveUID launchctl start com.apple.Dock.agent
2134

2235
echo "Uninstalled"

0 commit comments

Comments
 (0)