config.sh 6.18 KB
Newer Older
1
#!/bin/bash
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
# Path to deploy the Tomcat Bundle
BONITA_PATH=${BONITA_PATH:-/opt/bonita}
# Templates directory
BONITA_TPL=${BONITA_TPL:-/opt/templates}
# Files directory
BONITA_FILES=${BONITA_FILES:-/opt/files}
# Flag to allow or not the SQL queries to automatically check and create the databases
ENSURE_DB_CHECK_AND_CREATION=${ENSURE_DB_CHECK_AND_CREATION:-true}
# Java OPTS
JAVA_OPTS=${JAVA_OPTS:--Xms1024m -Xmx1024m}
# Flag to enable or not dynamic authorization checking on Bonita REST API
REST_API_DYN_AUTH_CHECKS=${REST_API_DYN_AUTH_CHECKS:-true}

# retrieve the db parameters from the container linked
if [ -n "$POSTGRES_PORT_5432_TCP_PORT" ]
then
	DB_VENDOR='postgres'
	DB_HOST=$POSTGRES_PORT_5432_TCP_ADDR
	DB_PORT=$POSTGRES_PORT_5432_TCP_PORT
elif [ -n "$MYSQL_PORT_3306_TCP_PORT" ]
then
	DB_VENDOR='mysql'
	DB_HOST=$MYSQL_PORT_3306_TCP_ADDR
	DB_PORT=$MYSQL_PORT_3306_TCP_PORT
else
	DB_VENDOR=${DB_VENDOR:-h2}
fi

case $DB_VENDOR in
	"h2")
		DB_HOST=${DB_HOST:-localhost}
		DB_PORT=${DB_PORT:-9091}
		;;
	"postgres")
		DB_PORT=${DB_PORT:-5432}
		;;
	"mysql")
		DB_PORT=${DB_PORT:-3306}
		;;
	*)
		;;
esac
# BIZ_DB_VENDOR is currently set to the same value than DB_VENDOR
BIZ_DB_VENDOR=$DB_VENDOR

# if not enforced, set the default values to configure the databases
DB_NAME=${DB_NAME:-bonitadb}
DB_USER=${DB_USER:-bonitauser}
DB_PASS=${DB_PASS:-bonitapass}
DB_DROP_EXISTING=${DB_DROP_EXISTING:-N}
BIZ_DB_NAME=${BIZ_DB_NAME:-businessdb}
BIZ_DB_USER=${BIZ_DB_USER:-businessuser}
BIZ_DB_PASS=${BIZ_DB_PASS:-businesspass}
BIZ_DB_DROP_EXISTING=${BIZ_DB_DROP_EXISTING:-N}

# if not enforced, set the default credentials
PLATFORM_LOGIN=${PLATFORM_LOGIN:-platformAdmin}
PLATFORM_PASSWORD=${PLATFORM_PASSWORD:-platform}
TENANT_LOGIN=${TENANT_LOGIN:-install}
TENANT_PASSWORD=${TENANT_PASSWORD:-install}

65
if [ ! -d ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION} ]
66
then
67
  unzip -q ${BONITA_FILES}/BonitaCommunity-${BRANDING_VERSION}.zip -d ${BONITA_PATH}
68
69
70
71
fi

if [ "${ENSURE_DB_CHECK_AND_CREATION}" = 'true' ]
then
72
    echo "Creating (if missing) database and users"
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
	# load SQL functions
	. ${BONITA_FILES}/functions.sh
	case "${DB_VENDOR}" in
		mysql)
			DB_ADMIN_USER=${DB_ADMIN_USER:-root}
			if [ -z "$DB_ADMIN_PASS" ]
			then
				DB_ADMIN_PASS=$MYSQL_ENV_MYSQL_ROOT_PASSWORD
			fi
			;;
		postgres)
			DB_ADMIN_USER=${DB_ADMIN_USER:-postgres}
			if [ -z "$DB_ADMIN_PASS" ]
			then
				DB_ADMIN_PASS=$POSTGRES_ENV_POSTGRES_PASSWORD
			fi
			;;
	esac
	if [ "${DB_VENDOR}" != 'h2' ]
	then
		# ensure to create bonita db and user
		create_user_if_not_exists "$DB_VENDOR" "$DB_HOST" "$DB_PORT" "$DB_ADMIN_USER" "$DB_ADMIN_PASS" "$DB_USER" "$DB_PASS"
		create_database_if_not_exists "$DB_VENDOR" "$DB_HOST" "$DB_PORT" "$DB_ADMIN_USER" "$DB_ADMIN_PASS" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_DROP_EXISTING"
		# ensure to create business db and user if needed
		create_user_if_not_exists "$DB_VENDOR" "$DB_HOST" "$DB_PORT" "$DB_ADMIN_USER" "$DB_ADMIN_PASS" "$BIZ_DB_USER" "$BIZ_DB_PASS"
		create_database_if_not_exists "$DB_VENDOR" "$DB_HOST" "$DB_PORT" "$DB_ADMIN_USER" "$DB_ADMIN_PASS" "$BIZ_DB_NAME" "$BIZ_DB_USER" "$BIZ_DB_PASS" "$BIZ_DB_DROP_EXISTING"
	fi
fi

# apply conf
# copy templates
104
105
cp ${BONITA_TPL}/setenv.sh ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/tomcat-templates/setenv.sh
cp ${BONITA_TPL}/database.properties ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/database.properties
106
107
108
109

# if required, uncomment dynamic checks on REST API
if [ "$REST_API_DYN_AUTH_CHECKS" = 'true' ]
then
110
    sed -i -e 's/^#GET|/GET|/' -e 's/^#POST|/POST|/' -e 's/^#PUT|/PUT|/' -e 's/^#DELETE|/DELETE|/' ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/platform_conf/initial/tenant_template_portal/dynamic-permissions-checks-custom.properties
111
112
113
fi

# replace variables
114
find ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/platform_conf/initial -name "*.properties" | xargs -n10 sed -i \
115
116
117
118
119
120
121
    -e 's/^#userName\s*=.*/'"userName=${TENANT_LOGIN}"'/' \
    -e 's/^#userPassword\s*=.*/'"userPassword=${TENANT_PASSWORD}"'/' \
    -e 's/^platform.tenant.default.username\s*=.*/'"platform.tenant.default.username=${TENANT_LOGIN}"'/' \
    -e 's/^platform.tenant.default.password\s*=.*/'"platform.tenant.default.password=${TENANT_PASSWORD}"'/' \
    -e 's/^#platformAdminUsername\s*=.*/'"platformAdminUsername=${PLATFORM_LOGIN}"'/' \
    -e 's/^#platformAdminPassword\s*=.*/'"platformAdminPassword=${PLATFORM_PASSWORD}"'/'

122
echo "Using JAVA_OPTS: ${JAVA_OPTS}"
123
sed -i -e 's/{{JAVA_OPTS}}/'"${JAVA_OPTS}"'/' ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/tomcat-templates/setenv.sh
124
125
126
127
128

if [ -n "$JDBC_DRIVER" ]
then
    # if $JDBC_DRIVER is set and the driver is not present, copy the JDBC driver into the Bundle
    file=$(basename $JDBC_DRIVER)
129
    if [ ! -e ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/lib/$file ]
130
    then
131
        cp ${BONITA_FILES}/${JDBC_DRIVER} ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/lib/
132
133
134
    fi
fi

135
136
137
138
139
140
echo "Using DB_VENDOR: ${DB_VENDOR}"
echo "Using DB_NAME: ${DB_NAME}"
echo "Using DB_HOST: ${DB_HOST}"
echo "Using DB_PORT: ${DB_PORT}"
echo "Using BIZ_DB_NAME: ${BIZ_DB_NAME}"

141
142
143
144
145
146
147
148
149
sed -e 's/{{DB_VENDOR}}/'"${DB_VENDOR}"'/' \
    -e 's/{{DB_USER}}/'"${DB_USER}"'/' \
    -e 's/{{DB_PASS}}/'"${DB_PASS}"'/' \
    -e 's/{{DB_NAME}}/'"${DB_NAME}"'/' \
    -e 's/{{DB_HOST}}/'"${DB_HOST}"'/' \
    -e 's/{{DB_PORT}}/'"${DB_PORT}"'/' \
    -e 's/{{BIZ_DB_USER}}/'"${BIZ_DB_USER}"'/' \
    -e 's/{{BIZ_DB_PASS}}/'"${BIZ_DB_PASS}"'/' \
    -e 's/{{BIZ_DB_NAME}}/'"${BIZ_DB_NAME}"'/' \
150
    -i ${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/setup/database.properties
151
152

# apply logging configuration
153
LOGGING_FILE=${BONITA_PATH}/BonitaCommunity-${BRANDING_VERSION}/server/conf/logging.properties
154
155
mv ${LOGGING_FILE} ${LOGGING_FILE}.original
awk -f ${BONITA_FILES}/logging.awk ${LOGGING_FILE}.original > ${LOGGING_FILE}
156
157

# use the setup tool to initialize and configure Bonita Tomcat bundle
158
cd /opt/bonita/BonitaCommunity-${BRANDING_VERSION}
159
# platform setup tool logging configuration file
160
BONITA_SETUP_LOGGING_FILE=${BONITA_SETUP_LOGGING_FILE:-/opt/bonita/BonitaCommunity-${BRANDING_VERSION}/setup/logback.xml}
161
162
echo y | ./setup/setup.sh init -Dlogging.config=${BONITA_SETUP_LOGGING_FILE}
./setup/setup.sh configure -Dlogging.config=${BONITA_SETUP_LOGGING_FILE}