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 ...@@ -13,53 +13,49 @@ TARGET_DIR=/var/www/webmail
# Name of the MySQL database to use. # Name of the MySQL database to use.
MYSQL_DB="ai_roundcube" MYSQL_DB="ai_roundcube"
install_config() { die() {
install -o root -g root -m 644 ${CONFIG_DIR}/config.inc.php ${TARGET_DIR}/config/config.inc.php echo "ERROR: $*" >&2
exit 1
# 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}
} }
set -e
set -u
# Abort if some fundamental environment variables are not defined. # Abort if some fundamental environment variables are not defined.
# This is nicer than having Apache die with an error. # This is nicer than having Apache die with an error later.
if [ -z "${DOMAIN}" ]; then test -n "${DOMAIN}" \
echo "ERROR: The 'DOMAIN' environment variable is not defined" >&2 || die "the 'DOMAIN' environment variable is not defined"
exit 1 test -n "${SHARD_ID}" \
fi || die "the 'SHARD_ID' environment variable is not defined"
if [ -z "${SHARD_ID}" ]; then
echo "ERROR: The 'SHARD_ID' environment variable is not defined" >&2 # Install the main Roundcube configuration to TARGET_DIR/config.
exit 1 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 fi
# Run database upgrade if necessary.
${TARGET_DIR}/bin/update.sh -v ${cur_version} -y \
|| die "Roundcube update script failed"
install_config mysql -e "update rc_version set version='${RC_VERSION}'" ${MYSQL_DB}
setup_database
exit 0 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