#!/bin/bash # #!F:switch_gethostbyname # #!P:/usr/local/sbin # #!D:Standalone softlink switcher for online/offline hostname resolving # #!C:Copyright 1997-1998 Peter Bieringer # #!V:Version 1.01 18.07.1998 # # Changes to # 1.00: Extraction from my /usr/local/sbin/isdn.dial Version 2.26 # 1.01: Minor corrections PATH=/bin:/usr/bin:/sbin:/usr/sbin ### Info for switching configuration files ## Named # Switching BIND enabled? NAMEDB_SWITCH=yes # Root directory of the DNS data base NAMEDB_ROOT=/etc/namedb # Name of the nameserver daemon NAMEDB_NAME=named #set -x ## Resolver # Switching resolv.conf enabled? RESOLV_SWITCH=yes # Filenames RESOLV_ONLINE=/etc/resolv.conf.online RESOLV_OFFLINE=/etc/resolv.conf.offline RESOLV_ORIG=/etc/resolv.conf ## Hosts # Switching host.conf enabled? HOST_SWITCH=yes # Filenames HOST_ONLINE=/etc/host.conf.online HOST_OFFLINE=/etc/host.conf.offline HOST_ORIG=/etc/host.conf ## Functions # Display information info() { grep "^#!D" $0 | awk -F: '{ print $2}' grep "^#!C" $0 | awk -F: '{ print " " $2}' grep "^#!V" $0 | awk -F: '{ print " " $2}' echo } ### Start info # Decission of some named related settings if [ "$NAMEDB_SWITCH" = "yes" ]; then # Test if named is running TEST=`ps -hx | grep " $NAMEDB_NAME"` if [ ! "$TEST" = "" ]; then # Get PID named NAMEDPID=`echo $TEST | awk '{ print $1 }'` # Get path of named NAMEDPATHBIN=`which $NAMEDB_NAME` # Get major version number of named (4 or 8) NAMEDMAJORVERSION=`strings $NAMEDPATHBIN | grep "^@(#)named" | cut -d " " -f2 | cut -d "." -f1` # Resource files if [ "$NAMEDMAJORVERSION" = "4" ]; then NAMEDB_ONLINE=$NAMEDB_ROOT/named.boot.online NAMEDB_OFFLINE=$NAMEDB_ROOT/named.boot.offline NAMEDB_ORIG=$NAMEDB_ROOT/named.boot echo " Running BIND is version 4" elif [ "$NAMEDMAJORVERSION" = "8" ]; then NAMEDB_ONLINE=$NAMEDB_ROOT/named.conf.online NAMEDB_OFFLINE=$NAMEDB_ROOT/named.conf.offline NAMEDB_ORIG=$NAMEDB_ROOT/named.conf echo " Running BIND is version 8" fi fi fi # Now work like option specified: case $1 in online) # Change softlink to a resolv.conf, # which has online related nameserver entries if [ "$RESOLV_SWITCH" = "yes" ]; then # Test if new file exists if [ ! -f $RESOLV_ONLINE ]; then echo " File '$RESOLV_ONLINE' doesn't exist!" exit 1 fi # Make backup of the existing file, if not a link if [ -f $RESOLV_ORIG -a ! -L $RESOLV_ORIG ]; then mv -bV t $RESOLV_ORIG $RESOLV_ORIG.bak fi echo " Link '$RESOLV_ORIG' to '$RESOLV_ONLINE' for online usage." # Create new or change link ln -f -s $RESOLV_ONLINE $RESOLV_ORIG fi # Change softlink to a host.conf, # which has online related host entries if [ "$HOST_SWITCH" = "yes" ]; then # Test if new file exists if [ ! -f $HOST_ONLINE ]; then echo " File '$HOST_ONLINE' doesn't exist!" exit 1 fi # Make backup of the existing file, if not a link if [ -f $HOST_ORIG -a ! -L $HOST_ORIG ]; then mv -bV t $HOST_ORIG $HOST_ORIG.bak fi echo " Link '$HOST_ORIG' to '$HOST_ONLINE' for online usage." # Create new or change link ln -f -s $HOST_ONLINE $HOST_ORIG fi # Change softlink to a nameserver bootfile, # which has online related entries and reload named if [ "$NAMEDB_SWITCH" = "yes" -a ! "$NAMEDMAJORVERSION" = "" ]; then # Test if new file exists if [ ! -f $NAMEDB_ONLINE ]; then echo " File '$NAMEDB_ONLINE' doesn't exist!" exit 1 fi # Make backup of the existing file, if not a link if [ -f $NAMEDB_ORIG -a ! -L $NAMEDB_ORIG ]; then mv -bV t $NAMEDB_ORIG $NAMEDB_ORIG.bak fi echo " Link '$NAMEDB_ORIG' to '$NAMEDB_ONLINE' for online usage" # Create new or change link ln -f -s $NAMEDB_ONLINE $NAMEDB_ORIG # Reload named echo " Reload named." kill -HUP $NAMEDPID fi ;; offline) # Change softlink to a resolv.conf, # which has offline related nameserver entries if [ "$RESOLV_SWITCH" = "yes" ]; then # Test if new file exists if [ ! -f $RESOLV_OFFLINE ]; then echo " File '$RESOLV_OFFLINE' doesn't exist!" exit 1 fi # Make backup of the existing file, if not a link if [ -f $RESOLV_ORIG -a ! -L $NAMEDB_ORIG ]; then mv -bV t $RESOLV_ORIG $RESOLV_ORIG.bak fi echo " Link '$RESOLV_ORIG' to '$RESOLV_OFFLINE' for offline usage." # Create new or change link ln -f -s $RESOLV_OFFLINE $RESOLV_ORIG fi # Change softlink to a host.conf, # which has offline related host entries if [ "$HOST_SWITCH" = "yes" ]; then # Test if new file exists if [ ! -f $HOST_OFFLINE ]; then echo " File '$HOST_OFFLINE' doesn't exist!" exit 1 fi # Make backup of the existing file, if not a link if [ -f $HOST_ORIG -a ! -L $HOST_ORIG ]; then mv -bV t $HOST_ORIG $HOST_ORIG.bak fi echo " Link '$HOST_ORIG' to '$HOST_OFFLINE' for offline usage." # Create new or change link ln -f -s $HOST_OFFLINE $HOST_ORIG fi # Change softlink to a nameserver bootfile, # which has offline related entries and reload named if [ "$NAMEDB_SWITCH" = "yes" -a ! "$NAMEDMAJORVERSION" = "" ]; then # Test if new file exists if [ ! -f $NAMEDB_OFFLINE ]; then echo " File '$NAMEDB_OFFLINE' doesn't exist!" exit 1 fi # Make backup of the existing file, if not a link if [ -f $NAMEDB_ORIG -a ! -L $NAMEDB_ORIG ]; then mv -bV t $NAMEDB_ORIG $NAMEDB_ORIG.bak fi echo " Link '$NAMEDB_ORIG' to '$NAMEDB_OFFLINE' for online usage" # Create new or change link ln -f -s $NAMEDB_OFFLINE $NAMEDB_ORIG # Reload named echo " Reload BIND." kill -HUP $NAMEDPID fi ;; *) echo "Syntax: switch_gethostbyname {online|offline}" exit 1 ;; esac exit 0