diff --git a/upgrade_roundcube.sh b/upgrade_roundcube.sh index 9896d3d..a282da3 100755 --- a/upgrade_roundcube.sh +++ b/upgrade_roundcube.sh @@ -18,7 +18,7 @@ echo -e "\n \033[32mStart script for upgrading Roundcube Webmailer..\033[m" # - Settings # ------------- -#_src_base_dir="$(realpath $(dirname $0))" +_src_base_dir="$(realpath $(dirname $0))" #conf_file="${_src_base_dir}/conf/install_upgrade_roundcube.conf" script_name="$(basename $(realpath $0))" @@ -332,6 +332,53 @@ else fi fi +# - Get the latest PHP version +# - +echononl "\tGet major version of latest installed PHP version" +php_latest_ver="" +if $PHP_DEBIAN_INSTALLATION ; then + echo_skipped +else + if [[ -n "$php_major_versions" ]]; then + for _ver in $php_major_versions ; do + if [[ -z "$php_latest_ver" ]] ; then + php_latest_ver=$_ver + elif [[ "${_ver%.*}" -gt "${php_latest_ver%.*}" ]] ; then + php_latest_ver=$_ver + elif [[ "${_ver%.*}" -eq "${php_latest_ver%.*}" ]] ; then + [[ "${_ver#*.}" -gt "${php_latest_ver#*.}" ]] && php_latest_ver=$_ver + fi + done + echo_ok + else + echo_skipped + warn "Getting major version of latest installed PHP version failed! - No installed PHP versiond found!" + fi +fi + +# - Get activ PHP version, means that on which is part of $PATH environment +# - +echononl "\tGet PHP version in PATH environment.." +if $(which php > /dev/null 2>&1) ; then + php_version_in_path="$(php --version 2> /dev/null | head -1 | cut -d' ' -f2 | cut -d '-' -f1 2> /dev/null)" + if [[ $? -eq 0 ]] && [[ -n "${php_version_in_path}" ]]; then + echo_ok + else + echo_failed + + fatal "Failed getting PHP Version.." + fi +else + echo_skipped + + fatal "No PHP binary found in PATH environment.." +fi + + +# - Log directory containing upgrade log files +# - +_log_dir=${script_dir}/log-upgrade-roundcube-${ROUNDCUBE_VERSION} + echo "" echo "" @@ -383,6 +430,7 @@ else done echo "" echo -e "\tNewest PHP Version...................: $php_latest_ver" + echo -e "\tPHP Version of php binary in PATH....: $php_version_in_path" fi echo "" echo -e "\tCrontab backup file..................: $crontab_backup_file" @@ -415,8 +463,42 @@ else fi +echononl "\tInstall/Update composer to /usr/local/bin" + +echononl "\tDownload composer from 'getcomposer.org'.." +php -r "copy('https://getcomposer.org/installer', '${script_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 ${script_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 + + echo -e "\n\n \033[37m\033[1mCreate some Backups..\033[m\n" +echononl " Backup existing upgrade log directory \033[37m\033[1m$(basename "${_log_dir}")\033[m" +if [[ -d "${_log_dir}" ]] ; then + mv "${_log_dir}" "${_log_dir}.${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 " Backup existing Database '$DB_NAME'" if [[ "$DB_TYPE" = "mysql" ]]; then echo -n " (MySQL).." @@ -631,8 +713,8 @@ else fi echononl " Create log-directory for update log file" -if [[ ! -d "${script_dir}/log" ]]; then - mkdir "${script_dir}/log" > $log_file 2>&1 +if [[ ! -d "${_log_dir}" ]]; then + mkdir "${_log_dir}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else @@ -643,10 +725,40 @@ else echo_skipped 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 composer to ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" +php ${script_dir}/composer-setup.php --install-dir=${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} > $log_file 2>&1 +if [[ "$?" = "0" ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tRemove the installer" +php -r "unlink('${script_dir}/composer-setup.php');" > $log_file 2>&1 +if [[ "$?" = "0" ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + + + echo "" echo " Update the the roundcube web-directory to version '${ROUNDCUBE_VERSION}'" -echononl " See: ${script_dir}/log/update_roundcube-${ROUNDCUBE_VERSION}.${backup_date}.log" -echo "y" | ${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}/bin/installto.sh "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > ${script_dir}/log/update_roundcube-${ROUNDCUBE_VERSION}.${backup_date}.log 2>&1 +echononl " See: ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}.${backup_date}.log" +echo "y" | ${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}/bin/installto.sh "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}.${backup_date}.log 2>&1 if [[ $? -eq 0 ]]; then echo_ok else @@ -681,12 +793,12 @@ done echononl " Update dependencies by running 'php composer.phar update --no-dev'" -php composer.phar --no-interaction update --no-dev > ${script_dir}/log/update_roundcube-${ROUNDCUBE_VERSION}-dependencies.${backup_date}.log 2>&1 +php composer.phar --no-interaction update --no-dev > ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}-dependencies.${backup_date}.log 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed - error "command was:\n\t # cd "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}"\n\t #php composer.phar --no-interaction update --no-dev\n\n$(cat ${script_dir}/log/update_roundcube-${ROUNDCUBE_VERSION}-dependencies.${backup_date}.log)" + error "command was:\n\t # cd "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}"\n\t #php composer.phar --no-interaction update --no-dev\n\n$(cat ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}-dependencies.${backup_date}.log)" echononl "continue anyway [yes/no]: " read OK