-
Notifications
You must be signed in to change notification settings - Fork 13
/
setup.sh
executable file
·106 lines (94 loc) · 2.95 KB
/
setup.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
: "${MYSQL_HOSTNAME:="localhost"}"
: "${MYSQL_ROOT_USER:="root"}"
: "${MYSQL_ROOT_PASSWORD:="idoit"}"
: "${IDOIT_ADMIN_CENTER_PASSWORD:="admin"}"
: "${MYSQL_USER:="idoit"}"
: "${MYSQL_PASSWORD:="idoit"}"
: "${IDOIT_DEFAULT_TENANT:="CMDB"}"
: "${IDOIT_SYSTEM_DATABASE:="idoit_system"}"
: "${IDOIT_TENANT_DATABASE:="idoit_data"}"
: "${APACHE_USER:="www-data"}"
: "${APACHE_GROUP:="www-data"}"
: "${MARIADB_BIN:="$(command -v mysql)"}"
: "${MEMCACHED_HOST:=""}"
: "${MEMCACHED_PORT:=""}"
function report {
log "Default tenant: $IDOIT_DEFAULT_TENANT"
log "MariaDB hostname: $MYSQL_HOSTNAME"
log "i-doit system database: $IDOIT_SYSTEM_DATABASE"
log "i-doit tenant database: $IDOIT_TENANT_DATABASE"
log "MariaDB super-user: $MYSQL_ROOT_USER"
log "MariaDB i-doit user: $MYSQL_USER"
}
function waitForDBMS {
while ! "$MARIADB_BIN" \
-h"$MYSQL_HOSTNAME" \
-u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" \
-e "SHOW DATABASES;" &> /dev/null; do
log "Wait for MariaDB…"
sleep 1
done
}
function runIdoitSetup {
log "Install i-doit"
php console.php install \
-u "$MYSQL_ROOT_USER" \
-p "$MYSQL_ROOT_PASSWORD" \
--host="$MYSQL_HOSTNAME" \
-d "$IDOIT_SYSTEM_DATABASE" \
-U "$MYSQL_USER" \
-P "$MYSQL_PASSWORD" \
--admin-password "$IDOIT_ADMIN_CENTER_PASSWORD" \
-n || \
abort "Installation of i-doit failed"
log "Create tenant"
php console.php tenant-create \
-u "$MYSQL_ROOT_USER" \
-p "$MYSQL_ROOT_PASSWORD" \
-U "$MYSQL_USER" \
-P "$MYSQL_PASSWORD" \
-d "$MYSQL_PASSWORD" \
-t "$IDOIT_DEFAULT_TENANT" \
-n || \
abort "Tenant can't be created"
}
function enableMemcached {
if [[ -n "$MEMCACHED_HOST" ]]; then
log "Enable memcached: $MEMCACHED_HOST"
"$MARIADB_BIN" \
-h"$MYSQL_HOSTNAME" \
-u"$MYSQL_USER" -p"$MYSQL_PASSWORD" \
-e"INSERT INTO ${IDOIT_SYSTEM_DATABASE}.isys_settings (isys_settings__key, isys_settings__value) VALUES ('memcache.host', '${MEMCACHED_HOST}');" || \
abort "SQL statement failed"
fi
if [[ -n "$MEMCACHED_PORT" ]]; then
log "Configure memcached port: $MEMCACHED_PORT"
"$MARIADB_BIN" \
-h"$MYSQL_HOSTNAME" \
-u"$MYSQL_USER" -p"$MYSQL_PASSWORD" \
-e"INSERT INTO ${IDOIT_SYSTEM_DATABASE}.isys_settings (isys_settings__key, isys_settings__value) VALUES ('memcache.port', '${MEMCACHED_PORT}');" || \
abort "SQL statement failed"
fi
}
function finish {
log "Done. Have fun :-)"
exit 0
}
function log {
echo -e "$1" 1>&2
}
function abort {
echo -e "$1" 1>&2
echo "Operation failed. Please check what is wrong and try again." 1>&2
exit 1
}
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
report
waitForDBMS
runIdoitSetup
enableMemcached
finish
fi