Listing 2 Creating post-configuration scripts
# cd /var/bootcd/s0/Solaris_8/Product/packages
# cat > netconf
#!/usr/bin/ksh
if [[ $# -ne 1 ]]
then
echo "Usage: ${0} "
exit 1
fi
PATH=${PATH}:.
if [ ! -f ${1} ]
then
echo "ERROR: File ${1} not found"
exit 1
fi
. ${1}
echo "The following configuration is going to be applied:"
echo " IP address : ${IP_ADDRESS}"
echo " Network address : ${NET_ADDRESS}"
echo " Netmask : ${NETMASK}"
echo " Gateway : ${GATEWAY}"
echo " Hostname : ${HOSTNAME}"
if [ ! -z ${DOMAINNAME} ]
then
echo " Default domain : ${DOMAINNAME}"
fi
echo ""
# --- /etc/hosts
echo "Configuring /etc/hosts ..."
if [ -f /etc/hosts ]; then
cp /etc/hosts /etc/hosts.bak.$$
fi
grep -v ${HOSTNAME} /etc/hosts > /etc/hosts.tmp.$$
cat /etc/hosts.tmp.$$ > /etc/hosts
echo "${IP_ADDRESS} ${HOSTNAME} ${HOSTNAME}.${DOMAINNAME}" \
>> /etc/hosts
rm /etc/hosts.tmp.$$
# --- /etc/netmasks
echo "Configuring /etc/netmasks ..."
if [ -f /etc/netmasks ]; then
cp /etc/netmasks /etc/netmasks.bak.$$
fi
grep -v ${NET_ADDRESS} /etc/netmasks > /etc/netmasks.tmp.$$
cat /etc/netmasks.tmp.$$ > /etc/netmasks
echo "${NET_ADDRESS} ${NETMASK}" >> /etc/netmasks
rm /etc/netmasks.tmp.$$
# --- /etc/hostname.
DEVICES="eri bge hme ce"
for dev in ${DEVICES}
do
grep "\"${dev}\"" /etc/path_to_inst > /dev/null 2>&1
if [ $? = 0 ]
then
DEVICE=${dev}0
fi
done
echo "Configuring /etc/hostname.${DEVICE} ... "
if [ -f /etc/hostname.${DEVICE} ]; then
cp /etc/hostname.${DEVICE} /etc/hostname.${DEVICE}.bak.$$
fi
echo "${HOSTNAME}" > /etc/hostname.${DEVICE}
# --- /etc/defaultrouter
echo "Configuring /etc/defaultrouter ... "
if [ -f /etc/defaultrouter ]; then
cp /etc/defaultrouter /etc/deflaultrouter.bak.$$
fi
echo "${GATEWAY}" > /etc/defaultrouter
# --- /etc/nodename
echo "Configuring /etc/nodename ... "
if [ -f /etc/nodename ]; then
cp /etc/nodename /etc/nodename.bak.$$
fi
echo "${HOSTNAME}" > /etc/nodename
# --- /etc/defaultdomain
echo "Configuring /etc/defaultdomain ... "
if [ ! -z ${DOMAINNAME} ]
then
if [ -f /etc/defaultdomain ]; then
cp /etc/defaultdomain /etc/defaultdomain.bak.$$
fi
echo "${DOMAINNAME}" > /etc/defaultdomain
fi
# --- Apply changes live
echo "Applying changes ... \c"
ifconfig ${DEVICE} plumb
ifconfig ${DEVICE} ${IP_ADDRESS} netmask ${NETMASK} up
route add default ${GATEWAY}
domainname ${DOMAINNAME}
hostname ${HOSTNAME}
echo "done."
^D
# chmod +x netconf
Sample configuration file:
# cat > network.conf
#
# IP address of the host
#
IP_ADDRESS=
#
# This is the base address of the network
#
NET_ADDRESS=
#
# Netmask
#
NETMASK=255.255.255.0
#
# Default gateway
#
GATEWAY=
#
# Hostname
#
HOSTNAME="preinst"
#
# Domain name (can stay empty, if not needed)
#
DOMAINNAME=""
^D
|