Skip to content

Commit 5ce9ef5

Browse files
committed
Introduce Max OS X (Mountain Lion) package uninstaller
1 parent e7aa9a5 commit 5ce9ef5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

pkguninstall

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
CMD=pkguninstall
4+
5+
if [ "$0" = "-bash" ]; then
6+
7+
function _pkguninstall_pkgs() {
8+
local cur
9+
cur="${COMP_WORDS[COMP_CWORD]}"
10+
COMPREPLY=( $( compgen -W "$(pkgutil --pkgs)" -- ${cur}) )
11+
}
12+
13+
complete -F _pkguninstall_pkgs $CMD
14+
return
15+
16+
fi
17+
18+
if [ $# = 0 ]; then
19+
cat >&2 <<_USAGE
20+
Usage:
21+
$CMD PKGID [--execute]
22+
23+
Without --execute parameter it will run in dry run mode.
24+
You will most likely need to run it through sudo.
25+
26+
Run this line to use command completion:
27+
. $CMD
28+
_USAGE
29+
exit 0
30+
fi
31+
32+
PKGID=$1
33+
EXECUTE=0
34+
if [ "$2" = "--execute" ]; then
35+
EXECUTE=1
36+
fi
37+
38+
echo "Package info:"
39+
pkgutil --pkg-info $PKGID
40+
echo ""
41+
cd /
42+
echo "Deleting $(pkgutil --only-files --files $PKGID | wc -l) files using sudo ..."
43+
pkgutil --only-files --files $PKGID | while read FILE; do
44+
[ -f "$FILE" ] && echo -e "\t/$FILE" && [[ $EXECUTE == 1 ]] && rm -f
45+
done
46+
echo "Files deleted."
47+
48+
echo "Pruning empty directories with sudo ... "
49+
pkgutil --only-dirs --files $PKGID | while read DIR; do
50+
[ -s "$DIR" ] && echo -e "\t/$DIR" && [[ $EXECUTE == 1 ]] && find "$DIR" -type d -empty -delete
51+
done
52+
echo "Empty directories deleted."
53+
54+
echo "Finally forget the package."
55+
[[ $EXECUTE == 1 ]] && pkgutil --forget $PKGID
56+
57+
echo ""
58+
echo "Package info (do we still have it?):"
59+
pkgutil --pkg-info $PKGID

0 commit comments

Comments
 (0)