summaryrefslogtreecommitdiffstats
path: root/Services/postgres/postgres_modify_pass.sh
blob: d76e189649a0210f03452b26a431ae9dece797e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

if [ -f /.postgres_pass_modified ]; then
    echo "PostgreSQL 'postgres' user pass already modified!"
    exit 0
fi

#generate pasword
PASS=${POSTGRES_PASS:-$(pwgen -s 12 1)}
_word=$( [ ${POSTGRES_PASS} ] && echo "preset" || echo "random" )

echo "=> Modifying 'postgres' user with a ${_word} password in PostgreSQL"
sudo -u postgres psql -U postgres -d postgres -c "alter user postgres with password '$PASS';"
echo "=> Done!"
touch /.postgres_pass_modified

echo "========================================================================"
echo "You can now connect to this PostgreSQL Server using:"
echo ""
echo "    psql -h <host> -p <port> --username=postgres"
echo "and enter the password '$PASS' when prompted"
echo ""
echo "Please remember to change the above password as soon as possible!"
echo "========================================================================"