-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsetup-postgres
More file actions
executable file
·47 lines (36 loc) · 1.28 KB
/
setup-postgres
File metadata and controls
executable file
·47 lines (36 loc) · 1.28 KB
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
40
41
42
43
44
45
46
47
#!/bin/bash
set -e
cd "$( dirname "${BASH_SOURCE[0]}" )" && cd ../
# Initial One-Time Postgres Setup
PS_USER="root"
PS_USER_HOME=$( getent passwd "$PS_USER" | cut -d: -f6 )
DB_USER="printspool"
if [[ "$RUST_ENV" == "development" ]]; then
DB_USER="printspool-dev"
fi
DB=$DB_USER
DB_PASSWORD=`apg -n 1 -m 64 -M NCL -E \:\'\"\\`
# Renaming v0.16.2 User and Database
if [ -f /usr/local/etc/printspool/common/.needs_0_16_2_pg_patch ]; then
ALTER USER teg RENAME TO $DB_USER || true
ALTER DATABASE teg RENAME TO $DB || true
else
sudo -u postgres createuser -d $DB_USER || true
sudo -u postgres createdb -O $DB_USER $DB || true
fi
sudo -u postgres psql -c "ALTER USER $DB_USER WITH PASSWORD '$DB_PASSWORD';"
sudo -u $PS_USER touch $PS_USER_HOME/.pgpass
sudo -u $PS_USER chmod 0600 $PS_USER_HOME/.pgpass
# Remove old pgpass entries
sudo -u $PS_USER sed -i "/localhost\:\*\:$DB\:$DB_USER/d" $PS_USER_HOME/.pgpass
# Add new pgpass entry
PG_PASS_LINE="localhost:*:$DB:$DB_USER:$DB_PASSWORD"
sudo -u $PS_USER sh -c "echo \"$PG_PASS_LINE\" >> $PS_USER_HOME/.pgpass"
if [[ "$RUST_ENV" == "development" ]]; then
touch ~/.pgpass
chmod 0600 ~/.pgpass
# Remove old pgpass entries
sed -i "/localhost\:\*\:$DB\:$DB_USER/d" ~/.pgpass
# Add new pgpass entry
echo "$PG_PASS_LINE" >> ~/.pgpass
fi