Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- die() {
- echo "error: $@" >&2
- exit 1
- }
- test "$#" -gt 0 || die "Usage: $0 <package identifier>"
- test "$(uname -s)" = "Darwin" || die "Must be run under macOS"
- test $(id -u) -eq 0 || die "Must be root"
- which -s pkgutil || die "pkgutil not available. Install XCode"
- APP="$1"
- pkgutil --pkg-info "$APP" > /dev/null || die "No found app by this package identifier"
- for key in volume location
- do
- EXP="^$key: "
- VAL=$(pkgutil --pkg-info "$APP" | grep "$EXP" | sed "s/$EXP//")
- eval $key=\$VAL
- done
- BASE="$volume$location"
- test -d "$BASE" || die "Resolved base directory '$BASE' doesn't exist"
- pushd "$BASE"
- pkgutil --only-files --files "$APP" | tr '\n' '\0' | xargs -0 -n 1 rm
- pkgutil --only-dirs --files "$APP" | sort -r | tr '\n' '\0' | xargs -0 -n 1 rmdir
- popd
- pkgutil --forget "$APP" || die "Failed to remove the package from the database"
- echo "Done."
Add Comment
Please, Sign In to add comment