diff --git a/upgrade_roundcube.sh b/upgrade_roundcube.sh index a282da3..ef9c1c7 100755 --- a/upgrade_roundcube.sh +++ b/upgrade_roundcube.sh @@ -3,6 +3,8 @@ clear echo -e "\n \033[32mStart script for upgrading Roundcube Webmailer..\033[m" +CUR_IFS="$IFS" + ## ----------------------------------------------------------------- ## ---------------------------------------------------------------- ## --- @@ -186,6 +188,7 @@ while IFS='' read -r -d '' _conf_file ; do fi WEBSITE_NAME="" done < <(find "${conf_dir}" -maxdepth 1 -type f -name "install_upgrade_roundcube*.conf" -print0) +IFS="$CUR_IFS" if [[ ${#unsorted_website_arr} -eq 0 ]]; then fatal "No configuration files found in '${script_dir}/conf' or no website configured!" @@ -194,7 +197,7 @@ fi # - Sort array # - IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}")) -IFS=' ' +IFS="$CUR_IFS" WEBSITE_NAME= @@ -208,6 +211,8 @@ for _site in ${website_arr[@]} ; do echo " [$i] ${_arr[0]}" ((i++)) done +IFS="$CUR_IFS" + echo echononl " Eingabe: " while ! $_OK ; do @@ -223,6 +228,7 @@ read _IN echononl " Eingabe: " fi done +IFS="$CUR_IFS" echo "" echononl " Include Configuration file.." @@ -234,6 +240,7 @@ else echo_ok fi + [[ -n "$WEBSITE_NAME" ]] || fatal "Website's name (WEBSITE_NAME) not present!" DEFAULT_WEBSITE_BASEDIR="/var/www/${WEBSITE_NAME}" @@ -278,6 +285,34 @@ if [[ "$DB_TYPE" = "mysql" ]]; then else [[ "$DB_TYPE" = "pgsql" ]] || fatal "Unknown Database Type '$DB_TYPE' (DB_TYPE)" fi +mysql_credential_args="$MYSQL_CREDENTIALS" + + +if [[ "$DB_TYPE" = "mysql" ]]; then + echononl " Get MySQL command.." + mysql_command="$(which mysql)" + if [[ $? -eq 0 ]]; then + echo_ok + else + + if [[ -x "/usr/local/mysql/bin/mysql" ]]; then + mysql_command="/usr/local/mysql/bin/mysql" + echo_ok + else + echo_failed + fatal "$(cat $tmp_log_file)" + fi + fi +elif [[ "$DB_TYPE" = "pgsql" ]] ; then + echononl " Get PostgreSQL command.." + psql_command="$(which psql)" + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fi + +fi echo -e "\033[32m--\033[m" @@ -330,6 +365,7 @@ else else echo_ok fi + IFS="$CUR_IFS" fi # - Get the latest PHP version @@ -447,16 +483,44 @@ else fatal "Abort by user request - Answer as not 'YES'" fi +echononl "\tCheck Database connection .." if [[ "$DB_TYPE" = "mysql" ]]; then - if ! mysql $MYSQL_CREDENTIALS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIALS -N -s -e \ "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$DB_NAME'" 2>> $log_file \ - | grep $DB_NAME >> $log_file 2>&1 ; then - fatal "MySQL Database '$DB_NAME' does not exit. (See Parameter 'DB_NAME')" + | grep $DB_NAME >> $log_file 2>&1 + + if [[ "$?" = "0" ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" fi + elif [[ "$DB_TYPE" = "pgsql" ]]; then - count=$(su - postgres -c "psql -q -A -t -l" | grep -c -e "^$DB_NAME") + count=$(su - postgres -c "${psql_command} -q -A -t -l" | grep -c -e "^$DB_NAME") if [[ $count -eq 0 ]];then - fatal "PostgreSQL Database '$DB_NAME' does not exit. (See Parameter 'DB_NAME')" + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + else + echo_ok fi else fatal "Cannot detect database type (value of DB_TYPE is neither 'mysql' nor 'pgsql')"