#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/mariadb-tools-update-db - MariaDB Server update # # Creation: 2014-03-06 hbfl # Last Update: $Id$ # # Copyright (c) 2014-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # set package name package_name=mariadb #include eislib . /var/install/include/eislib #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # default values . /var/lib/mysql/defaults.info admin_user='root' admin_pass='' PasswordParam="" ASK=/var/install/bin/ask CAT=/bin/cat RM=/bin/rm MKTEMP=/bin/mktemp #data_dir=$(grep '^MARIADB_DATADIR' /etc/config.d/${package_name} | # sed "s|#.*$||; s/^.*=['\"]\(.*\)['\"].*$/\1/") # --------------------------------------------------------------------------- # update path to php5 mysql.sock # --------------------------------------------------------------------------- if [ -f /var/install/packages/apache2_php5 ] then __socket=$(grep 'PHP5_EXT_MYSQL_SOCKET' /etc/config.d/apache2_php5 | sed "s|#.*$||; s/^.*=['\"]\(.*\)['\"].*$/\1/") __socket_new="${mysql_socket}" if [ -n "${__socket}" -a "${__socket}" != "${__socket_new}" ] then sed -i "s|${__socket}|${__socket_new}|" /etc/config.d/apache2_php5 apache2_start=true fi fi # --------------------------------------------------------------------------- # update database # --------------------------------------------------------------------------- rm -f /var/lib/mysql/update-install # remove old processes and pid files if [ -e ${mysql_pid_file} ] then /etc/init.d/${package_name} stop rm -f ${mysql_pid_file} fi mysql_start=$(grep '^START_MARIADB' /etc/config.d/${package_name} | sed "s|#.*$||; s/^.*=['\"]\(.*\)['\"].*$/\1/") if [ "${mysql_start}" = "yes" ] then # start new /etc/init.d/${package_name} start echo if [ ! -e ${mysql_pid_file} ] then echo "MariaDB/MySQL ERROR: cannot start!" fi if ${apache2_start:-false} then apache2_start=$(grep '^START_APACHE2' /etc/config.d/apache2 | sed "s|#.*$||; s/^.*=['\"]\(.*\)['\"].*$/\1/") if [ "${apache2_start}" = "yes" ] then /var/install/config.d/apache2_php5.sh fi fi fi # check MySQL, add backup and add root password if [ -e ${mysql_pid_file} ] then # check status from mysql database root, if exists ${mysql_basedir}/mysqladmin -u root status >/dev/null 2>&1 if [ "${?}" -eq 0 ] then __status=true fi password='' if ! "${__status:-false}" then # backup is deprecated if [ -f ${mysql_datadir:-/var/lib/mysql}/backup.pwd ] then # read the password include special chars password=$(sed -n '/passwd/ s/passwd=//p' \ ${mysql_datadir:-/var/lib/mysql}/backup.pwd) admin_user='backup' PasswordParam="-p$password" echo "Check database ..." ${mysql_basedir}/mysqladmin \ -u ${admin_user:-root} ${PasswordParam} status >/dev/null 2>&1 if [ ${?} -eq 0 ] then __status=true fi fi fi # count=1 # while [ ${count} -le 3 ] # do # echo # _ask_tmpfile=$( ${MKTEMP} -t .XXXXXXXXXXXXX ) # ${ASK} "MariaDB/MySQL user root password required:" "" "+hidden+" >${_ask_tmpfile} # rc=${?} # read password < ${_ask_tmpfile} # ${RM} -f ${_ask_tmpfile} # # admin_user="root" # # echo # if [ -n "${password}" ] # then # /usr/bin/mysqladmin \ # -u ${admin_user} -p${password} status >/dev/null 2>&1 # # if [ ${?} -eq 0 ] # then # break # else # echo "Password input error" # echo # fi # count=$( expr ${count} + 1 ) # fi # done # fi if ! "${__status:-false}" then # if [ -z "${password}" ] # then echo _ask_tmpfile=$( ${MKTEMP} -t .XXXXXXXXXXXXX ) ${ASK} "Set Password for MariaDB/MySQL user root:" "yes" >${_ask_tmpfile} rc=${?} read answer < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} admin_user="root" if [ "${answer}" = "yes" ] then # set root password /var/install/bin/mariadb-tools-userpass -nu=root ${mysql_basedir}/mysqladmin status >/dev/null 2>&1 if [ "${?}" -eq 0 ] then __status=true fi # # create default backup user # randompass=$( echo "${RANDOM}a${RANDOM}b${RANDOM}" ) # /var/install/bin/mariadb-tools-useradd -nu=backup \ # -np=${randompass} -hn=localhost -ar=12 -u=root fi fi if "${__status:-false}" # if [ -n "${password}" ] then # force upgrade ${mysql_basedir}/mysql_upgrade --verbose --user=${admin_user:-root} \ ${PasswordParam} --force >/dev/null # fix the old table type # /usr/bin/mysql_fix_privilege_tables \ # --password=${password} --bindir=/usr/bin >/dev/null else echo "datetime" >/var/lib/mysql/update-install fi else echo "datetime" >/var/lib/mysql/update-install fi exit 0 # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------