Last active
December 5, 2018 11:50
-
-
Save carlessanagustin/04918754207fa047ba66ec68674dbee4 to your computer and use it in GitHub Desktop.
Postgresql database and user creation - wget -O - https://bit.ly/2AOIw22 | bash -s <DB_HOST> <DB_NAME> <DB_USER> <DB_PASS>
This file contains hidden or 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
#!/usr/bin/env bash | |
DB_HOST=$1 | |
DB_NAME=$2 | |
DB_USER=$3 | |
DB_PASS=$4 | |
psql "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=$DB_HOST port=5432 user=postgres" << EOF | |
CREATE DATABASE $DB_NAME ; | |
CREATE USER $DB_USER WITH ENCRYPTED PASSWORD '$DB_PASS' ; | |
GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER ; | |
EOF | |
echo "LIST DATABASES..." | |
psql "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=$DB_HOST port=5432 user=postgres" --list | |
echo "USAGE: " | |
echo psql \"sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=$DB_HOST port=5432 user=$DB_USER dbname=$DB_NAME\" | |
: ' | |
## HELP ## | |
show database = \l | |
show users = \du | |
drop database $DB_NAME; | |
drop user $DB_USER ; | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment