#!/bin/sh # /serve/sgi/sbin/switchconf - switch beteeen multiple sets of config files # author Neil Franklin, last modification 2000.02.29 # to install: # create /home//system # copy scripts and share into here # create /home//homes1 # in homes1 links to system # presently installed on: truffaut # these files have variable configs FILES="/etc/hosts /etc/config/ifconfig-1.options /etc/config/static-route.options /etc/config/yp /homes1 /serve" # on installing convert existing state tot his config INSTOLDCONFIG=standard # new configs should resemble this config BASEADDCONFIG=$INSTOLDCONFIG NAME=`echo $0 | tr "/" "\n" | tail -1` # give users who do not know the game some help if [ $# -gt 0 ] ; then if [ $1 = -help ] ; then echo "${NAME}: usage:" echo " install on a computer: $NAME -install" echo " uninstall from a computer: $NAME -uninstall" echo " add annother config: $NAME -add " echo " delete an existing config: $NAME -delete " echo " tell what files are switched: $NAME -files" echo " switch to a config: $NAME (or just simply )" echo "available s on this computer are:" ls -al /usr/local/sbin | grep " -> .*$NAME" | awk '{ print " " $9 }' exit 0 fi fi # special modes, for administering configs if [ $# -gt 0 ] ; then case $1 in ( '-install' ) if [ $# -gt 1 ] ; then echo "${NAME}: -install: too many parameters, try $NAME -help" exit 1 fi # if there exists a INSTOLDCONFIG config for the first file, do not (re-)install if [ -f `echo $FILES | cut -f 1 -d ' '`.$INSTOLDCONFIG ] ; then echo ${NAME}: -install: we seem to have already installed here, aborting exit 1 fi echo ${NAME}: setting up pseudo-server on /home/`hostname` mkdir /home/`hostname`/sgi /home/`hostname`/sgi/sbin cp -p /serve/sgi/sbin/switchconf /home/`hostname`/sgi/sbin mkdir /home/`hostname`/system /home/`hostname`/homes1 cp -R /homes1/system/scripts /home/`hostname`/system cp -R /homes1/system/share /home/`hostname`/system ln -s /home/`hostname`/system /home/`hostname`/homes1 echo ${NAME}: setting up first config # save existing config as the normal one, with name from INSTOLDCONFIG for FILE in $FILES ; do mv $FILE ${FILE}.$INSTOLDCONFIG ln -s ${FILE}.$INSTOLDCONFIG $FILE done ln -s $0 /usr/local/sbin/$INSTOLDCONFIG exit 0 ;; ( '-uninstall' ) if [ $# -gt 1 ] ; then echo "${NAME}: too many parameters, try $NAME -help" exit 1 fi # if there does not exist a INSTOLDCONFIG config for the first file, do not (re-)uninstall if [ ! -f `echo $FILES | cut -f 1 -d ' '`.$INSTOLDCONFIG ] ; then echo ${NAME}: -uninstall: we seem to not be installed here, aborting exit 1 fi rm -f /usr/local/sbin/$INSTOLDCONFIG # restoring INSTOLDCONFIG config als only state echo ${NAME}: unsetting first config for FILE in $FILES ; do rm $FILE mv ${FILE}.$INSTOLDCONFIG $FILE done echo ${NAME}: deleting pseudo-server on /home/`hostname` \rm -rf /home/`hostname`/system /home/`hostname`/homes1 /home/`hostname`/sgi exit 0 ;; ( '-add' ) if [ $# = 2 ] ; then ADDCONFIG=$2 for FILE in $FILES ; do # symlinks can not be copied verbatim, dammit if [ -h ${FILE}.$BASEADDCONFIG ] ; then ln -s `ls -l ${FILE}.$BASEADDCONFIG | awk '{ print " " $11 }'` ${FILE}.$ADDCONFIG else cp -p ${FILE}.$BASEADDCONFIG ${FILE}.$ADDCONFIG fi done ln -s $0 /usr/local/sbin/$ADDCONFIG echo ${NAME}: added config: $ADDCONFIG exit 0 else echo ${NAME}: -add requres a configname, try $NAME -help exit 1 fi ;; ( '-delete' ) if [ $# = 2 ] ; then DELCONFIG=$2 for FILE in $FILES ; do rm ${FILE}.$DELCONFIG done rm -f /usr/local/sbin/$DELCONFIG echo ${NAME}: deleted config: $DELCONFIG exit 0 else echo ${NAME}: -delete requres a configname, try $NAME -help exit 1 fi ;; ( '-files' ) for FILE in $FILES ; do echo $FILE done exit 0 ;; ( '-'* ) echo ${NAME}: unknown command: $*, try $NAME -help exit 1 ;; esac fi # determine what config the user wants if [ $# -gt 1 ] ; then echo "${NAME}: too many parameters, try $NAME -help" exit 1 elif [ $# = 1 ] ; then CONFIG=$1 else # program can be linked to name of desired config CONFIG=$NAME fi # if there is not a config for the ffirst file, invalid config name, user error if [ ! -f `echo $FILES | cut -f 1 -d ' '`.$CONFIG ] ; then echo "${NAME}: unknown , available s on this computer are": ls -al /usr/local/sbin | grep " -> .*$NAME" | awk '{ print " " $9 }' exit >1 fi # do the actual job for FILE in $FILES ; do rm -rf $FILE ln -s ${FILE}.$CONFIG $FILE done echo ${NAME}: switched to config: $CONFIG