#---------------------------------------------------------------------------- # /var/install/bin/phpmyadmin-tools-helper # # Creation: 2015-11-02 hbfl # Last Update: $Id$ # # Copyright (c) 2015-@@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. #---------------------------------------------------------------------------- ASK='/var/install/bin/ask' MKTEMP='/usr/bin/mktemp' RM='/usr/bin/rm' EXPR='/usr/bin/expr' # --------------------------------------------------------------------------- # defaults # --------------------------------------------------------------------------- get_defaults() { # base_dir="$(awk -F' = ' '/basedir/ {print $2}' /etc/my.cnf)/bin" # default values . /var/lib/mysql/defaults.info admin_user='root' admin_pass='' # pid_file=$(mysqld_get_param pid-file) # data_dir=$(mysqld_get_param datadir) } # --------------------------------------------------------------------------- # Usage: void mysqld_get_param option # --------------------------------------------------------------------------- mysqld_get_param() { ${base_dir}/mysqld --print-defaults | tr ' ' '\n' | grep -- "--$1" | tail -n 1 | cut -d= -f2 } # --------------------------------------------------------------------------- # check status and access of MariaDB/MySQL Database # --------------------------------------------------------------------------- check_status() { if [ ! -f ${mysql_pid_file} ] then echo mecho --error "MariaDB/MySQL Server is not running on localhost." echo exit 1 fi ${mysql_basedir}/mysqladmin status >/dev/null 2>&1 if [ "${?}" -ne 0 ] then echo mecho -n --error 'MariaDB/MySQL Server' mecho -n --std " 'root' " mecho --error 'password is required.' mecho --info 'Please set the root password.' echo exit 1 fi } # --------------------------------------------------------------------------- # get_passwd # --------------------------------------------------------------------------- get_passwd() { clrhome mecho -n --info "Please enter Admin and Password for DB " mecho "'${host}'" echo _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Name of MariaDB/MySQL admin:" "" "+" > ${_ask_tmpfile} rc=${?} read admin_user < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi count=1 while [ ${count} -le 3 ] do _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Password for MariaDB/MySQL admin:" "" "+hidden+" > ${_ask_tmpfile} rc=${?} read password < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi echo if [ -n "${password}" ] then ${mysql_basedir}/mysqladmin \ -h ${host} -u ${admin_user} \ -p${password} status >/dev/null 2>&1 if [ ${?} -eq 0 ] then break else mecho --error "Password input error" echo if [ ${count} -eq 3 ] then anykey exit 0 fi fi count=$(expr ${count} + 1) fi done admin_pass="-p${password}" } # --------------------------------------------------------------------------- # list configured servers # --------------------------------------------------------------------------- list_configured_servers() { mecho mecho 'Configured activ servers:' mecho techo --begin '3 4 20 30' techo --row '' --info "No." --info "Host" --info "Advanced features" # begin idx -le ${PHPMYADMIN_SERVER_N} idx=1 while [ "${idx}" -le "${PHPMYADMIN_SERVER_N}" ] do eval active='${PHPMYADMIN_SERVER_'${idx}'_ACTIVE}' # begin $active if [ "${active}" = "yes" ] then eval host='${PHPMYADMIN_SERVER_'${idx}'_HOST}' eval port='${PHPMYADMIN_SERVER_'${idx}'_PORT}' eval advancedFeaturesActive='${PHPMYADMIN_SERVER_'${idx}'_ADVANCED_FEATURES}' if [ "${advancedFeaturesActive}" = "yes" ] then eval pmadb='${PHPMYADMIN_SERVER_'${idx}'_PMADB}' eval controluser='${PHPMYADMIN_SERVER_'${idx}'_CONTROLUSER}' eval controlpass='${PHPMYADMIN_SERVER_'${idx}'_CONTROLPASS}' techo --row '' ${idx} ${host} "active" else techo --row '' ${idx} ${host} "not active" fi # end $active else techo --row '' ${idx} "not active" fi # end idx -le ${PHPMYADMIN_SERVER_N} idx=$(${EXPR} ${idx} + 1) done techo --end echo _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Select" "" "1-$(${EXPR} ${idx} - 1)" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read server < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi } # --------------------------------------------------------------------------- # print result # --------------------------------------------------------------------------- print_result() { if [ ${1} -eq 0 ] then mecho --ok else mecho --fail fi } # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------