2024-03-30 17:23:15 +01:00
|
|
|
#!/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
|
2024-10-16 18:52:00 +02:00
|
|
|
podman exec postgres psql -c "$stmt"
|
2024-03-30 17:23:15 +01:00
|
|
|
done
|