25 lines
453 B
Bash
25 lines
453 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
read -rp "Database: " database
|
||
|
|
||
|
read -rp "User: " user
|
||
|
|
||
|
read -srp "Password: " password
|
||
|
|
||
|
echo ""
|
||
|
read -rp "Create database $database & user $user? [Y/n]: " answer
|
||
|
|
||
|
if ! [[ $answer =~ ^(Y|y)?$ ]]; then
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
stmts=(
|
||
|
"CREATE USER $user PASSWORD '$password'"
|
||
|
"CREATE DATABASE $database WITH OWNER = $user"
|
||
|
"GRANT ALL ON DATABASE $database TO $user"
|
||
|
)
|
||
|
|
||
|
for stmt in "${stmts[@]}"; do
|
||
|
docker exec postgres psql -c "$stmt"
|
||
|
done
|