~doma/do-auth

ref: 03fa8d5dd3e3d88f7f4ee643651af8bdf8f7b0f9 do-auth/priv/dev/create-role-phoenix.sh -rwxr-xr-x 1.0 KiB
03fa8d5dJonn Problem: No PostgreSQL available 13 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash

set -euo pipefail

_pw_phoenix=$(mix phx.gen.secret)
_pw_root=$(mix phx.gen.secret)
_user=$(whoami)
cat >/tmp/run.sql <<EOF
create role phoenix with password '${_pw_phoenix}';
alter role phoenix with login;
alter role phoenix createdb;
alter role ${_user} with password '${_pw_root}';
alter role ${_user} with login;
EOF
/usr/lib/postgresql/12/bin/psql -h 127.0.0.1 -d postgres -f /tmp/run.sql
rm /tmp/run.sql
cat <<EOF
Created role 'phoenix' with password ${_pw_phoenix}
Save this password to your configuration!
For demonstration purposes, restricted local logins to password-based logins.
New password for user ${_user} is ${_pw_root}. Saving this password to ~/.pgpass ...
EOF
echo -n "127.0.0.1:5432:postgres:${_user}:${_pw_root}" >> ~/.pgpass
chmod 0600 ~/.pgpass
echo "Done!"

cat <<EOF

* * *
Now saving phoenix password into ./config/dev.secret.exs
EOF

cat >> config/dev.secret.exs <<EOF

config :do_auth, DoAuth.Repo, username: "phoenix", password: "${_pw_phoenix}"

EOF
chmod 0600 config/dev.secret.exs
echo "Done!"