#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/apache2-config-modules-phpmyadmin-common-tools-pma-db # # 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 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 check_executable exit 127 fi case ${option} in '') select_server ;; 0) check_executable exit 127 ;; 1) # drop db and create new mecho mecho -n "Creating SQL script for server '" mecho -n --info "${host}" mecho "' ... " createSQLScriptHeader ${host} ${pmadb_name} ${controluser} createSQLScriptDropDB ${host} ${pmadb_name} ${controluser} # createSQLScriptGrantPrivileges ${host} ${pmadb_name} ${controluser} createSQLScriptCreateTables ${host} ${pmadb_name} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${database_exec} \ ${database_option} \ -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_name} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${database_exec} \ ${database_option} \ -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_name}" mecho -n "' on server '" mecho -n --info "${host}" mecho "' ... " ${database_exec} \ ${database_option} \ -u ${admin_user} ${admin_pass} \ -e "DROP DATABASE ${pmadb_name};" print_result ${?} ;; 4) # update tables mecho mecho -n "Creating SQL script for server '" mecho -n --info "${host}" mecho "' ... " createSQLScriptHeader ${host} ${pmadb_name} ${controluser} createSQLScriptCreateDB ${host} ${pmadb_name} ${controluser} createSQLScriptCreateTables ${host} ${pmadb_name} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${database_exec} \ ${database_option} \ -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_name} ${controluser} createSQLScriptCreateDB ${host} ${pmadb_name} ${controluser} # createSQLScriptGrantPrivileges ${host} ${pmadb_name} ${controluser} createSQLScriptCreateTables ${host} ${pmadb_name} ${controluser} print_result ${?} mecho -n "Executing SQL script for server '" mecho -n --info "${host}" mecho "' ... " ${database_exec} \ ${database_option} \ -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 -n --info 'phpMyAdminDB on server ' mecho -n --std "'${_server}' " mecho --info 'is not active.' mecho fi # end of advanced features active check else # server is not active mecho mecho -n --info 'Server ' mecho -n --std "'${_server}' " mecho --info '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 '') 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 #----------------------------------------------------------------------------