#!/bin/sh # ---------------------------------------------------------------------------- # /var/install/bin/bcsrv-db-tools # # Creation: 2009-04-03 starwarsfan # Last Update: $Id$ # # Copyright (c) 2007-2008 Yves Schumann # # 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. # ---------------------------------------------------------------------------- #exec 2>/public/bcsrv-db-tools-trace$$.log #set -x #. /etc/config.d/bcsrv . /var/install/include/eislib mysqlDataDir=/var/lib/mysql mysqlBaseDir=/usr scriptName=`basename $0` baculaDBName='bacula' # --------------------------------------------------------------------------- # Show usage # --------------------------------------------------------------------------- showUsage () { cat < /dev/null 2>&1 return $? } # ---------------------------------------------------------------------------- # Grant Bacula database access rights # ---------------------------------------------------------------------------- dropDatabase () { mecho "" if checkDBExistence then if ! ${mysqlBaseDir}/bin/mysql -e"drop database ${baculaDBName};" > /dev/null 2>&1 then mecho -warn "Something went wrong during drop of database '${baculaDBName}'." anykey fi else mecho "Database '${baculaDBName}' not existing, nothing to drop." fi } # ---------------------------------------------------------------------------- # Create Bacula database # ---------------------------------------------------------------------------- createDatabase () { mecho "" if ! checkDBExistence then if ! /usr/local/bacula/scripts/create_mysql_database then mecho -warn "An error occoured during setup of Bacula database." anykey fi else mecho "Database '${baculaDBName}' exists, nothing created." fi } # ---------------------------------------------------------------------------- # Create Bacula tables # ---------------------------------------------------------------------------- dropTables () { mecho "" if ! /usr/local/bacula/scripts/drop_mysql_tables then mecho -warn "An error occoured during drop of Bacula tables." anykey fi } # ---------------------------------------------------------------------------- # Create Bacula tables # ---------------------------------------------------------------------------- createTables () { mecho "" if ! /usr/local/bacula/scripts/make_mysql_tables then mecho -warn "An error occoured during setup of Bacula tables." anykey fi } # ---------------------------------------------------------------------------- # Main # ---------------------------------------------------------------------------- inputValue="0" passwd='' check=false dropDB=false quietMode=false # ----------------------------- # Show usage if no params given if [ "$1" == '-h' ] || [ "$1" == '-help' ] || [ "$1" == '--help' ] then showUsage exit 1 fi # --------------- # Read parameters while [ $# -ne 0 ] do case $1 in '-c'|'--check' ) check=true ;; '-d'|'--drop' ) dropDB=true ;; '--quiet' ) quietMode=true ;; * ) ;; esac shift done mysqlDataDir=`mysqldGetParam datadir` mysqlPidFile=`mysqldGetParam pid-file` # ---------------------------------------------------------------------------- # Check status of mysql # ---------------------------------------------------------------------------- if [ ! -f ${mysqlPidFile} ] then mecho "" mecho -error "MySQL Server not running" mecho "" exit 1 fi if ${check} then checkDBExistence if [ $? -eq 0 ] then mecho "Database '${baculaDBName}' exists, script skipped." exit 0 fi fi if ${dropDB} then dropDatabase fi if ${quietMode} then grantBaculaDBRights createDatabase createTables else until [ "${inputValue}" == "q" ] do clrhome mecho "" mecho " 1 - Grant Bacula DB access" mecho " 2 - Create Bacula Database" mecho " 3 - Create Bacula Tables" mecho " 4 - Drop Bacula Tables" mecho " 5 - Drop Bacula Database" mecho "" inputValue=`/var/install/bin/ask "Please choose an action, 'q' to quit: " "" "*"` case x${inputValue} in x1) grantBaculaDBRights ;; x2) createDatabase ;; x3) createTables ;; x4) /var/install/bin/ask "Are you sure to drop the Bacula tables?" "no" if [ $? -eq 0 ] then dropTables fi ;; x5) /var/install/bin/ask "Are you sure to drop the Bacula database?" "no" if [ $? -eq 0 ] then dropDatabase fi ;; *) ;; esac done fi exit 0 ### -------------------------------------------------------------------------- ### End ### --------------------------------------------------------------------------