Commit 8f9b7f0c authored by ale's avatar ale

Refactor start.sh to be more linear

parent 5c941db6
Pipeline #848 passed with stages
in 3 minutes and 34 seconds
......@@ -13,53 +13,49 @@ TARGET_DIR=/var/www/webmail
# Name of the MySQL database to use.
MYSQL_DB="ai_roundcube"
install_config() {
install -o root -g root -m 644 ${CONFIG_DIR}/config.inc.php ${TARGET_DIR}/config/config.inc.php
# For each known plugin, look for a NAME.config.inc.php file in
# the config directory: if found, copy it to the plugin directory
# as plugins/NAME/config.inc.php.
for p in $(cd ${TARGET_DIR}/plugins && echo *) ; do
if [ -e "${CONFIG_DIR}/${p}.config.inc.php" ]; then
install -o root -g root -m 644 ${CONFIG_DIR}/${p}.config.inc.php \
${TARGET_DIR}/plugins/${p}/config.inc.php
fi
done
}
setup_database() {
# The current Roundcube version is stored in the database.
cur_version=$(mysql -NBe 'select version from rc_version' ${MYSQL_DB} 2>/dev/null)
# If cur_version is empty, it means that the database has not been
# initialized yet.
if [ -z "${cur_version}" ]; then
mysql ${MYSQL_DB} < ${TARGET_DIR}/SQL/mysql.initial.sql
mysql -e "create table rc_version (version text); insert into rc_version (version) values ('unknown')" ${MYSQL_DB}
fi
# Run database upgrade if necessary.
${TARGET_DIR}/bin/update.sh -v ${cur_version} -y
mysql -e "update rc_version set version='${RC_VERSION}'" ${MYSQL_DB}
die() {
echo "ERROR: $*" >&2
exit 1
}
set -e
set -u
# Abort if some fundamental environment variables are not defined.
# This is nicer than having Apache die with an error.
if [ -z "${DOMAIN}" ]; then
echo "ERROR: The 'DOMAIN' environment variable is not defined" >&2
exit 1
fi
if [ -z "${SHARD_ID}" ]; then
echo "ERROR: The 'SHARD_ID' environment variable is not defined" >&2
exit 1
# This is nicer than having Apache die with an error later.
test -n "${DOMAIN}" \
|| die "the 'DOMAIN' environment variable is not defined"
test -n "${SHARD_ID}" \
|| die "the 'SHARD_ID' environment variable is not defined"
# Install the main Roundcube configuration to TARGET_DIR/config.
test -e ${CONFIG_DIR}/config.inc.php \
|| die "${CONFIG_DIR}/config.inc.php is missing"
install -o root -g root -m 644 ${CONFIG_DIR}/config.inc.php ${TARGET_DIR}/config/config.inc.php
# For each known plugin, look for a NAME.config.inc.php file in
# the config directory: if found, copy it to the plugin directory
# as plugins/NAME/config.inc.php.
for p in $(cd ${TARGET_DIR}/plugins && echo *) ; do
test -e "${CONFIG_DIR}/${p}.config.inc.php" \
&& install -o root -g root -m 644 ${CONFIG_DIR}/${p}.config.inc.php \
${TARGET_DIR}/plugins/${p}/config.inc.php
done
# Now set up the MySQL database for Roundcube. The current Roundcube
# version is stored in the database.
cur_version=$(mysql -NBe 'select version from rc_version' ${MYSQL_DB} 2>/dev/null)
# If cur_version is empty, it means that the database has not been
# initialized yet.
if [ -z "${cur_version}" ]; then
mysql ${MYSQL_DB} < ${TARGET_DIR}/SQL/mysql.initial.sql \
|| die "could not load initial SQL schema to ${MYSQL_DB}"
mysql -e "create table rc_version (version text); insert into rc_version (version) values ('unknown')" ${MYSQL_DB} \
|| die "could not create rc_version table in ${MYSQL_DB}"
fi
# Run database upgrade if necessary.
${TARGET_DIR}/bin/update.sh -v ${cur_version} -y \
|| die "Roundcube update script failed"
install_config
setup_database
mysql -e "update rc_version set version='${RC_VERSION}'" ${MYSQL_DB}
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment