I made a script to remove Postgres if this is already installed on your system. I have a other script to install Postgres, so this script can be used before you going to install Postgres.
Do you like this script? I would love to hear feedback.
#!/bin/bash
#
#################################
#
# Script to remove Postgres
#
#################################
#function
prompt_ynq () {
echo -e "\e[01;31m${1}\e[00m"
PS3="Maak je keuze ('s' voor stop): "
INSTALL=false
select ANSWER in "ja" "nee"; do
case ${ANSWER} in
* ) INSTALL=${ANSWER}; break;;
esac
done
check_stop ${INSTALL}
}
#function
check_stop () {
if [ -z ${1} ]
then
echo -e "\n\e[01;31mYou've chosed to quit.\e[00m\n"
exit
fi
}
echo -e "\e[01;31mSearching for Postgres\e[00m"
sleep 3
echo ""
if [ -f postgres* ] && [ -f postgresql* ]
then
echo -e "\e[01;31mFound versions of Postgres:\e[00m"
dpkg -l | grep postgres
echo ""
prompt_ynq "Do you want to remove this versions of Postgres?"
if [ ${ANSWER} = "ja" ]
then
sudo apt-get --purge remove postgresql-* postgresql-client-* postgresql-client-common-* postgresql-common-* postgresql-contrib-*
sudo rm -rf /var/lib/postgresql/
sudo rm -rf /var/log/postgresql/
sudo rm -rf /etc/postgresql/
else
echo ""
echo -e "\e[01;31mYou've chosen to remove Postgres\e[00m"
echo ""
fi
else
echo "No Postgres found"
fi
