Last active
April 27, 2024 10:57
-
-
Save TomMannson/20b2ccae83744860cf01657528c927df to your computer and use it in GitHub Desktop.
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 | |
# Check if the correct number of arguments were provided | |
if [ "$#" -ne 3 ]; then | |
echo "Usage: $0 <DATABASE_NAME> <USERNAME> <PASSWORD>" | |
exit 1 | |
fi | |
DB_NAME=$1 | |
USER_NAME=$2 | |
USER_PASS=$3 | |
#### POSTGRESS DB Config | |
# Confirm PostgreSQL installation | |
sudo -u postgres psql -c "SELECT version();" | |
sudo -u postgres psql -c "CREATE DATABASE $DB_NAME;" | |
sudo -u postgres psql -c "CREATE USER $USER_NAME WITH PASSWORD '$USER_PASS';" | |
# Grants that allow to make all necesary changes | |
sudo -u postgres psql -c "GRANT ALL ON SCHEMA public TO $USER_NAME;" | |
sudo -u postgres psql -c "GRANT ALL ON DATABASE $DB_NAME TO $USER_NAME;" | |
sudo -u postgres psql -c "ALTER DATABASE $DB_NAME OWNER TO $USER_NAME;" | |
sudo -u postgres psql -c "ALTER ROLE $USER_NAME SUPERUSER;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment