Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. #!/bin/bash
  2. #date: 28/06/2017, author: nbodev
  3. #remove package from mac os
  4. # tested on mac os Sierra
  5.  
  6. #steps
  7. #pkgutil --pkgs # list all installed packages
  8. #pkgutil --files the-package-name.pkg # list installed files for a given package
  9. #pkgutil --pkg-info the-package-name.pkg # check the location of a given package
  10. #cd / # assuming the package is rooted at /...
  11. #pkgutil --only-files --files the-package-name.pkg | tr '\n' '\0' | xargs -n 1 -0
  12. #pkgutil --only-files --files the-package-name.pkg | tr '\n' '\0' | xargs -n 1 -0 sudo rm -f
  13. #pkgutil --only-dirs --files the-package-name.pkg | tail -r | tr '\n' '\0' | xargs -n 1 -0
  14. #pkgutil --only-dirs --files the-package-name.pkg | tail -r | tr '\n' '\0' | xargs -n 1 -0 sudo rmdir
  15. #sudo pkgutil --forget the-package-name.pkg
  16. #pkgutil --files the-package-name.pkg # list installed files
  17.  
  18.  
  19.  
  20. read -p "Enter package name: " name
  21. pkgutil --pkgs | grep -i $name
  22. read -p "Enter the package full name (e.g. the-package-name.pkg): " full_name
  23. echo "************ running pkgutil --files $full_name"
  24. pkgutil --files $full_name
  25. if [ $? == 0 ]; then #package name correct
  26. echo "************ running pkgutil --pkg-info $full_name"
  27. pkgutil --pkg-info $full_name
  28.  
  29. read -p "Step 1/2 => Continue scanning the package, nothing will be deleted ? (Y)" answer
  30. if [ $answer == "Y" ]; then
  31. cd / # assuming the package is rooted at /...
  32. echo "************ running pkgutil --only-files --files $full_name | tr '\n' '\0' | xargs -n 1 -0"
  33. pkgutil --only-files --files $full_name | tr '\n' '\0' | xargs -n 1 -0
  34. echo "************ running pkgutil --only-dirs --files $full_name | tail -r | tr '\n' '\0' | xargs -n 1 -0"
  35. pkgutil --only-dirs --files $full_name | tail -r | tr '\n' '\0' | xargs -n 1 -0
  36. else
  37. echo "Aborting Step 1/2 ..."
  38. exit 0
  39. fi
  40.  
  41. read -p "Step 2/2 => Danger zone: delete the package ? (Y)" answer_danger
  42. if [ $answer_danger == "Y" ]; then
  43. cd / # assuming the package is rooted at /...
  44.  
  45. echo "************ running pkgutil --only-files --files $full_name | tr '\n' '\0' | xargs -n 1 -0 sudo rm -f"
  46. pkgutil --only-files --files $full_name | tr '\n' '\0' | xargs -n 1 -0 sudo rm -f
  47.  
  48. echo "************ running pkgutil --only-dirs --files $full_name | tail -r | tr '\n' '\0' | xargs -n 1 -0 sudo rmdir"
  49. pkgutil --only-dirs --files $full_name | tail -r | tr '\n' '\0' | xargs -n 1 -0 sudo rmdir
  50.  
  51. echo "************ running sudo pkgutil --forget $full_name"
  52. sudo pkgutil --forget $full_name
  53.  
  54. echo "************ running pkgutil --files $full_name" #run again to check if the package is still here or not
  55. pkgutil --files $full_name
  56. else
  57. echo "Aborting Step 2/2 ..."
  58. exit 0
  59. fi
  60. else
  61. echo "looks like the the package full name is wrong " $full_name
  62. exit 1
  63. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement