From 971a5a3057d9c5e361412d815620ed1cf509e598 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 10 Oct 2017 02:35:51 +0200 Subject: [PATCH] - Adjust sample configuration file. - Support composer for installing roundcube's dependencies (PHP + JS). --- conf/install_roundcube.conf.sample | 11 +- install_roundcube.sh | 342 ++++++++++++++++++++--------- 2 files changed, 251 insertions(+), 102 deletions(-) diff --git a/conf/install_roundcube.conf.sample b/conf/install_roundcube.conf.sample index fedad59..405c352 100644 --- a/conf/install_roundcube.conf.sample +++ b/conf/install_roundcube.conf.sample @@ -71,6 +71,9 @@ IPV6="" # - Directory where certificate and key for the roundcube website # - are stored. # - +# - Example: +# - APACHE_CERT_DIR="/var/lib/dehydrated/certs/$WEBSITE_NAME" +# - # - Defaults to # - '/etc/apache2' if apache is installed from debian package system # - '/usr/local/apache2/conf' otherwise @@ -79,12 +82,18 @@ IPV6="" # - Certificate for the Rounfcube Website # - +# - Example: +# - APACHE_SERVER_CERT="fullchain.pem" +# - # - Defaults to 'server-bundle.crt' # - #APACHE_SERVER_CERT="" # - Key File for the Rounfcube Website # - +# - Example: +# - APACHE_SERVER_KEY="privkey.pem" +# - # - Defaults to 'server.key' # - #APACHE_SERVER_KEY="" @@ -241,7 +250,7 @@ POSTFIX_DB_TYPE="pgsql" # - # - used for setting $config['password_db_dsn'] # - -POSTFIX_DB_PASSWD='CbX8vg347Vvm' +POSTFIX_DB_PASSWD='' # === diff --git a/install_roundcube.sh b/install_roundcube.sh index 124c41e..13f9601 100755 --- a/install_roundcube.sh +++ b/install_roundcube.sh @@ -28,6 +28,7 @@ conf_file="${_src_base_dir}/conf/install_roundcube.conf" curdir=`pwd` log_file="$(mktemp)" +backup_date="$(date +%Y-%m-%d-%H%M)" # ------------- @@ -242,7 +243,7 @@ fi [[ -n "$PW_MIN_LENGTH" ]] || PW_MIN_LENGTH=10 [[ -n "$PW_REQUIRE_NONALPHA" ]] || PW_REQUIRE_NONALPHA=true [[ -n "$PW_PASSWD_ALGO" ]] || PW_PASSWD_ALGO="dovecot" -[[ -n "$PW_PASSWD_ALGO_PREFIX" ]] || PW_PASSWD_ALGO_PREFIX="{CRAM-MD5}" +#[[ -n "$PW_PASSWD_ALGO_PREFIX" ]] || PW_PASSWD_ALGO_PREFIX="{CRAM-MD5}" [[ -n "$POSTFIX_DB_TYPE" ]] || fatal "Plugin password: Database Type for Password Database (POSTFIX_DB_TYPE) not given!" if [[ "$POSTFIX_DB_TYPE" != "pgsql" ]] && [[ "$POSTFIX_DB_TYPE" != "mysql" ]]; then @@ -367,37 +368,36 @@ _log_dir=${_src_base_dir}/log-roundcube-$_version ## ---------------------------- ## - Begin Installation -## - REQUIREMENTS -## - ============ -## - -## - * The Apache, Lighttpd, Cherokee or Hiawatha web server -## - * .htaccess support allowing overrides for DirectoryIndex -## - * PHP Version 5.2.1 or greater including -## - - PCRE, DOM, JSON, XML, Session, Sockets (required) -## - - libiconv (recommended) -## - - mbstring, fileinfo, mcrypt (optional) -## - * PEAR packages distributed with Roundcube or external: -## - - MDB2 2.5.0 or newer -## - - Mail_Mime 1.8.1 or newer -## - - Mail_mimeDecode 1.5.5 or newer -## - - Net_SMTP 1.4.2 or newer -## - - Net_IDNA2 0.1.1 or newer -## - - Auth_SASL 1.0.6 or newer -## - * php.ini options (see .htaccess file): -## - - error_reporting E_ALL & ~E_NOTICE (or lower) -## - - memory_limit > 16MB (increase as suitable to support large attachments) -## - - file_uploads enabled (for attachment upload features) -## - - session.auto_start disabled -## - - zend.ze1_compatibility_mode disabled -## - - suhosin.session.encrypt disabled -## - - mbstring.func_overload disabled -## - - magic_quotes_runtime disabled -## - - magic_quotes_sybase disabled -## - * PHP compiled with OpenSSL to connect to IMAPS and to use the spell checker -## - * A MySQL (4.0.8 or newer), PostgreSQL, MSSQL database engine -## - or the SQLite extension for PHP -## - * One of the above databases with permission to create tables -## - * An SMTP server (recommended) or PHP configured for mail delivery +# - REQUIREMENTS +# - ============ +# - +# - * An IMAP, HTTP and SMTP server +# - * .htaccess support allowing overrides for DirectoryIndex +# - * PHP Version 5.4 or greater including: +# - - PCRE, DOM, JSON, Session, Sockets, OpenSSL, Mbstring (required) +# - - PHP PDO with driver for either MySQL, PostgreSQL, SQL Server, Oracle or SQLite (required) +# - - Iconv, Zip, Fileinfo, Intl, Exif (recommended) +# - - LDAP for LDAP addressbook support (optional) +# - * PEAR and PEAR packages distributed with Roundcube or external: +# - - Mail_Mime 1.10.0 or newer +# - - Net_SMTP 1.7.1 or newer +# - - Net_Socket 1.0.12 or newer +# - - Net_IDNA2 0.1.1 or newer +# - - Auth_SASL 1.0.6 or newer +# - - Net_Sieve 1.3.2 or newer (for managesieve plugin) +# - - Crypt_GPG 1.6.0 or newer (for enigma plugin) +# - - Endroid/QrCode 1.6.0 or newer (https://github.com/endroid/QrCode) +# - * php.ini options (see .htaccess file): +# - - error_reporting E_ALL & ~E_NOTICE & ~E_STRICT +# - - memory_limit > 16MB (increase as suitable to support large attachments) +# - - file_uploads enabled (for attachment upload features) +# - - session.auto_start disabled +# - - suhosin.session.encrypt disabled +# - - mbstring.func_overload disabled +# - * A MySQL, PostgreSQL, MS SQL Server (2005 or newer), Oracle database +# - or SQLite support in PHP - with permission to create tables +# - * Composer installed either locally or globally (https://getcomposer.org) + needed_php_pear_modules=" MDB2 @@ -448,13 +448,57 @@ for _version in $php_major_versions ; do done -echo -e "\n\n\t\033[37m\033[1mBase install Roundcube Webmail..\033[m\n" +echo -e "\n\n\t\033[37m\033[1mInstall (global) composer..\033[m\n" -# - install roundcube -# - -echononl "\tDownload 'roundcubemail-${ROUNDCUBE_VERSION}'.." -if [[ ! -f "$_src_base_dir/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz" ]]; then - wget -O ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBE_VERSION}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz > $log_file 2>&1 +echononl "\tDownload composer from 'getcomposer.org'.." +php -r "copy('https://getcomposer.org/installer', '${_src_base_dir}/composer-setup.php');" > $log_file 2>&1 +if [[ "$?" = "0" ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tInstall composer to /usr/local/bin" +php ${_src_base_dir}/composer-setup.php --install-dir=/usr/local/bin --filename=composer > $log_file 2>&1 +if [[ "$?" = "0" ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tRemove the installer" +php -r "unlink('${_src_base_dir}/composer-setup.php');" > $log_file 2>&1 +if [[ "$?" = "0" ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + + +echo -e "\n\n\t\033[37m\033[1mCreate some Backups..\033[m\n" + + +echononl "\tBackup existing source directory 'roundcubemail-${ROUNDCUBE_VERSION}'.." +if [[ -d "${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}" ]] ;then + mv ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION} \ + ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.$backup_date > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + +echononl "\tBackup existing web-directory 'roundcubemail-${ROUNDCUBE_VERSION}'.." +if [[ -d "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" ]]; then + mv ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}.$backup_date > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else @@ -466,10 +510,13 @@ else fi -echononl "\tBackup existing source directory 'roundcubemail-${ROUNDCUBE_VERSION}'.." -if [[ -d "${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}" ]] ;then - mv ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION} \ - ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.`date +%Y%m%d-%H%M` > $log_file 2>&1 +echo -e "\n\n\t\033[37m\033[1mBase install Roundcube Webmail..\033[m\n" + +# - install roundcube +# - +echononl "\tDownload 'roundcubemail-${ROUNDCUBE_VERSION}'.." +if [[ ! -f "$_src_base_dir/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz" ]]; then + wget -O ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBE_VERSION}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else @@ -502,20 +549,6 @@ else echo_skipped fi -echononl "\tBackup existing web-directory 'roundcubemail-${ROUNDCUBE_VERSION}'.." -if [[ -d "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" ]]; then - mv ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} \ - ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}.`date +%Y%m%d-%H%M` > $log_file 2>&1 - if [[ $? -eq 0 ]]; then - echo_ok - else - echo_failed - error "$(cat $log_file)" - fi -else - echo_skipped -fi - echononl "\tCopy Roundcube to web-directory" cp -a ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION} $WEBSITE_BASEDIR/ > $log_file 2>&1 if [[ $? -eq 0 ]]; then @@ -525,6 +558,78 @@ else error "$(cat $log_file)" fi +echononl "\tChange owner/group for Roundcube Webdirectory.." +chown -R ${HTTP_USER}:$HTTP_GROUP $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION} > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + + +echononl "\tChange into Roundcube Webdirectory.." +cd "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tRename the composer.json-dist file into composer.json" +cp -a "composer.json-dist" "composer.json" > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + + +echononl "\tInstall PHP dependencies.." +#/usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer install --no-dev +su www-data -c"cd ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} + /usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer install --no-dev" -s /bin/bash \ + > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tInstall Javascript dependencies.." +${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/bin/install-jsdeps.sh > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + + +# - Install a cronjob for cleaning up database +# - +echononl "\tInstall a cronjob for cleaning up database" +crontab -l > /tmp/tmp_crontab +if ! grep -q -E "${WEBSITE_BASEDIR}/htdocs/bin/cleandb.sh" /tmp/tmp_crontab 2> /dev/null ; then + echo "" >> /tmp/tmp_crontab + echo "# - Keep roundcube database slick and clean" >> /tmp/tmp_crontab + echo "# -" >> /tmp/tmp_crontab + echo "37 3 * * * ${WEBSITE_BASEDIR}/htdocs/bin/cleandb.sh" >> /tmp/tmp_crontab + crontab /tmp/tmp_crontab > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + + echononl "\tSet Permissions 'root:root' on \n\t ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" chown -R root:root $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION} > $log_file 2>&1 if [[ $? -eq 0 ]]; then @@ -648,19 +753,6 @@ else echo_skipped fi -echononl "\tCreate Web-Directory '$WEBSITE_BASEDIR'.." -if [[ ! -d "$WEBSITE_BASEDIR" ]]; then - mkdir $WEBSITE_BASEDIR - if [[ "$?" = "0" ]]; then - echo_ok - else - echo_failed - error "$(cat $log_file)" - fi -else - echo_skipped -fi - if [[ "$PHP_TYPE" = "fcgid" ]] ; then @@ -951,7 +1043,7 @@ echo "" echononl "\tSave existing vhost file.." if [ -f ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ];then if [[ -f "${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf" ]]; then - mv ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf.`date +%Y%m%d-%H%M` > $log_file 2>&1 + mv ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf.$backup_date > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else @@ -1321,26 +1413,43 @@ echo -e "\n\n\t\033[37m\033[1mSetup Database '$DB_TYPE'..\033[m\n" # - MySQL/PostgreSQL Datenbank erstellen # - # - -echo "" -echononl "\tCreate Database '$DB_NAME'" + +if [[ "$DB_TYPE" = "mysql" ]]; then + if ! mysql $MYSQL_CREDENTIALS -N -s -e \ + "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$DB_NAME'" 2>> $log_file \ + | grep $POSTFIX_DB_NAME >> $log_file 2>&1 ; then + database_exists=false + else + database_exists=true + fi +elif [[ "$DB_TYPE" = "pgsql" ]]; then + count=$(su - postgres -c "psql -q -A -t -l" | grep -c -e "^$DB_NAME") + if [[ $count -eq 0 ]];then + database_exists=false + else + database_exists=true + fi +else + fatal "Cannot detect database type (value of DB_TYPE is neither 'mysql' nor 'pgsql')" +fi + _failed=false -if [ "$DB_TYPE" = "mysql" ]; then - echo -n " (MySQL).." - if ! mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \ - "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$DB_NAME'" 2>/dev/null \ - | grep $DB_NAME > /dev/null 2>&1 ; then - mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \ +echononl "\tCreate Database '$DB_NAME'" +if ! $database_exists ; then + if [[ "$DB_TYPE" = "mysql" ]]; then + echo -n " (MySQL).." + mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \ "CREATE DATABASE IF NOT EXISTS $DB_NAME CHARACTER SET utf8 COLLATE utf8_general_ci" - if [[ $0 -ne 0 ]]; then + if [[ $? -ne 0 ]]; then _failed=true fi - mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \ + mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \ "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS'" - if [[ $0 -ne 0 ]]; then + if [[ $? -ne 0 ]]; then _failed=true fi mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e "FLUSH PRIVILEGES" - if [[ $0 -ne 0 ]]; then + if [[ $? -ne 0 ]]; then _failed=true fi if ! $_failed ; then @@ -1348,20 +1457,15 @@ if [ "$DB_TYPE" = "mysql" ]; then else echo_failed fi - else - echo_skipped - fi -elif [ "$DB_TYPE" = "pgsql" ]; then - echo -n " (PostgreSQL).." - count=`su - postgres -c "psql -q -A -t -l" | grep -c -e "^$DB_NAME"` - if [ $count -eq 0 ];then - echo "CREATE ROLE $DB_USER WITH LOGIN NOCREATEDB NOCREATEROLE NOSUPERUSER ENCRYPTED PASSWORD '$DB_PASS'" \ + elif [[ "$DB_TYPE" = "pgsql" ]]; then + echo -n " (PostgreSQL).." + echo "CREATE ROLE $DB_USER WITH LOGIN NOCREATEDB NOCREATEROLE NOSUPERUSER ENCRYPTED PASSWORD '$DB_PASS'" \ | su - postgres -c "psql" > /dev/null - if [[ $0 -ne 0 ]]; then + if [[ $? -ne 0 ]]; then _failed=true fi su - postgres -c "createdb -E utf8 -O $DB_USER $DB_NAME" - if [[ $0 -ne 0 ]]; then + if [[ $? -ne 0 ]]; then _failed=true fi if ! $_failed ; then @@ -1369,11 +1473,34 @@ elif [ "$DB_TYPE" = "pgsql" ]; then else echo_failed fi - else - echo_skipped - fi + fi else - echo_skipped + echo_skipped +fi + +echononl "\tBackup existing Database '$DB_NAME'" +if $database_exists ; then + if [[ "$DB_TYPE" = "mysql" ]]; then + echo -n " (MySQL).." + mysqldump -u$_mysql_rootuser -p$_mysql_rootpass --opt $DB_NAME > ${WEBSITE_BASEDIR}/${DB_NAME}.$backup_date 2> $log_file + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + elif [[ "$DB_TYPE" = "pgsql" ]]; then + echo -n " (PostgreSQL).." + su - postgres -c "pg_dump $DB_NAME" > ${WEBSITE_BASEDIR}/${DB_NAME}.$backup_date.sql 2> $log_file + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + fi +else + echo_skipped fi @@ -1427,7 +1554,7 @@ read OK if [[ "$OK" = "YES" ]] ; then echo "" echo "" - echo -e "\t\033[1;32mGoing to install Roundcube Webmailer \033[1;37m$network \033[m" + echo -e "\t\033[1;32mGoing to configure Roundcube Webmailer \033[1;37m$network \033[m" echo "" else warn "Abort by user request - Answer as not 'YES'" @@ -2009,7 +2136,7 @@ _plugin="vacation" add_plugin_arr+=("$_plugin") _config_file="${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php" -_backup_file="${_config_file}.$(date +%Y-%m-%d-%H%M)" +_backup_file="${_config_file}.$backup_date" echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" echononl "\tDownload Pluging '$_plugin'.." @@ -2543,7 +2670,7 @@ EOF _failed=true fi - _pgppass_back_file="~/.pgpass.$(date +%Y-%m-%d-%H%M)" + _pgppass_back_file="~/.pgpass.$backup_date" _pgpass_was_present=false if [[ -f "~/.pgpass" ]]; then _pgpass_was_present=true @@ -2637,7 +2764,7 @@ EOF _failed=true fi - _pgppass_back_file="~/.pgpass.$(date +%Y-%m-%d-%H%M)" + _pgppass_back_file="~/.pgpass.$backup_date" _pgpass_was_present=false if [[ -f "~/.pgpass" ]]; then _pgpass_was_present=true @@ -2731,7 +2858,7 @@ EOF _failed=true fi - _pgppass_back_file="~/.pgpass.$(date +%Y-%m-%d-%H%M)" + _pgppass_back_file="~/.pgpass.$backup_date" _pgpass_was_present=false if [[ -f "~/.pgpass" ]]; then _pgpass_was_present=true @@ -2837,6 +2964,19 @@ else echo_skipped fi + +echo -e "\n\n\t\033[37m\033[1mPost installation tasks\033[m" +echo "" + +echononl "\tIndex build-in addressbook" +${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/bin/indexcontacts.sh > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + echo "" echononl "\tRemove installer Folder.." rm -r $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/installer > $log_file 2>&1