Skip to content

Instantly share code, notes, and snippets.

@anurag-roy
Created September 15, 2021 09:59
Show Gist options
  • Save anurag-roy/4557a8be0a45cd0e19e454ab7acad06b to your computer and use it in GitHub Desktop.
Save anurag-roy/4557a8be0a45cd0e19e454ab7acad06b to your computer and use it in GitHub Desktop.
# Install Postgres if not exists
which psql
if [ "$?" -ne 0 ]
then
echo "Installing Postgres..."
sudo apt-get install postgresql --yes
echo "Altering password for user 'postgres'"
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';"
else
echo "Postgres is installed. Skipping installation..."
fi
# Uninstall postgresql
sudo apt-get --purge remove $(dpkg -l | grep postgres | awk '{ ORS = " " } {print $2}') --yes
# Delete 'postgres' user
sudo deluser postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment