#!/bin/ksh93 ETCMAIL='/etc/mail' CFDIR='/usr/lib/mail' M4=${M4:-/usr/bin/m4} SCRIPT=${0##*/} CFFILE='' USAGE='[+NAME?'"${SCRIPT}"' - create a new sendmail configuration file using a m4 mail config file]'" [+DESCRIPTION?A simple script to create a sendmail configuration file (*.cf) from a m4 mail config file (*.mc). It basically takes \afile\a\b.mc\b, generates a corresponding \afile\a\b.cf\b and symlinks it to \bsendmail.cf\b. If \afile\a\b.cf\b already exists, it gets copied to \afile\a\b.bak\b before the \bcf\b file gets overwritten.] [+?Without any option, ${SCRIPT} creates a new \b${ETCMAIL}/client.cf\b from the file \b${ETCMAIL}/client.mc\b and symlinks it to \b${ETCMAIL}/sendmail.cf\b. This is a nullclient configuration file, which instructs sendmail to send all mails unmangled to the central mail gateway with the hostname \bmailhost\b.] [h:help?Print this help and exit.] [c:config]:[file?Use the given m4 \afile\a to create a new \b${ETCMAIL}/\b\afile\a\b.cf\b, which than gets symlinked to \b${ETCMAIL}/sendmail.cf\b.] [s:server?Use the m4 file \b${ETCMAIL}/server.mc\b to create a new \b${ETCMAIL}/server.cf\b, which than gets symlinked to \b${ETCMAIL}/sendmail.cf\b. This is meant as an example, only. You should copy the \bserver.mc\b to another file (e.g. myserver.mc), adjust the settings and execute '\b${SCRIPT} -c myserver.mc\b'.] [d:direct]:[dir?Create the \bcf\b file as well as the \bsendmail.cf\b symlink to it in the directory \adir\a instead of \b${ETCMAIL}/\b.] [+NOTES?Since Solaris 10 it is possible to generate the sendmail server config file (per default \b/etc/mail/sendmail.cf\b) as well as the sendmail client config file (per default \b/etc/mail/submit.cf\b) on startup of the corresponding service automatically - see \bsendmail\b(4). So if you use this script without the option \b-d ...\b as well as the described mechanism, the generated \bcf\b file on startup may overwrite the \bcf\b file generated by this script!] [+?Whenever a new \bcf\b file gets generated, the related sendmail service needs to be restarted to take the changes into account.] [+SEE ALSO?\bsendmail\b(4), \bsvcadm\b(1M)] " if [[ ! -d ${ETCMAIL} ]]; then print -u2 "Mail configuration directory '$ETCMAIL' does not exist!" exit 1 fi if [[ ! -d ${CFDIR} ]]; then print -u2 "Sendmail m4 config files directory '${CFDIR}' does not exist!" exit 2 fi if [[ ! -x ${M4} ]]; then M4=${ whence m4 ; } [[ -z ${M4} ]] && M4=${ whence gm4 ; } if [[ -n ${M4} ]]; then print "Using ${M4} as macro processor." elif [[ -x /local/usr/bin/m4 ]]; then M4=/local/usr/bin/m4 elif [[ -x /usr/local/bin/m4 ]]; then M4=/usr/local/bin/m4 else print -u2 'Unable to find a usable m4 macro processor!' exit 3 fi fi DESTDIR="${ETCMAIL}" integer SERVER=0 while getopts -a ${SCRIPT} "${ print ${USAGE} ; }" OPT ; do case $OPT in s) SERVER=1 ;; c) CFFILE="${OPTARG}" ;; d) [[ ! -d ${OPTARG} ]] && \ print -u2 "Directory '${OPTARG}' does not exists." && exit 7 DESTDIR="${OPTARG}" ;; h|*) $0 --man ; exit ;; esac done if [[ -z ${CFFILE} ]]; then CFFILE="${ETCMAIL}/" (( SERVER )) && CFFILE+=server.mc || CFFILE+=client.mc else [[ ${F:0:1} != '/' ]] && CFFILE="${PWD}/${CFFILE}" fi if [[ ! -r ${CFFILE} ]]; then print -u2 "sendmail m4 config file '${CFFILE}' is not readable." exit 4 fi print "Using '${CFFILE}' for configuration." TARGET="${CFFILE##*/}" TARGET="${TARGET%.*}'.cf'" if [[ ${DESTDIR}/${TARGET} == ${CFFILE} ]]; then print -u2 ' Please rename your configuration file to something else than '"${CFFILE}"' since we do not want to overwrite it. E.g.: '"${DESTDIR}/${TARGET}.mc"' ' exit 5 fi "${M4}" -D_CF_DIR_=${CFDIR}/ ${CFDIR}/m4/cf.m4 "${CFFILE}" \ >"${DESTDIR}/${TARGET}.tmp" if (( $? )); then print -u2 ' Unable to produce '"${DESTDIR}/${TARGET}."' '"${DESTDIR}/${TARGET}.tmp"' contains, what I got so far. Delete it, if you do not need it for troubleshooting.' exit 6 fi cd "${DESTDIR}" [[ -e ${TARGET} ]] && mv "${TARGET}" "${TARGET}.bak" mv "${TARGET}.tmp" "${TARGET}" chmod 644 "${TARGET}" rm -f sendmail.cf ln -sf "./${TARGET}" sendmail.cf print ' Done. Check the new '"'${DESTDIR}/sendmail.cf'"' and restart sendmail, if it is ok. ' if [[ -e ${TARGET}.bak ]]; then print ' Otherwise cp the old '"'${DESTDIR}/${TARGET}.bak'"' back to '"'${DESTDIR}/sendmail.cf'"'. ' fi