#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/apache2-config-modules-phpmyadmin-common-tools-pma-user # # Creation: 2007-01-22 starwarsfan # Last Update: $Id$ # # Copyright (c) 2007-2009 the eisfair team, team(at)eisfair(dot)org # 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. #---------------------------------------------------------------------------- # 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 # --------------------------------------------------------------------------- # create the sql script and execute it # --------------------------------------------------------------------------- db_operation() { _server=${1} # check if entered server is active eval active='${'${project_name}'_SERVER_'${_server}'_ACTIVE}' if [ "${active}" = "yes" ] then # check if advanced features are activated eval pmadb_use='${'${project_name}'_SERVER_'${_server}'_PMADB_USE}' if [ "${pmadb_use}" = "yes" ] then eval host='${'${project_name}'_SERVER_'${_server}'_HOST}' eval port='${'${project_name}'_SERVER_'${_server}'_PORT}' eval pmadb_name='${'${project_name}'_SERVER_'${_server}'_PMADB_NAME}' eval controluser='${'${project_name}'_SERVER_'${_server}'_CONTROLUSER}' eval controlpass='${'${project_name}'_SERVER_'${_server}'_CONTROLPASS}' if [ -z "${port}" ] then port=3306 fi case "${host}" in localhost|127.0.0.1) get_defaults defaults_ret=${?} if [ ${defaults_ret:-1} -eq 0 ] then check_status localhost database_option="--socket=${mysql_socket}" else echo mecho --error 'MariaDB/MySQL Server is not running on localhost.' echo anykey select_server fi ;; *) check_status externhost database_option="--host=${host} --port=${port}" get_admin_and_passwd ;; esac echo mecho -n --info 'Please enter host from which the pma user ' mecho -n --info "accesses server ' " mecho -n "${host}" mecho --info "'." _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Normally this should be the IP or FQDN of this machine:" "" "+" > ${_ask_tmpfile} rc=${?} read pmaHost < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then check_executable exit 127 fi # pmaHost=`/var/install/bin/ask "Normally this should be the IP or FQDN of this machine: " "" "+"` echo mecho -n --info "Setting rights for pma user '" mecho -n "${controluser}@${pmaHost}" mecho -n --info "' on server '" mecho -n "${host}" mecho --info "'." echo mecho 'If the pma user is not existing, it will be created.' _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Continue" "y" > ${_ask_tmpfile} rc=${?} read executeSQL < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then check_executable exit 127 fi # executeSQLScript=`/var/install/bin/ask "Continue" "y"` if [ "${executeSQL}" = "yes" ] then ${database_exec} \ ${database_option} \ -u ${admin_user} ${admin_pass} \ -e "GRANT SELECT, INSERT, DELETE, UPDATE ON \ ${pmadb_name}.* TO '${controluser}'@'${pmaHost}' \ IDENTIFIED BY '${controlpass}';FLUSH PRIVILEGES;" print_result ${?} else mecho "Creation of pma user canceled" fi else # advanced features not activated mecho mecho -n --info 'phpMyAdminDB on server ' mecho -n --std "'${_server}' " mecho --info 'is not active.' mecho fi # end of advanced features active check else # given server number is not active mecho mecho -n --info 'Server ' mecho -n --std "'${_server}' " mecho --info 'is not active.' mecho fi # end of server active check anykey } # --------------------------------------------------------------------------- # select server # --------------------------------------------------------------------------- select_server() { clrhome mecho mecho 'This script will create or alter the pma database user. To do' mecho 'this you have to choose one of the available servers and enter name' mecho 'and password of a user with admin rights on the choosen server.' mecho list_configured_servers case ${server} in '') check_executable exit 0 ;; 0) check_executable exit 127 ;; *) db_operation ${server} select_server ;; esac } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { alias="${1}" project_name=$(echo ${alias} | tr [:lower:] [:upper:]) # include config . /etc/config.d/${alias} # include helper function . /var/install/bin/apache2-config-modules-phpmyadmin-common-tools-helper select_server check_executable exit 0 } # --------------------------------------------------------------------------- # call function main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------