#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/phpmyadmin-tools-pma-db # # Creation: 2007-01-22 starwarsfan # Last Update: $Id$ # # Copyright (c) 2007-2009 the eisfair team, team(at)eisfair(dot)org # Maintained by Y. Schumann, yves(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 config . /etc/config.d/phpmyadmin # include eislib . /var/install/include/eislib # include helper function . /var/install/bin/phpmyadmin-tools-helper #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # --------------------------------------------------------------------------- # Create Header for the SQL-Script # --------------------------------------------------------------------------- createSQLScriptHeader() { givenHost=$1 givenDBName=$2 givenControluser=$3 cat >${tmpSQLScript} <>${tmpSQLScript} <>${tmpSQLScript} <>${tmpSQLScript} <>${tmpSQLScript} <${tmpSQLScript} <${_ask_tmpfile} rc=${?} read option < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi case ${option} in '') exit 0 ;; 0) exit 127 ;; 1) # drop db and create new mecho mecho -n "Creating SQL script for server '" mecho -n --info "${host}" mecho "' ... " createSQLScriptHeader ${host} ${pmadb} ${controluser} createSQLScriptDropDB ${host} ${pmadb} ${controluser} # createSQLScriptGrantPrivileges ${host} ${pmadb} ${controluser} createSQLScriptCreateTables ${host} ${pmadb} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${mysql_basedir}/mysql \ -h ${host} \ -u ${admin_user} ${admin_pass} < ${tmpSQLScript} print_result ${?} mecho 'Removing SQL script ...' ${RM} -f ${tmpSQLScript} print_result ${?} ;; 2) # alter existing pma database mecho mecho -n "Creating SQL script for server '" mecho -n --info "${host}" mecho "' to alter pma database ... " createSQLScriptAlterDB ${host} ${pmadb} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${mysql_basedir}/mysql \ -h ${host} \ -u ${admin_user} ${admin_pass} < ${tmpSQLScript} print_result ${?} mecho 'Removing SQL script ...' ${RM} -f ${tmpSQLScript} print_result ${?} ;; 3) # drop pma database mecho mecho -n "Removing pma database '" mecho -n --info "${pmadb}" mecho -n "' on server '" mecho -n --info "${host}" mecho "' ... " ${mysql_basedir}/mysql \ -h ${host} \ -u ${admin_user} ${admin_pass} \ -e "DROP DATABASE ${pmadb};" print_result ${?} ;; 4) # update tables mecho mecho -n "Creating SQL script for server '" mecho -n --info "${host}" mecho "' ... " createSQLScriptHeader ${host} ${pmadb} ${controluser} createSQLScriptCreateDB ${host} ${pmadb} ${controluser} createSQLScriptCreateTables ${host} ${pmadb} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${mysql_basedir}/mysql \ -h ${host} \ -u ${admin_user} ${admin_pass} < ${tmpSQLScript} print_result ${?} mecho "Removing SQL script ... " ${RM} -f ${tmpSQLScript} print_result ${?} esac else # pmadb not found, create new mecho mecho -n "Creating SQL script for server '" mecho -n --info "${host}" mecho "' ... " createSQLScriptHeader ${host} ${pmadb} ${controluser} createSQLScriptCreateDB ${host} ${pmadb} ${controluser} # createSQLScriptGrantPrivileges ${host} ${pmadb} ${controluser} createSQLScriptCreateTables ${host} ${pmadb} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${mysql_basedir}/mysql \ -h ${host} \ -u ${admin_user} ${admin_pass} < ${tmpSQLScript} print_result ${?} mecho "Removing SQL script ... " ${RM} -f ${tmpSQLScript} print_result ${?} fi else # advanced features not activated mecho mecho --info "Advanced features on server ${_server} not active" mecho fi # end of advanced features active check else # server is not active mecho mecho --info "Server ${_server} is not active" mecho fi # end of server active check # clearup rm -f ${tmpSQLScript} anykey } # --------------------------------------------------------------------------- # select server # --------------------------------------------------------------------------- select_server() { clrhome mecho mecho "This script will create, alter or delete the pma database. 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 '') exit 0 ;; 0) exit 127 ;; *) doDBOperation ${server} select_server ;; esac } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { select_server exit 0 } # --------------------------------------------------------------------------- # call function main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end #----------------------------------------------------------------------------