File postfix-update-hostname of Package webyast-mail-ws
#!/bin/bash
#
# Copyright (c) 2010 SUSE LINUX Products GmbH, Germany.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
usage () {
echo $@
echo "usage: $SCRIPTNAME [<config>] <interface> [-o <options>]"
echo ""
echo "Options are:"
echo " [on]boot : we are currently booting (or shutting down)"
echo " debug : be verbose"
echo " dhcp : indicates that we are called by dhcp client"
echo " rc : indicates that we are called from rcnetwork"
echo ""
echo "Any another options are ignored"
echo ""
exit $R_USAGE
}
######################################################################
# change the working direcory and source some common files
#
R_INTERNAL=1 # internal error, e.g. no config or missing scripts
cd /etc/sysconfig/network || exit $R_INTERNAL
test -f ./config && . ./config
test -f ./dhcp && . ./dhcp
test -f scripts/functions && . scripts/functions || exit $R_INTERNAL
test -f /etc/sysconfig/mail && . /etc/sysconfig/mail
test -f /etc/sysconfig/postfix && . /etc/sysconfig/postfix
######################################################################
# check arguments and how we are called (in case of links)
#
SCRIPTNAME=${0##*/}
debug $*
case $1 in ""|-h|*help*) usage ;; esac
CONFIG="$1"
shift
if [ "x$1" != x -a "x$1" != "x-o" ] ; then
INTERFACE="$1"
else
INTERFACE="$CONFIG"
fi
shift
test "x$1" = "x-o" && shift
MODE=''
RUN_FROM_RC=no
DEBUG=${DEBUG:-no}
DHCP=no
while [ $# -gt 0 ]; do
case $1 in
boot|onboot) MODE=onboot ;;
debug) DEBUG=yes ;;
dhcp) DHCP=yes ;;
rc) RUN_FROM_RC=yes ;;
*) debug unknown option $1 ;;
esac
shift
done
# filter out some special interface types
case "$INTERFACE" in
all|noiface|lo) exit 0 ;;
esac
# source interface config to get per interface settings
test -f ./ifcfg-$CONFIG && . ./ifcfg-$CONFIG || exit 0
# the hostname where we write it for the session time
POSTFIX_DHCP_HOSTNAME_FILE="/var/run/dhcp-hostname"
case $0 in
*if-up.d*)
# run only as post if-up.d script
test "x$DHCP" = xyes || exit 0
# allow the user to disable this feature
test "x${POSTFIX_DHCP_HOSTNAME_UPDATE:-yes}" = xyes || exit 0
# only when dhcp is allowed to set the hostname anyway
test "x$DHCLIENT_SET_HOSTNAME" = xyes || exit 0
# and when SuSEconfig.postfix handles postfix config
test "x$MAIL_CREATE_CONFIG" = xyes || exit 0
# update when we are the primary (first) dhcp interface
is_dhcp_primary=`read_cached_config_data primary $INTERFACE`
test "x$is_dhcp_primary" = xyes || exit 0
# write it down and call SuSEconfig.postfix to pickup it
fqhn=`hostname -f 2>/dev/null`
rm -f "$POSTFIX_DHCP_HOSTNAME_FILE"
case $fqhn in
".") ;;
*.*)
{
echo "FQHOSTNAME=$fqhn"
echo "INTERFACE=$INTERFACE"
} > "$POSTFIX_DHCP_HOSTNAME_FILE"
;;
esac
/sbin/SuSEconfig -module postfix
;;
*if-down.d*)
# cleanup when the we are interface that wrote it
if test -f "$POSTFIX_DHCP_HOSTNAME_FILE" ; then
while read line ; do
case $line in
""|\#*) continue ;;
esac
eval "_$line"
done < <(cat "$POSTFIX_DHCP_HOSTNAME_FILE" 2>/dev/null)
if test "x$_INTERFACE" != "x" -a \
"x$_INTERFACE" = "x$INTERFACE" ; then
rm -f "$POSTFIX_DHCP_HOSTNAME_FILE"
/sbin/SuSEconfig -module postfix &>/dev/null
fi
fi
;;
*)
usage
;;
esac