22 lines
602 B
Bash
Executable File
22 lines
602 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -u
|
|
|
|
error() {
|
|
echo >&2 "error: $*"
|
|
exit 1
|
|
}
|
|
|
|
# Make sure only root can run our script
|
|
(($( id -u) == 0)) || error "this script must be run as root!"
|
|
|
|
command -v sudo > /dev/null || error "sudo command not found!"
|
|
command -v openssl > /dev/null || error "openssl command not found!"
|
|
command -v psql > /dev/null || error "psql command not found!"
|
|
|
|
typeset -r DB_USER="airtime"
|
|
typeset -r DB_PASSWORD=$(openssl rand -hex 16)
|
|
|
|
echo "Changing password for database user '$DB_USER' to '$DB_PASSWORD'"
|
|
sudo -u postgres psql -c "ALTER USER $DB_USER WITH PASSWORD '$DB_PASSWORD';"
|