24 lines
453 B
Bash
Executable file
24 lines
453 B
Bash
Executable file
#!/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
|
|
podman exec postgres psql -c "$stmt"
|
|
done
|