1 #!/bin/sh 2 3 DIRNAME=`dirname "$0"` 4 PROGNAME=`basename "$0"` 5 6 if [ "$1" = '--help' ] || [ ! "$1" ] || [ ! "$2" ]; then 7 cat 1>&2 <<EOF 8 Usage: $PROGNAME <definitions file> <output directory> [ <configuration> ] 9 10 Produce files to configure imip-agent using the definitions in the specified 11 file, storing the configuration files in the given output directory. This 12 utility is intended to make the customisation of the example configuration files 13 easier. 14 15 Once the files have been generated, they may be reviewed and copied into the 16 appropriate locations. 17 EOF 18 exit 1 19 fi 20 21 DEFSFILE=$1 22 OUTDIR=$2 23 CONF=${3:-"conf"} 24 25 if [ ! -e "$DEFSFILE" ]; then 26 cat 1>&2 <<EOF 27 The specified definitions file $DEFSFILE does not exist. 28 EOF 29 exit 1 30 fi 31 32 if [ ! -e "$CONF" ]; then 33 cat 1>&2 <<EOF 34 The $CONF directory cannot be found. 35 EOF 36 exit 1 37 fi 38 39 # Obtain the definitions. 40 41 . "$DEFSFILE" 42 43 # Configure the components. 44 45 for COMPONENT in apache exim postfix ; do 46 CONFDIR="$CONF/$COMPONENT" 47 48 for FILENAME in `find "$CONFDIR" -type f` ; do 49 PARENTPATH="$OUTDIR/"`dirname "$FILENAME"` 50 51 # Skip files not relevant for the chosen user database. 52 53 PARENT=`basename "$PARENTPATH"` 54 if ( [ "$USER_DATABASE" = 'Simple' ] && [ "$PARENT" = 'ldap' ] ) || \ 55 ( [ "$USER_DATABASE" = 'LDAP' ] && [ "$PARENT" = 'simple' ] ); then 56 continue 57 fi 58 59 if [ ! -e "$PARENTPATH" ]; then 60 mkdir -p "$PARENTPATH" 61 fi 62 63 envsubst "$SUBSTITUTED" < "$FILENAME" > "$OUTDIR/$FILENAME" 64 done 65 done 66 67 # Copy other files. 68 69 cp "$CONF/aliases.example" "$OUTDIR/$CONF/aliases"