uninstall_polipo_bundle.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. #
  3. ### this is the location of a file which contains all the actual package names
  4. ## (ie "Polipo", "polipostartup", ...) the list should be new-line-delimited.
  5. PACKAGE_LIST_SRC="Polipo polipostartup"
  6. ### this is the name of the user created in the install process of Polipo
  7. POLIPO_USER=_polipo
  8. ### these should be constant across all osX installs (so leave them be)
  9. STARTUP_ITEMS_DIR=/Library/StartupItems
  10. PKG_RCPT_BASE_DIR=/Library/Receipts
  11. BOM_INTERMEDIATE_DIR=Contents/Resources
  12. INFO_INTERMEDIATE_DIR=$BOM_INTERMEDIATE_DIR/English.lproj
  13. TEMP_BOM_CONTENTS=/tmp/polipo_uninst_scratch
  14. ### make sure the script is being run as root, barf if not
  15. if [ "`whoami`" != "root" ]; then
  16. echo "Must be root to run the uninstall script."
  17. exit -1
  18. fi
  19. ### check to see if polipo is currently running, kill it if it is
  20. ## we grep on 'Polipo/polipo ' because 'polipo' is too common (like in 'direcpolipoy')
  21. ## -- this relies on the fact that polipo has been started with command
  22. ## line arguments.. :-/
  23. POLIPO_PID=`ps -uax | grep 'Polipo/polipo ' | grep -v grep | awk '{print $2;}'`
  24. if [ ${#POLIPO_PID} -gt 0 ]; then
  25. echo ". Killing currently running polipo process, pid is $POLIPO_PID"
  26. kill -9 $POLIPO_PID
  27. else
  28. echo ". polipo process appears to already be stopped"
  29. fi
  30. ## grab each package name from the package list file
  31. while read LINE; do
  32. if [ ${#LINE} -gt 0 ]; then
  33. PACKAGE_NAME=$LINE.pkg
  34. PACKAGE_PATH=$PKG_RCPT_BASE_DIR/$PACKAGE_NAME
  35. echo ". Uninstalling $PACKAGE_NAME"
  36. if [ ! -d $PACKAGE_PATH ]; then
  37. echo " . No receipt exists for this package -- skipping."
  38. continue
  39. fi
  40. ## get rid of the startup item if it exists
  41. STARTUP_DIR=$STARTUP_ITEMS_DIR/$LINE
  42. if [ -d $STARTUP_DIR ]; then
  43. echo " . Deleting startup item $STARTUP_DIR"
  44. rm -rf $STARTUP_DIR
  45. fi
  46. ## determine the root direcpolipoy of the the relative paths specified in the bom
  47. DEFAULT_LOC=`grep DefaultLocation $PACKAGE_PATH/$INFO_INTERMEDIATE_DIR/$LINE.info | awk '{print $2;}'`
  48. if [ ${#DEFAULT_LOC} -eq 0 ]; then
  49. echo "!! Could not find default location for $LINE package -- skipping package."
  50. continue
  51. fi
  52. ## examine the list of installed items desribed in the bom
  53. BOM_FILE=$PACKAGE_PATH/$BOM_INTERMEDIATE_DIR/$LINE.bom
  54. lsbom $BOM_FILE > $TEMP_BOM_CONTENTS
  55. while read BOM_ITEM; do
  56. ## 3 column items describe just direcpolipoies, 5 column items describe actual files
  57. COL_COUNT=$(echo $BOM_ITEM | awk '{print NF;}')
  58. if [ "$COL_COUNT" -eq 5 ]; then
  59. FILE_NAME=$DEFAULT_LOC/$(echo $BOM_ITEM | awk '{print $1;}')
  60. echo " . Removing $FILE_NAME"
  61. rm -rf $FILE_NAME
  62. fi
  63. done < $TEMP_BOM_CONTENTS
  64. ## remove package receipt
  65. echo " . Removing package receipt $PACKAGE_PATH"
  66. rm -rf $PACKAGE_PATH
  67. fi
  68. done < $PACKAGE_LIST_SRC
  69. ## nuke the user created by the install process.
  70. echo ". Removing created user $POLIPO_USER"
  71. niutil -destroy . /users/$POLIPO_USER
  72. ## clean up
  73. echo ". Cleaning up"
  74. rm -rf $TEMP_BOM_CONTENTS
  75. rm -rf /Library/Polipo/ /Library/StartupItems/Polipo/
  76. echo ". Finished"