#!/bin/bash #always have the right System.map (in /usr/src/linux), ipvsadm... #no matter which kernel version you're running #Joseph Mack (C) 2001 released under GPL, jmack@wm7d.net, #To use: #for files/directories which are kernel version specific. # #eg you'll get error messages about System.map being the wrong version unless #you have /usr/src/linux linked to the same version of linux as you booted from. #eg in /sbin: ipvsadm-2.4.1, ipvsadm-2.2.18 which is called as /sbin/ipvsadm # #in main you send a list of directories/files like /usr/src/linux/, /sbin/ipvsadm #for each item in this list, this program will #a. delete /usr/src/linux if linux is a link, otherwise do nothing if linux is a file #b. look for linux-x.x.x where x.x.x is the kernel version #c. ln -s linux-x.x.x linux, else issue notice if there is no linux-x.x.x # #--------------------- ip_vs(){ #IPVS_VERSION is assigned the version number of IPVS currently loaded if [ "$LINUX_KERNEL_SERIES" = "2.2" ] then IPVS_VERSION=`grep "IP Virtual Server version" /proc/net/ip_masq/vs | awk '{print \$5}'` echo $IPVS_VERSION elif [ "$LINUX_KERNEL_SERIES" = "2.4" ] then IPVS_VERSION=`grep "IP Virtual Server version" /proc/net/ip_vs | awk '{print \$5}'` echo $IPVS_VERSION elif [ "$LINUX_KERNEL_SERIES" = "2.6" ] then IPVS_VERSION=`grep "IP Virtual Server version" /proc/net/ip_vs | awk '{print \$5}'` echo $IPVS_VERSION else echo "Error: kernel $UNAME_R not from 2.2 or 2.4 series" exit -1 fi } make_link(){ BASENAME=`/bin/basename $1` #echo "BASENAME $BASENAME" cd `/bin/dirname $1` #if $BASENAME a link or doesn't exist if [ -L $BASENAME -o ! \( -e $BASENAME \) ] then #only do something if we have a target if [ -d $BASENAME-${UNAME_R}-${IPVS_VERSION} -o -f $BASENAME-${UNAME_R}-${IPVS_VERSION} ] then if [ -L $BASENAME ] #if the filename is a link, delete it then /bin/rm $BASENAME fi #there is no $BASENAME now. /bin/ln -s $BASENAME-${UNAME_R}-${IPVS_VERSION} $BASENAME elif [ -d $BASENAME-${IPVS_VERSION}-${UNAME_R} -o -f $BASENAME-${IPVS_VERSION}-${UNAME_R} ] then if [ -L $BASENAME ] #if the filename is a link, delete it then /bin/rm $BASENAME fi #there is no $BASENAME now. /bin/ln -s $BASENAME-${IPVS_VERSION}-${UNAME_R} $BASENAME elif [ -d $BASENAME-${IPVS_VERSION} -o -f $BASENAME-${IPVS_VERSION} ] then if [ -L $BASENAME ] #if the filename is a link, delete it then /bin/rm $BASENAME fi #there is no $BASENAME now. /bin/ln -s $BASENAME-${IPVS_VERSION} $BASENAME elif [ -d $BASENAME-${UNAME_R} -o -f $BASENAME-${UNAME_R} ] then if [ -L $BASENAME ] #if the filename is a link, delete it then /bin/rm $BASENAME fi #there is no $BASENAME now. /bin/ln -s $BASENAME-${UNAME_R} $BASENAME else echo "no $BASENAME-${UNAME_R} or $BASENAME-${IPVS_VERSION} to link to" fi else echo "cannot delete $BASENAME, doesn't exist or is a regular file" fi cd - } #----------------- #main: echo -n "rc.system_map " UNAME_R=`/bin/uname -r` LINUX_KERNEL_SERIES=${UNAME_R%.*} #when bootup, the modules (ip_vs.o) won't be loaded #and hence there will be no /proc/net/ip_vs. #Hence you can't tell that ip_vs has been compiled into the kernel. #You could force the ip_vs.o module to load by running `ipvsadm`. #However at this stage, #you don't know which version of ipvsadm to run. #Punt by just loading the module modprobe ip_vs ip_vs if [ $? != "0" ] then echo "Error: unable to determine IPVS version" exit -1 fi make_link /usr/src/linux make_link /sbin/ipvsadm make_link /sbin/ipvsadm-save make_link /sbin/ipvsadm-restore make_link /usr/src/ipvs make_link /boot/System.map make_link /boot/bzImage #make_link /bin/foo #a test, foo-x.x.x doesn't exist #-----------------