Skip to content

Commit c7dde5d

Browse files
committed
uninstall: generalize uninstaller script
To prepare for an install-from-source target in the Makefile, create a general (Unix) 'uninstall.sh' script. This script is nearly identical to 'build/package/pkg/uninstall.sh', with a few notable differences: 1. The script does not run as 'root' by calling itself with 'sudo'; instead, operations that may require root privileges are first tried as the calling user and, if they fail, are called again with 'sudo'. 2. If the script is run with 'sudo' (or otherwise as 'root'), the user is prompted to confirm whether they want to proceed. These changes help us avoid platform-specific code around finding the current logged in user to run 'git-bundle-server web-server stop'. Signed-off-by: Victoria Dye <[email protected]>
1 parent 1193883 commit c7dde5d

File tree

3 files changed

+68
-47
lines changed

3 files changed

+68
-47
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ $(PKGDIR)/payload: check-arch build
8484
@echo
8585
@echo "======== Formatting package contents ========"
8686
@build/package/layout-unix.sh --bindir="$(BINDIR)" \
87-
--uninstaller="$(CURDIR)/build/package/pkg/uninstall.sh" \
87+
--uninstaller="$(CURDIR)/scripts/uninstall.sh" \
8888
--output="$(PKGDIR)/payload"
8989

9090
$(PKG_FILENAME): check-version $(PKGDIR)/payload

build/package/pkg/uninstall.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

scripts/uninstall.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Setup root escalation operation
5+
SUDO=$(if command -v sudo >/dev/null 2>&1; then echo sudo; fi)
6+
retry_root () {
7+
$@ 2>/dev/null || "$SUDO" $@
8+
}
9+
10+
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
11+
PATH_TO_BIN_SYMLINKS="$THISDIR/../bin"
12+
PATH_TO_MAN_SYMLINKS="$THISDIR/../share/man"
13+
14+
# Ensure we're running as root
15+
if [ $(id -u) == "0" ]
16+
then
17+
echo
18+
echo "WARNING: running this script as root will not remove user-scoped resources such"
19+
echo "as daemon configurations."
20+
echo
21+
read -p "Are you sure you want to proceed? (y/N) " response
22+
case $response in
23+
[yY]*)
24+
break # do nothing
25+
;;
26+
[nN]*|"")
27+
exit 0 # exit
28+
;;
29+
*)
30+
echo "Invalid response: $response"
31+
;;
32+
esac
33+
fi
34+
35+
"$THISDIR/bin/git-bundle-server" web-server stop --remove
36+
37+
# Remove symlinks
38+
for program in "$THISDIR"/bin/*
39+
do
40+
symlink="$PATH_TO_BIN_SYMLINKS/$(basename $program)"
41+
if [ -L "$symlink" ]
42+
then
43+
echo "Deleting '$symlink'..."
44+
retry_root rm -f "$symlink"
45+
else
46+
echo "No symlink found at path '$symlink'."
47+
fi
48+
done
49+
50+
# Remove application files
51+
if [ -d "$THISDIR" ]
52+
then
53+
echo "Deleting application files in '$THISDIR'..."
54+
retry_root rm -rf "$THISDIR"
55+
else
56+
echo "No application files found."
57+
fi
58+
59+
# If installed via MacOS .pkg, remove package receipt
60+
PKG_ID=com.github.gitbundleserver
61+
if command -v pkgutil >/dev/null 2>&1 && pkgutil --pkgs=$PKG_ID >/dev/null 2>&1
62+
then
63+
# Must run as root
64+
$SUDO pkgutil --forget $PKG_ID
65+
fi
66+
67+
exit 0

0 commit comments

Comments
 (0)