Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. die() {
  4. echo "error: $@" >&2
  5. exit 1
  6. }
  7.  
  8. test "$#" -gt 0 || die "Usage: $0 <package identifier>"
  9. test "$(uname -s)" = "Darwin" || die "Must be run under macOS"
  10. test $(id -u) -eq 0 || die "Must be root"
  11. which -s pkgutil || die "pkgutil not available. Install XCode"
  12.  
  13. APP="$1"
  14.  
  15. pkgutil --pkg-info "$APP" > /dev/null || die "No found app by this package identifier"
  16. for key in volume location
  17. do
  18. EXP="^$key: "
  19. VAL=$(pkgutil --pkg-info "$APP" | grep "$EXP" | sed "s/$EXP//")
  20. eval $key=\$VAL
  21. done
  22.  
  23. BASE="$volume$location"
  24.  
  25. test -d "$BASE" || die "Resolved base directory '$BASE' doesn't exist"
  26.  
  27. pushd "$BASE"
  28. pkgutil --only-files --files "$APP" | tr '\n' '\0' | xargs -0 -n 1 rm
  29. pkgutil --only-dirs --files "$APP" | sort -r | tr '\n' '\0' | xargs -0 -n 1 rmdir
  30. popd
  31.  
  32. pkgutil --forget "$APP" || die "Failed to remove the package from the database"
  33.  
  34. echo "Done."
Add Comment
Please, Sign In to add comment