#!/bin/bash # This script sets the DB connection parameters in the # site settings file (settings.php). # # The script will operate on any parameters supplied on # the command line. If none are supplied, the script will # operate in interactive mode, prompting for all parameters. # include library file . "`dirname ${0}`/drupalLibrary.sh" printUsage() { echo -e " " echo -e "Sets database connection parameters into a site's settings file." echo -e "Operates in interactive mode if no parameters defined on command line." echo -e " " echo -e "Usage:" echo -e "$0 [-noconfirm] [-dbhost ] [-dbname ] [-user ] [-pass ] [install group root dir]" echo -e "where:" echo -e " " echo -e "-noconfirm" echo -e "\tSupresses the confirmation request. (ignored in interactive mode)" echo -e " " echo -e " - The host on which the site's database runs." echo -e " - The name of this site's database." echo -e " - The database username." echo -e " - The password associated with the username." echo -e " " outputGroupRootDirUsage echo -e " " } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi echo " " # Handle flags pInteractive="yes" pUser=""; pPass=""; pDBHost=""; pDBName=""; while (true); do case "${1}" in -user | -pass | -dbhost | -dbname ) if [ $# -lt 3 ]; then echo -e "** No argument supplied for '${1}' parameter. Aborting.\n" printUsage exit 1 fi pInteractive="" case "${1}" in -dbhost ) pDBHost="${2}" ;; -dbname ) pDBName="${2}" ;; -user ) pUser="${2}" ;; -pass ) pPass="${2}" ;; esac shift; shift ;; -noconfirm ) pNoConfirm="-noconfirm"; shift; ;; * ) break ;; esac done # process Group Root Dir pRootDir="`getGroupRootDir "${2}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi pInstall="${1}" # Validate the installation errorStr="`validateSite "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified install: ${errorStr}. Aborting.\n"; exit 1 fi ######### if [ -n "${pInteractive}" ]; then # Running in interactive mode # Get default information from site. defaultDBHost="`getDBHost "${pInstall}" "${pRootDir}"`" defaultDBName="`getDBName "${pInstall}" "${pRootDir}"`" defaultUser="`getDBUsername "${pInstall}" "${pRootDir}"`" defaultPass="`getDBPassword "${pInstall}" "${pRootDir}"`" # Run thru interactive questions read -p "Database hostname [${defaultDBHost}]: " pDBHost read -p "Database name [${defaultDBName}]: " pDBName read -p "Database username [${defaultUser}]: " pUser read -p "Database password [${defaultPass}]: " pPass if [ -z "${pDBHost}" -a -z "${pDBName}" -a -z "${pUser}" -a -z "${pPass}" ]; then echo -e "\n** No settings changes made." exit 0 fi fi # Confirm if [ -z "${pNoConfirm}" ]; then if [ -n "${pInteractive}" ]; then echo " " fi echo "Seting the following DB connection parameters on site '${pInstall}':" if [ -n "${pDBHost}" ]; then echo -e "\tDB host: '${pDBHost}'" fi if [ -n "${pDBName}" ]; then echo -e "\tDB name: '${pDBName}'" fi if [ -n "${pUser}" ]; then echo -e "\tusername: '${pUser}'" fi if [ -n "${pPass}" ]; then echo -e "\tpassword: '${pPass}'" fi echo "Press to continue, or ^C to quit..." read fi # Make changes if [ -n "${pDBHost}" ]; then setDBHost "${pInstall}" "${pRootDir}" "${pDBHost}" fi if [ -n "${pDBName}" ]; then setDBName "${pInstall}" "${pRootDir}" "${pDBName}" fi if [ -n "${pUser}" ]; then setDBUsername "${pInstall}" "${pRootDir}" "${pUser}" fi if [ -n "${pPass}" ]; then setDBPassword "${pInstall}" "${pRootDir}" "${pPass}" fi # done echo -e "\n** Done."