Skip to content

Instantly share code, notes, and snippets.

@vanpelt
Created January 11, 2009 22:13
Show Gist options
  • Save vanpelt/45818 to your computer and use it in GitHub Desktop.
Save vanpelt/45818 to your computer and use it in GitHub Desktop.
rm #!/bin/sh
# clean up the previous installation so we can test it again.
echo
echo \# This script will attempt to remove all vestiges of a PostgreSQL8 installation
echo \# -----------------------------------------------------------------------------
echo \#
# make sure that we are running as root
x=`whoami | grep root`
if (! test -n "$x") then
echo \# You must be root \(sudo\) to have sufficient rights to remove the
echo \# folders and files that need to be removed.
exit 0
fi
#set -e
echo \# User: $x
# make sure the database is shutdown
echo \# Stopping the Database
/Library/StartupItems/PostgreSQL/PostgreSQL stop
echo \# ...done
# remove the user and group from the netinfo database
echo \# Removing NetInfo entries
PG_UID=`/usr/bin/dscl . -read /users/postgres | grep "^UniqueID:.[0-9]" | sed 's/.*: //' | sed 's/ //'`
# User exists
if test $PG_UID; then
sudo /usr/bin/dscl . -delete /users/postgres
echo \# ...Deleted Postgres User: $PG_UID
fi
PG_GID=`/usr/bin/dscl . read /groups/postgres PrimaryGroupID | grep "PrimaryGroupID:.[0-9]" | sed 's/.*: //' | sed 's/ //'`
# Group Exist, destroy it
if test $PG_GID; then
sudo /usr/bin/dscl . -delete /groups/postgres
echo \# ...Deleted Postgres Group: $PG_GID
fi
echo \# ...done
# remove the log files
echo \# Removing Logs \& Receipts
sudo rm -f /Library/Logs/PostgreSQL8.log
sudo rm -rf /Library/Receipts/postgresql830Postflight.pkg
sudo rm -rf /Library/Receipts/postgresql.pkg
sudo rm -rf /Library/Receipts/queryToolForPostgres.pkg
sudo rm -rf /Library/Receipts/createUser.pkg
sudo rm -rf /Library/Receipts/createDatabase.pkg
sudo rm -rf /Library/Receipts/serviceManager.pkg
sudo rm -rf /Library/Receipts/backupDatabase.pkg
sudo rm -rf /Library/Receipts/uninstallPostgresqlServer.pkg
sudo rm -rf /Library/Receipts/postgreSQL8.pkg
echo \# ...done
# remove the directories
echo \# Removing Files and Folders
sudo rm -rf /Library/PostgreSQL8
sudo rm -rf /Library/StartupItems/PostgreSQL
sudo rm -rf /Applications/PostgreSQL
echo \# ...done
echo \#
echo \# -----------------------------------------------------------------------------
echo \# PostgreSQL8 has been removed from the system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment