#!/bin/bash set -ex # Configuration options you usually edit go here ROUNDCUBEMAIL_VERSION=1.4.7 CHECK_GPG=false CLEAN_INTERMEDIATES=false CONTAINER_VOLUME_CONFIG=/var/roundcube/config CONTAINER_WEBROOT=/var/www/html CONTAINER_PHP_CONFD=/usr/local/etc/php/conf.d CONTAINER_SCRIPTS=/usr/local/sbin # This is internal stuff used to build everything # Be aware, that several of these paths are used with rm -rf! SRCDIR=$(pwd)/src TMPDIR=$(pwd)/tmp BUILDDIR=$(pwd)/build SCRIPTS_SRC=${SRCDIR}/scripts ROUNDCUBE_DOWNLOAD=${TMPDIR}/roundcubemail.tar.gz ROUNDCUBE_ASC_DOWNLOAD=${ROUDCUBE_DOWNLOAD}.asc ROUNDCUBE_SRC=${TMPDIR}/roundcubemail ISPCONFIG_DOWNLOAD=${TMPDIR}/ispconfig3_roundcube.zip ISPCONFIG_SRC=${TMPDIR}/ispconfig3_roundcube ROOTFSTREE=${TMPDIR}/tree ROOTFSFILE=${BUILDDIR}/rootfs.tar.gz CONFIG_DST=${ROOTFSTREE}${CONTAINER_VOLUME_CONFIG} WEBROOT_DST=${ROOTFSTREE}${CONTAINER_WEBROOT} PHP_CONFD_DST=${ROOTFSTREE}${CONTAINER_PHP_CONFD} SCRIPTS_DST=${ROOTFSTREE}${CONTAINER_SCRIPTS} #### Sanitize Build Enviornment if [ -d ${TMPDIR} ]; then rm -rf ${TMPDIR} fi mkdir ${TMPDIR} if [ -d ${BUILDDIR} ]; then rm -rf ${BUILDDIR} fi mkdir ${BUILDDIR} #### Prepare the roundcube source # Download Roundcube and verify GPG if configured to do so: if [ -f ${ROUNDCUBE_DOWNLOAD} ]; then rm -f ${ROUNDCUBE_DOWNLOAD} fi curl -o ${ROUNDCUBE_DOWNLOAD} \ -SL https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBEMAIL_VERSION}/roundcubemail-${ROUNDCUBEMAIL_VERSION}-complete.tar.gz if [ "$CHECK_GPG" = true ]; then export GNUPGHOME="$(mktemp -d)" if [ -f ${ROUNDCUBE_ASC_DOWNLOAD} ]; then rm -f ${ROUNDCUBE_ASC_DOWNLOAD} fi curl -o ${ROUNDCUBE_ASC_DOWNLOAD} \ -SL https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBEMAIL_VERSION}/roundcubemail-${ROUNDCUBEMAIL_VERSION}-complete.tar.gz.asc # ha.pool.sks-keyservers.net seems to be unreliable, use pgp.mit.edu as fallback gpg --keyserver ha.pool.sks-keyservers.net --recv-keys F3E4C04BB3DB5D4215C45F7F5AB2BAA141C4F7D5 \ || gpg --keyserver pgp.mit.edu --recv-keys F3E4C04BB3DB5D4215C45F7F5AB2BAA141C4F7D5 gpg --batch --verify ${ROUNDCUBE_ASC_DOWNLOAD} ${ROUNDCUBE_DOWNLOAD} # Clean up behind us if [ "$CLEAN_INTERMEDIATES" = true ]; then gpgconf --kill all rm -rf "$GNUPGHOME" ${ROUNDCUBE_ASC_DOWNLOAD} fi fi # Extract the file into a temporary location and clean up behind us tar -xzf ${ROUNDCUBE_DOWNLOAD} -C ${TMPDIR} # upstream tarballs include ./roundcubemail-${ROUNDCUBEMAIL_VERSION}/ so this gives us TMPDIR/roundcubemail-${ROUNDCUBEMAIL_VERSION} mv ${TMPDIR}/roundcubemail-${ROUNDCUBEMAIL_VERSION} ${ROUNDCUBE_SRC} # Clean up the source tree for later use rm -rf ${ROUNDCUBE_SRC}/installer # Clean up behind us if [ "$CLEAN_INTERMEDIATES" = true ]; then rm -f ${ROUNDCUBE_DOWNLOAD} fi #### Prepare the ISPConfig Stuff if [ -f ${ISPCONFIG_DOWNLOAD} ]; then rm -f ${ISPCONFIG_DOWNLOAD} fi curl -o ${ISPCONFIG_DOWNLOAD} -SL https://github.com/w2c/ispconfig3_roundcube/archive/master.zip unzip -q ${ISPCONFIG_DOWNLOAD} -d ${TMPDIR} # This gives us a dir ispconfig3_roundcube-master, which we normalize mv ${TMPDIR}/ispconfig3_roundcube-master ${ISPCONFIG_SRC} # Clean up the source tree for later use rm -f ${ISPCONFIG_SRC}/.gitignore ${ISPCONFIG_SRC}/README.md #### Create the ROOT FS TREE mkdir -p ${ROOTFSTREE} # Prepare the Webroot directory with the source tree, then create some links, which we'll # need during runtime, they will be created by our entry point script. mkdir -p ${WEBROOT_DST} tar -c --one-file-system -C ${ROUNDCUBE_SRC} . | tar -x -C ${WEBROOT_DST} ln -s ${CONTAINER_VOLUME_CONFIG}/config.inc.php ${WEBROOT_DST}/config/config.inc.php cp ${SRCDIR}/db.inc.php ${WEBROOT_DST}/config/db.inc.php # Setup PHP mkdir -p ${PHP_CONFD_DST} cp ${SRCDIR}/php.ini ${PHP_CONFD_DST}/php.ini # Move the ISPConfig Plugins into place, again create some links which we'll need during # runtime. These too will be created by our entry point script tar -c --one-file-system -C ${ISPCONFIG_SRC} . | tar -x -C ${WEBROOT_DST}/plugins ln -s ${CONTAINER_VOLUME_CONFIG}/ispconfig3_account.inc.php ${WEBROOT_DST}/plugins/ispconfig3_account/config/config.inc.php # Add Entry Point cp -a ${SRCDIR}/docker-entrypoint.sh ${ROOTFSTREE} # Add all helper scripts mkdir -p ${SCRIPTS_DST} curl -o ${SCRIPTS_DST}/wait-for-it.sh \ -SL https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh chmod +x ${SCRIPTS_DST}/wait-for-it.sh cp -a ${SCRIPTS_SRC}/* ${SCRIPTS_DST} # Clean up behind us if [ "$CLEAN_INTERMEDIATES" = true ]; then rm -rf ${ROUNDCUBE_SRC} rm -rf ${ISPCONFIG_SRC} fi #### Now we tar everything together, so that the Dockerfile can put everything in place in one run tar -czf ${ROOTFSFILE} -C ${ROOTFSTREE} . # Clean up behind us if [ "$CLEAN_INTERMEDIATES" = true ]; then rm -rf ${ROOTFSTREE} fi