summaryrefslogtreecommitdiff
path: root/localezcreate
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2002-12-09 00:17:34 +0000
committerJonas Smedegaard <dr@jones.dk>2002-12-09 00:17:34 +0000
commit03142063b852bb038951db3f24ef47a9006a3d93 (patch)
tree3ed497dc23e3f515c9f3b968579de5b1c063155c /localezcreate
parentc569a57540837ee4c4e2f625f34f69551cbefd79 (diff)
Add option --debug (showing options set and directories used).
Finally making setopts function work (renamed from setparams). Replace (almost) all && and contructs with if-then. Fix default handling of templates, languages and sql.
Diffstat (limited to 'localezcreate')
-rwxr-xr-xlocalezcreate182
1 files changed, 126 insertions, 56 deletions
diff --git a/localezcreate b/localezcreate
index 632070b..03fb425 100755
--- a/localezcreate
+++ b/localezcreate
@@ -3,7 +3,7 @@
# /usr/local/sbin/localezcreate
# Copyright 2001-2002 Jonas Smedegaard <dr@jones.dk>
#
-# $Id: localezcreate,v 1.22 2002-12-08 18:52:43 jonas Exp $
+# $Id: localezcreate,v 1.23 2002-12-09 00:17:34 jonas Exp $
#
# Create local eZ Publish site
#
@@ -20,7 +20,7 @@ set -e
prg=`basename $0`
-TEMP=`getopt -o hu:g:d:a:m:N:U:D:Z:i::v::q::f:: --long help,user:,group:,domain:,mailuser:,maildomain:,dbname:,dbuser:,dbserver:,dballow:,info::,verbose::,query::,force:: -n "$prg" -- "$@"`
+TEMP=`getopt -o hu:g:d:a:m:N:U:D:Z:i::v::q::f:: --long help,user:,group:,domain:,mailuser:,maildomain:,dbname:,dbuser:,dbserver:,dballow:,info::,verbose::,debug::,query::,force:: -n "$prg" -- "$@"`
# Check for non-GNU getopt
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
@@ -29,10 +29,10 @@ eval set -- "$TEMP"
# Defaults are evaluated at runtime in this order
# (If changing defaults, you might need to change these as well)
-opts1="user group domain maildomain dbserver dballow" # Options with self-contained defaults
+opts1="user group domain maildomain dbserver dballow templates languages sqlchunks templatedirs languagedirs sqldirs" # Options with self-contained defaults
opts2="dbuser home" # Options requiring $opts1 to resolve default
opts3="mailuser dbname basedir adminhost webcfg" # Options requiring $opts1, $opts2 or $host to resolve default
-optsboolean="info verbose query force" # Do not touch these!
+optsboolean="debug verbose info query force" # Do not touch these!
# Defaults
defaultuser="www-data"
@@ -46,20 +46,21 @@ defaultdbserver="localhost"
defaultdballow="localhost"
defaultinfo="on"
defaultverbose="off"
+defaultdebug="off"
defaultquery="on"
defaultforce="off"
# Defaults not (yet) user configurable
-templates=""
-languages="en_GB en_GB_org"
-sqlchunks="publish data"
+defaulttemplates=""
+defaultlanguages="en_GB en_GB_org"
+defaultsqlchunks="publish data"
defaulthome="/var/www"
defaultbasedir='/var/www/ez-$host.$domain'
defaultadminhost='admin.$host.$domain'
defaultwebcfg='/etc/apache/vhosts.d/ez-$host.$domain'
-templatedirs="/usr/src/ezpublish/templates"
-languagedirs="/usr/src/ezpublish/lang"
-sqldirs="/usr/share/ezpublish/sql"
+defaulttemplatedirs="/usr/src/ezpublish/templates"
+defaultlanguagedirs="/usr/src/ezpublish/lang"
+defaultsqldirs="/usr/share/ezpublish/sql"
# Override defaults from config file if available
if [ -e /etc/local/localezcreate.conf ]; then
@@ -71,6 +72,9 @@ sourcedirs="/usr/src/ezpublish"
sources="lib data tpl www"
bindir="/usr/share/ezpublish/bin"
+# This needs to exist from before parsing options
+debug="off"
+
function usage() {
echo "Usage: $prg [OPTION]... HOST [HOST]..."
echo "Create local eZ Publish sites"
@@ -93,6 +97,7 @@ function usage() {
echo " $defaultdballow)"
echo " -i, --info[=on|off] Show info during installation (default: $defaultinfo)"
echo " -v, --verbose[=on|off] Show details during installation (default: $defaultverbose)"
+ echo " --debug[=on|off] Show debug during installation (default: $defaultdebug)"
echo " -q, --query[=on|off] Ask for missing options (default: $defaultquery)"
echo " -f, --force[=on|off] Replace existing installation (default: $defaultforce)"
echo
@@ -101,10 +106,28 @@ function usage() {
echo "MySQL password for \$dbuser can be stored in \$HOME/.my.cnf of \$user."
}
-function setparams () { # TODO: Handle default argument '[[ASK]]', and fail loudly on empty defaults
- for param in $@; do
- eval "$param=`eval \"echo \"\\\"\$\{$param:-\\\$default${param}\}\\\"\"\"`"
-# [ $verbose ] && echo "--> $param="`eval echo \$\{$param\}`
+function setopts () {
+ for opt in $@; do
+ defaultvalue="`eval echo \$\{default$opt\}`"
+ value="`eval echo \$\{$opt:-$defaultvalue\}`"
+ if [ "$value" = '[[ASK]]' ]; then
+ if [ -n "$query" ]; then
+ echo -n "Enter value for $opt: "
+ read value
+ echo
+ else
+ echo "ERROR: value for $opt requested, but not running interactively!"
+ exit 1
+ fi
+ fi
+ if [ -z "$value" ]; then
+ echo "ERROR: Value of \"$opt\" is empty!"
+ exit 1
+ fi
+ eval $opt=\"$value\"
+ if [ "$debug" = "1" -o "$debug" = "on" ]; then
+ echo "----> $opt=\"$value\" (default: \"$defaultvalue\")"
+ fi
done
}
@@ -122,6 +145,7 @@ while true ; do
-Z|--dballow) dballow="$2"; shift 2;;
-i|--info) case "$2" in ""|on) info="on";; *) info="off";; esac; shift 2;;
-v|--verbose) case "$2" in ""|on) verbose="on";; *) verbose="off";; esac; shift 2;;
+ --debug) case "$2" in ""|on) debug="on";; *) debug="off";; esac; shift 2;;
-q|--query) case "$2" in ""|on) query="on";; *) query="off";; esac; shift 2;;
-f|--force) case "$2" in ""|on) force="on";; *) force="off";; esac; shift 2;;
--) shift; break;;
@@ -129,28 +153,33 @@ while true ; do
esac
done
-setparams $opts1
-setparams $opts2
-optdbserver="-p$dbserver"
-if [ "$dbserver" = "localhost" ]; then
- optdbserver="" # Do not force TCP/IP access when connecting locally
+setopts $optsboolean
+if [ "$debug" = "1" -o "$debug" = "on" ]; then
+ verbose="on" # Debug implies verbose
fi
-setparams $optsboolean
for boolean in $optsboolean; do
case `eval echo \$\{$boolean\}` in
on) eval $boolean="1";;
off) eval $boolean="";;
- *) echo "ERROR: Parameter of boolean option \"$boolean\" must be \"on\" or \"off\"!"; exit 1;;
+ *) echo "ERROR: Value of boolean option \"$boolean\" must be \"on\" or \"off\"!"; exit 1;;
esac
done
+setopts $opts1
+setopts $opts2
+optdbserver="-p$dbserver"
+if [ "$dbserver" = "localhost" ]; then
+ optdbserver="" # Do not force TCP/IP access when connecting locally
+fi
-[ $verbose ] && echo "Figure out database users and passwords"
+if [ -n "$verbose" ]; then
+ echo "--> Figure out database users and passwords"
+fi
if [ -z "$dbpass" ]; then
if [ -f $home/.my.cnf ]; then
dbpass=$(grep password $home/.my.cnf | awk -F= '{print $2}' | head -1 | sed 's/^ //g')
fi
if [ -z "$dbpass" ]; then
- if [ $query ]; then
+ if [ -n "$query" ]; then
echo -n "Enter database password for MySQL user $dbuser: "
read -s dbpass
echo
@@ -164,11 +193,13 @@ if [ -e /usr/share/wwwconfig-common/mysql-localadmpass.get -a "$dbserver" = "loc
status=""
. /usr/share/wwwconfig-common/mysql-localadmpass.get
if [ "$status" = "error" ] ; then
- [ $verbose ] && echo "$error"
+ if [ -n "$info" ]; then
+ echo "--> $error"
+ fi
fi
fi
if [ -z "$dbadmin" ]; then
- if [ $query ]; then
+ if [ -n "$query" ]; then
echo -n "Enter database administrator user (usually root): "
read dbadmin
echo
@@ -178,7 +209,7 @@ if [ -z "$dbadmin" ]; then
fi
fi
if [ -z "$dbadmpass" ]; then
- if [ $query ]; then
+ if [ -n "$query" ]; then
echo -n "Enter database password for administrator $sbadmin: "
read -s dbadmpass
echo
@@ -193,20 +224,32 @@ fi
##############################################
for host do
-[ $info ] && echo "Installing $host..."
+if [ -n "$info" ]; then
+ echo "Installing $host..."
+fi
-setparams $opts3
+setopts $opts3
-[ $verbose ] && echo "Check for existing installation"
+if [ -n "$verbose" ]; then
+ echo "--> Check for existing installation"
+fi
error=""
if [ -d $basedir ]; then
- error="Target directory"`[ $verbose ] && echo " $basedir"`" already exists."
+ if [ -n "$verbose" ]; then
+ error="Target directory $basedir already exists."
+ else
+ error="Target directory already exists."
+ fi
elif [ -f $webcfg ]; then
- error="Apache config"`[ $verbose ] && echo " $webcfg"`" already exists."
+ if [ -n "$verbose" ]; then
+ error="Apache config $webcfg already exists."
+ else
+ error="Apache config already exists."
+ fi
fi
# TODO: Check for existing MySQL database
if [ -n "$error" ]; then
- if [ $query ]; then
+ if [ -n "$query" ]; then
echo "WARNING: $error"
echo -n "Overwrite existing installation (y/N)?: "
read ack
@@ -216,20 +259,21 @@ if [ -n "$error" ]; then
*) echo "Installation aborted!"; exit 1;;
esac
fi
- if [ $force ]; then
- if [ $query ]; then
- mysqladmin -u$dbadmin -p$dbadmpass $optdbserver drop $dbname
- else
- mysqladmin -u$dbadmin -p$dbadmpass $optdbserver -f drop $dbname
- fi
+ if [ -n "$force" ]; then
+ mysqladmin -u$dbadmin -p$dbadmpass $optdbserver -f drop $dbname
rm -rf $basedir
+ rm -f $webcfg
else
echo "ERROR: $error!"
exit 1
fi
fi
-[ $verbose ] && echo "Create database $dbname"`[ "$dbserver" != "localhost" ] && echo " on $dbserver"`
+if [ -n "$verbose" -a "$dbhost" != "localhost" ]; then
+ echo "--> Create database $dbname on $dbserver"
+elif [ -n "$verbose" ]; then
+ echo "--> Create database $dbname"
+fi
if [ -e /usr/share/wwwconfig-common/mysql-createdb.sh ] ; then
status=""
. /usr/share/wwwconfig-common/mysql-createdb.sh
@@ -242,7 +286,9 @@ else
mysqladmin -u$dbadmin -p$dbadmpass $optdbserver create $dbname
fi
-[ $verbose ] && echo "Create/update database user $dbuser"
+if [ -n "$verbose" ]; then
+ echo "--> Create/update database user $dbuser"
+fi
if [ -e /usr/share/wwwconfig-common/mysql-createuser.sh ] ; then
status=""
. /usr/share/wwwconfig-common/mysql-createuser.sh
@@ -259,16 +305,22 @@ else
done
fi
-[ $verbose ] && echo -n "Fill the database: "
+if [ -n "$verbose" ]; then
+ echo -n "--> Fill the database: "
+fi
for chunk in $sqlchunks; do
- [ $verbose ] && echo -n "$chunk "
+ if [ -n "$verbose" ]; then
+ echo -n "$chunk "
+ fi
found=""
sqlfile=${chunk}_mysql.sql
for dir in $sqldirs; do
if [ -f $dir/$sqlfile ]; then
found="1"
sqldir=$dir
- [ $verbose ] && echo -n "($dir) "
+ if [ -n "$debug" ]; then
+ echo -n "($dir) "
+ fi
break
fi
done
@@ -284,41 +336,55 @@ for chunk in $sqlchunks; do
cat $sqldir/$sqlfile | mysql -u$dbadmin -p$dbadmpass $optdbserver $dbname
fi
else
- [ $verbose ] && echo
+ if [ -n "$verbose" ]; then
+ echo
+ fi
echo "ERROR: $chunk not found!"
exit 1
fi
done
-[ $verbose ] && echo
-
-[ $verbose ] && echo "Create base directory $basedir"
+if [ -n "$verbose" ]; then
+ echo
+ echo "--> Create base directory $basedir"
+fi
mkdir $basedir
-
for area in source language template; do
- [ $verbose ] && echo -n "Unpacking $area files: "
+ if [ -n "$verbose" ]; then
+ echo -n "--> Unpacking $area files: "
+ fi
for tarball in `eval echo \$\{${area}s\}`; do
- [ $verbose ] && echo -n "$tarball "
+ if [ -n "$verbose" ]; then
+ echo -n "$tarball "
+ fi
found=""
for dir in `eval echo \$\{${area}dirs\}`; do
if [ -f $dir/$tarball.tar.gz ]; then
found="1"
tarballdir=$dir
- [ $verbose ] && echo -n "($dir) "
+ if [ -n "$debug" ]; then
+ echo -n "($dir) "
+ fi
break
fi
done
if [ "$found" = "1" ]; then
(cd $basedir && tar -xz -C $basedir -f $tarballdir/$tarball.tar.gz) || exit 1
else
- [ $verbose ] && echo
+ if [ -n "$verbose" ]; then
+ echo
+ fi
echo "ERROR: $area $tarball not found!"
exit 1
fi
done
- [ $verbose ] && echo
+ if [ -n "$verbose" ]; then
+ echo
+ fi
done
-[ $verbose ] && echo "Configuring website"
+if [ -n "$verbose" ]; then
+ echo "--> Configuring website"
+fi
(cd $basedir && $bindir/modfix.sh >/dev/null) || exit 1 # TODO: Check if these are in sync and disable one of them
(cd $basedir && $bindir/secure_modfix.sh $user $group >/dev/null) || exit 1
mkdir -p $basedir/override
@@ -353,7 +419,9 @@ ReplyAddress=$mailuser@$maildomain
chown -R $user:$group $basedir
-[ $verbose ] && echo "Configuring Apache"
+if [ -n "$verbose" ]; then
+ echo "--> Configuring Apache"
+fi
echo "# Generated by $prg
<VirtualHost *>
ServerName $host.$domain
@@ -397,4 +465,6 @@ echo "# Generated by $prg
done
-[ $info ] && echo "All done! (Remember to reload the webserver...)"
+if [ -n "$info" ]; then
+ echo "All done! (Remember to reload the webserver...)"
+fi