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