-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker-entrypoint.sh
70 lines (62 loc) · 4.73 KB
/
docker-entrypoint.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
#SET THE TIMEZONE
apk add --update tzdata
cp "/usr/share/zoneinfo/$TIME_ZONE" /etc/localtime
echo "$TIME_ZONE" > /etc/timezone
apk del tzdata
#PREPARE THE PERMISSIONS FOR VOLUMES
chown -R root:root /config
chmod -R 755 /config
mv -n /apache.conf /config/apache.conf
mv -n /davical.php /config/davical.php
mv -n /rsyslog.conf /config/rsyslog.conf
sed -i "s@host=example@host=$DBHOST@" /config/davical.php
sed -i "s@password=example@password=$PASSDAVDB@" /config/davical.php
chown -R root:root /config
chmod -R 755 /config
chown root:apache /config/davical.php
chmod u+rwx,g+rx /config/davical.php
sleep 15
/usr/bin/pg_isready -U postgres -h "$DBHOST" -t 2000
#UPDATING FROM OLD VERSION OR NOT
UPDATE_FROM_OLD=false
INITIALIZED_DB=$(PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -l | grep davical)
if [[ -z "$INITIALIZED_DB" ]]; then
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'CREATE DATABASE davical;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'CREATE ROLE davical_dba;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'CREATE ROLE davical_app;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c "ALTER USER davical_dba WITH PASSWORD '$PASSDAVDB';"
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c "ALTER USER davical_app WITH PASSWORD '$PASSDAVDB';"
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'GRANT ALL PRIVILEGES ON DATABASE davical TO davical_dba;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'GRANT ALL PRIVILEGES ON DATABASE davical TO davical_app;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'ALTER DATABASE davical OWNER TO davical_dba;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'GRANT USAGE, CREATE ON SCHEMA PUBLIC TO davical_dba;'
PGPASSWORD=$PGSQL_ROOT_PASS /usr/bin/psql -qX -U postgres -h $DBHOST -c 'ALTER USER davical_dba WITH LOGIN;'
PGPASSWORD=$PGSQL_ROOT_PASS /usr/bin/psql -qX -U postgres -h $DBHOST -c 'ALTER USER davical_app WITH LOGIN;'
PGPASSWORD="$PASSDAVDB" /usr/bin/psql -qXAt -U davical_dba -h "$DBHOST" davical < /usr/share/awl/dba/awl-tables.sql
PGPASSWORD="$PASSDAVDB" /usr/bin/psql -qXAt -U davical_dba -h "$DBHOST" davical < /usr/share/awl/dba/schema-management.sql
PGPASSWORD="$PASSDAVDB" /usr/bin/psql -qXAt -U davical_dba -h "$DBHOST" davical < /usr/share/davical/dba/davical.sql
PGPASSWORD="$PASSDAVDB" /usr/share/davical/dba/update-davical-database --dbname davical --dbuser davical_dba --dbhost "$DBHOST" --dbpass "$PASSDAVDB" --appuser davical_app --nopatch --owner davical_dba
PGPASSWORD="$PASSDAVDB" /usr/bin/psql -qXAt -U davical_dba -h "$DBHOST" davical < /usr/share/davical/dba/base-data.sql
PGPASSWORD="$PASSDAVDB" /usr/bin/psql davical -qX -U davical_dba -h "$DBHOST" -c "UPDATE usr SET password = '**$ADMINDAVICALPASS' WHERE user_no = 1;"
else
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c "ALTER USER davical_dba WITH PASSWORD '$PASSDAVDB';"
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c "ALTER USER davical_app WITH PASSWORD '$PASSDAVDB';"
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'GRANT ALL PRIVILEGES ON DATABASE davical TO davical_dba;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'GRANT ALL PRIVILEGES ON DATABASE davical TO davical_app;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'ALTER DATABASE davical OWNER TO davical_dba;'
PGPASSWORD="$PGSQL_ROOT_PASS" /usr/bin/psql -qX -U postgres -h "$DBHOST" -c 'GRANT USAGE, CREATE ON SCHEMA PUBLIC TO davical_dba;'
PGPASSWORD=$PGSQL_ROOT_PASS /usr/bin/psql -qX -U postgres -h $DBHOST -c 'ALTER USER davical_dba WITH LOGIN;'
PGPASSWORD=$PGSQL_ROOT_PASS /usr/bin/psql -qX -U postgres -h $DBHOST -c 'ALTER USER davical_app WITH LOGIN;'
PGPASSWORD="$PASSDAVDB" /usr/bin/psql davical -qX -U davical_dba -h "$DBHOST" -c "UPDATE usr SET password = '**$ADMINDAVICALPASS' WHERE user_no = 1;"
fi
#UPDATE ALWAYS THE DATABASE
sleep 3
#CHECK UPDATING STATUS
if [[ "$UPDATE_FROM_OLD" = true ]]; then
/usr/share/davical/dba/update-davical-database --dbname davical --dbuser davical_dba --dbhost "$DBHOST" --dbpass "$PASSDAVDB" --appuser davical_app --owner davical_dba
else
/usr/share/davical/dba/update-davical-database --dbname davical --dbuser davical_dba --dbhost "$DBHOST" --dbpass "$PASSDAVDB" --appuser davical_app --nopatch --owner davical_dba
fi
#LAUNCH THE INIT PROCESS
exec /usr/sbin/httpd -e error -E /var/log/apache2/apache-start.log -DFOREGROUND