Last active
September 15, 2015 14:13
-
-
Save esbullington/548f3b7e51273f61be43 to your computer and use it in GitHub Desktop.
Bash script for easy bootstrapping a PostgreSQL database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
make_database () { | |
sudo -u postgres psql -d template1 -U postgres -c "CREATE USER $db_user WITH PASSWORD '$db_password';"; | |
sudo -u postgres psql -d template1 -U postgres -c "CREATE DATABASE $db_name;"; | |
sudo -u postgres psql -d template1 -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $db_name to $db_user;"; | |
sudo service postgresql restart; | |
} | |
echo "Please enter a database user: " | |
read -e db_user | |
echo "You entered: $db_user" | |
echo "Please enter a database name: " | |
read -e db_name | |
echo "You entered: $db_name" | |
echo "Please enter a database password: " | |
read -e -s db_password | |
echo "You entered: $db_password" | |
while true; do | |
echo "You selected database $db_name owned by user $db_user and your selected password." | |
read -p "Do you wish to configure this database? (y/n) " yn | |
case $yn in | |
[Yy]* ) echo "configuring...."; make_database; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment