-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
79 lines (69 loc) · 2.58 KB
/
run
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
71
72
73
74
75
76
77
78
79
#!/bin/bash
: ${BACULA_LOGDIR:="/var/log/bacula/"}
: ${BACULA_DEBUG:="50"}
: ${BACULA_DBHOST:="bacula"}
: ${BACULA_DBNAME:="baculadb"}
: ${BACULA_DBUSER:="bacula"}
: ${BACULA_DBPASSWORD:="bacula"}
: ${BACULA_DIRNAME:="bacula"}
: ${BACULA_CONSOLEPASSWORD:="password"}
: ${BACULA_FDNAME:="bacula-fd"}
: ${BACULA_FDPASSWORD:="password"}
: ${BACULA_SDPASSWORD:="password"}
: ${BACULA_DIRADDRESS:="127.0.0.1"}
: ${BACULA_FDADDRESS:="127.0.0.1"}
: ${BACULA_SDADDRESS:="127.0.0.1"}
echo "=> Checking wether database service at ${BACULA_DBHOST} is up"
if ping -q -c 1 -W 1 ${BACULA_DBHOST} > /dev/null; then
echo "=> Succeeded, Database up ..."
else
echo "=> Database down, exiting"
exit 1
fi
for i in $(seq 10 -1 1)
do
echo "=> Waiting database configuration ${i} ..."
sleep 1
done
echo "${BACULA_DBHOST}:*:*:${BACULA_DBUSER}:${BACULA_DBPASSWORD}" >> ~/.pgpass
echo "${BACULA_DBHOST}:*:*:postgres:${BACULA_DBPASSWORD}" >> ~/.pgpass
chmod 0600 ~/.pgpass
[ -d "${BACULA_LOGDIR}" ] && chown -R bacula:bacula ${BACULA_LOGDIR}
echo "=> Attempting database setup"
if [ -n "$(psql -h ${BACULA_DBHOST} -U postgres -lqt | cut -d'|' -f 1 | grep -w ${BACULA_DBNAME})" ]; then
echo "=> Database already setup, skipping."
else
echo "=> Setting Database ..."
echo -n "=> Creating Database ... "
psql -h ${BACULA_DBHOST} -U postgres -c "CREATE USER ${BACULA_DBUSER} WITH ENCRYPTED PASSWORD '${BACULA_DBPASSWORD}'" > /dev/null
psql -h ${BACULA_DBHOST} -U postgres -c "CREATE DATABASE ${BACULA_DBNAME} WITH OWNER ${BACULA_DBUSER}" > /dev/null
psql -h ${BACULA_DBHOST} -U postgres -c "UPDATE pg_database SET encoding = pg_char_to_encoding('SQL_ASCII') WHERE datname = '${BACULA_DBNAME}'" > /dev/null
psql -h ${BACULA_DBHOST} -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE ${BACULA_DBNAME} TO ${BACULA_DBUSER}" > /dev/null
echo "Done"
echo -n "=> Making Tables ... "
/etc/bacula/scripts/make_postgresql_tables -h ${BACULA_DBHOST} -U ${BACULA_DBUSER} -d ${BACULA_DBNAME} > /dev/null
echo "Done"
fi
CONFIGS_VARS=(
BACULA_DBHOST
BACULA_DBNAME
BACULA_DBUSER
BACULA_DBPASSWORD
BACULA_FDPASSWORD
BACULA_SDPASSWORD
BACULA_CONSOLEPASSWORD
BACULA_DIRNAME
BACULA_FDNAME
BACULA_FDADDRESS
BACULA_DIRADDRESS
BACULA_SDADDRESS
)
echo "=> Setting Bacula Director ..."
for c in ${CONFIGS_VARS[@]}; do
sed -i "s,@@${c}@@,$(eval echo \$${c})," /etc/bacula/bacula-dir.conf
sed -i "s,@@${c}@@,$(eval echo \$${c})," /etc/bacula/bconsole.conf
done
echo "=> Checking Bacula Director Configuration ..."
bacula-dir -t -c /etc/bacula/bacula-dir.conf
echo "=> Starting Bacula Director ..."
bacula-dir -f -c /etc/bacula/bacula-dir.conf -d ${BACULA_DEBUG}