uninstall_polipo_bundle.sh 3.1 KB

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