#---------------------------------------------------------------------------- # /var/install/bin/apache2-config-modules-phpmyadmin-common-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' GREP='/usr/bin/grep' XZ='/usr/bin/xz' # --------------------------------------------------------------------------- # defaults # --------------------------------------------------------------------------- get_defaults() { my_server=$(find /etc/config.d -maxdepth 1 \ -name 'mariadb' -printf '%f\n' -o \ -name 'mariadb[0-9]*' -printf '%f\n' -o \ -name 'mysql' -printf '%f\n' -o \ -name 'mysql[0-9]*' -printf '%f\n') if [ -n "${my_server}" ] then for SERVER in ${my_server} do . /etc/config.d/${SERVER} var_prefix=$(echo ${SERVER} | tr [:lower:] [:upper:]) eval connect_port='${'${var_prefix}'_CONNECT_PORT}' my_path=$(echo ${SERVER} | sed 's|[^[:digit:]]||g') if [ ${connect_port:-0} -eq ${port:-1} ] then break fi done fi if [ -n "${my_path}" ] then . /srv/mysql/defaults.info return 0 elif [ -f /var/lib/mysql/defaults.info ] then # old version, deprecated . /var/lib/mysql/defaults.info return 0 else return 1 fi } # --------------------------------------------------------------------------- # check status and access of MariaDB/MySQL Database # --------------------------------------------------------------------------- check_status() { admin_user='root' admin_pass='' local check_running="${1}" database_exec=${mysql_basedir}/mysql case "${check_running}" in localhost) if [ ! -f ${mysql_pid_file} ] then echo mecho --error "MariaDB/MySQL Server is not running on localhost." echo anykey select_server fi ${mysql_basedir}/mysqladmin --socket=${mysql_socket} \ 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 anykey select_server fi ;; externhost) database_exec=/usr/bin/mysql if [ ! -f ${database_exec} ] then # install the mariadb-client package eisman install --auto mariadb-client inst_ret=${?} if [ ${inst_ret} -ne 0 ] then echo mecho --error 'No mysql executable found' mecho --info 'Please install the mariadb-client package' echo anykey exit 1 fi # # the executable is contained # ${XZ} --decompress --quiet /srv/phpmyadmin/mysql.xz # # database_exec=/srv/phpmyadmin/mysql fi # output in tmpfile is require to catch all output from mysql too :-( tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) # use LANG=C to get always the same output to can grep them correctly LANG=C ${database_exec} --host=${host} \ --port=${port} \ --skip-column-names \ -e 'SELECT version()' > ${tmpfile} 2>&1 read status < ${tmpfile} ${RM} -f ${tmpfile} # Error: 2003 (CR_CONN_HOST_ERROR) # Message: Can't connect to MySQL server on '%s' (%d) if echo ${status} | ${GREP} -q 'ERROR 2003' then echo mecho -n --warn "MariaDB/MySQL Server on '" mecho -n --std "${host}" mecho --warn "' is not running" echo anykey select_server fi ;; esac } # --------------------------------------------------------------------------- # get_passwd # --------------------------------------------------------------------------- get_admin_and_passwd() { local count clrhome mecho -n --info "Please enter Admin and Password for MariaDB/MySQL " 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 check_executable 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 check_executable exit 127 fi echo if [ -n "${password}" ] then # output in tmpfile is require to catch all output from # mysql too :-( , 'select version()' is a dummy tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${database_exec} \ --host=${host} \ --port=${port} \ -u${admin_user} \ -p${password} \ --skip-column-names \ -e 'SELECT version()' > ${tmpfile} 2>&1 pw_check_ret=${?} ${RM} -f ${tmpfile} if [ ${pw_check_ret} -eq 0 ] then break else mecho --error 'Password input error' echo if [ ${count} -eq 3 ] then anykey select_server fi fi count=$((${count} + 1)) fi done admin_pass="-p${password}" } # --------------------------------------------------------------------------- # list configured servers # --------------------------------------------------------------------------- list_configured_servers() { local idx mecho mecho 'Configured activ servers:' mecho techo --begin '3 5r 20 27 13' techo --row '' --info 'No.' --info 'Host' --info 'Description' --info 'phpMyAdminDB' eval server_n='${'${project_name}'_SERVER_N}' idx=1 while [ ${idx} -le ${server_n} ] do eval active='${'${project_name}'_SERVER_'${idx}'_ACTIVE}' # begin $active if [ "${active}" = "yes" ] then eval host='${'${project_name}'_SERVER_'${idx}'_HOST}' eval port='${'${project_name}'_SERVER_'${idx}'_PORT}' eval name='${'${project_name}'_SERVER_'${idx}'_NAME}' eval verbose='${'${project_name}'_SERVER_'${idx}'_VERBOSE}' if [ -n "${verbose}" ] then name="${verbose}" fi eval pmadb_use='${'${project_name}'_SERVER_'${idx}'_PMADB_USE}' if [ "${pmadb_use}" = "yes" ] then eval pmadb_name='${'${project_name}'_SERVER_'${idx}'_PMADB_NAME}' eval controluser='${'${project_name}'_SERVER_'${idx}'_CONTROLUSER}' eval controlpass='${'${project_name}'_SERVER_'${idx}'_CONTROLPASS}' techo --row '' "${idx}." "${host}" "${name}" 'active' else techo --row '' "${idx}." "${host}" "${name}" 'not active' fi # end $active else techo --row '' "${idx}." '' '' 'not active' fi idx=$((${idx} + 1)) done techo --end echo _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Select" "" "1-$((${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 } # --------------------------------------------------------------------------- # check executable binary # --------------------------------------------------------------------------- check_executable() { if [ -f /srv/phpmyadmin/mysql ] then ${XZ} --compress --quiet /srv/phpmyadmin/mysql fi # clean up rm -f ${tmpSQLScript} } # --------------------------------------------------------------------------- # print result # --------------------------------------------------------------------------- print_result() { if [ ${1} -eq 0 ] then mecho --ok else mecho --fail fi } # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------