imip-agent

Annotated conf/tools/configure.sh

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