#! /bin/ksh
#
# Localstuff - local commands to be run after software installation.
#
# Version: 1995/05/16.
#
# Usage: Localstuff             - create any local files/links.
#	 Localstuff clean	- remove and recreate all local files/links.
#
host=`hostname`
clean=$1
#
umask 22
#
# Set master news node.
#
masternews=alchemy
#
if [ "$clean" = "clean" ]; then
   echo "Removing old files/links/directories, and relinking."
   echo ""
fi
#
# Create extra /dev files only if they don't exist:
#	/dev/wn1a	(only on //plumbum)
#	/dev/rwn1a	(only on //plumbum)
#	/dev/pty[pqrs]*	(only on //plumbum)
#	/dev/tty[pqrs]*	(only on //plumbum)
# Link /dev/rmt8 and /dev/rmt12 to /dev/ws_rmt8 and /dev/ws_rmt12
# respectively (on //plumbum only).
#
if [ $host = plumbum ]; then
   if [ -f /dev/wn1a ]; then
      echo "/dev/wn1a already exists - do nothing."
   else
      /etc/mknod /dev/wn1a b 0 17
      chmod 666 /dev/wn1a
      echo "/dev/wn1a created - see /etc/rc for the mount command."
   fi
   if [ -f /dev/rwn1a ]; then
      echo "/dev/rwn1a already exists - do nothing."
   else
      /etc/mknod /dev/rwn1a c 0 17
      chmod 666 /dev/rwn1a
      echo "/dev/rwn1a created."
   fi
   if [ -f /dev/ptyp0 ]; then
      echo "Some pty's already exist - do nothing."
   else
      /etc/crpty 32
      echo "/dev/pty[pqrs]* created."
   fi
   if [ "$clean" = "clean" ]; then
      rm -f /dev/rmt8
      echo "/dev/rmt8 removed."
      rm -f /dev/rmt12
      echo "/dev/rmt12 removed."
   fi
   test -L /dev/rmt8
   if [ "$?" = 0 ]; then
      echo "/dev/rmt8 is already a link - do nothing."
   else
      ln -s ws_rmt8 /dev/rmt8
      echo "/dev/rmt8 linked to /dev/ws_rmt8."
   fi
   test -L /dev/rmt12
   if [ "$?" = 0 ]; then
      echo "/dev/rmt12 is already a link - do nothing."
   else
      ln -s ws_rmt12 /dev/rmt12
      echo "/dev/rmt12 linked to /dev/ws_rmt12."
   fi
fi
#
# Create NFS mount points (if they don't exist).
# Create reference directories if they don't exist; note that these
# directories will contain links to the NFS mount point directories.
# Watch out for /nfs which is installed as a link to // on new nodes.
#
if [ "$host" = "aqua" ]; then
   donfsmountdirs=no
else
   donfsmountdirs=yes
fi
#
f1=/nfs
rm -f /nfs
if [ -d $f1 ]; then
   echo "$f1 already exists - do nothing."
else
   mkdir $f1
   echo "$f1 created."
fi
#
for nfshost in alchemy argentum gatto nachas solaia taurasi tikva yaffa
do
   d1=/nfs/$nfshost
   d2=/$nfshost
   if [ "$clean" = "clean" ]; then
      if [ "$donfsmountdirs" = "yes" ]; then
	 rmdir $d1
	 echo "$d1 removed."
      fi
      rm -f $d2
      echo "$d2 removed."
   fi
   if [ "$donfsmountdirs" = "yes" ]; then
      if [ -d $d1 ]; then
         echo "$d1 already exists - do nothing."
      else
         mkdir $d1
         echo "$d1 created"
      fi
   else
      echo "Skip creation of $d1 on $host - do nothing."
   fi
   test -L $d2
   if [ "$?" = 0 ]; then
      echo "$d2 already is a link - do nothing."
   else
      rm -f $d2
      echo "$d2 removed."
      ln -s $d1 $d2
      echo "$d2 linked to $d1."
   fi
done
#
# Create administrative files only if they don't exist:
#	/usr/adm/imagen_acct/imagen (on plumbum only).
#	/usr/spool/lpd/imagen/log
#	/usr/adm/wtmp
#
#if [ -f /usr/adm/imagen_acct/imagen ]; then
#   echo "/usr/adm/imagen_acct/imagen already exists - do nothing."
#else
#   if [ "$host" = "plumbum" ]; then
#      if [ ! -d /usr/adm/imagen_acct ]; then
#         mkdir /usr/adm/imagen_acct
#         chmod 755 /usr/adm/imagen_acct
#         echo "/usr/adm/imagen_acct directory created."
#      fi
#      touch /usr/adm/imagen_acct/imagen
#      chmod 664 /usr/adm/imagen_acct/imagen
#      chown -R daemon.daemon /usr/adm/imagen_acct
#      echo "/usr/adm/imagen_acct/imagen created."
#   else
#      echo "/usr/adm/imagen_acct/imagen skipped (only needed on plumbum)."
#   fi
#fi
#
if [ -f /usr/spool/lpd/imagen/log ]; then
   echo "/usr/spool/lpd/imagen/log already exists - do nothing."
else
   if [ ! -d /usr/spool/lpd/imagen ]; then
      mkdir /usr/spool/lpd/imagen
      chmod 755 /usr/spool/lpd/imagen
      echo "/usr/spool/lpd/imagen directory created."
   fi
   touch /usr/spool/lpd/imagen/log
   chmod 664 /usr/spool/lpd/imagen/log
   chown -R daemon.daemon /usr/spool/lpd/imagen
   echo "/usr/spool/lpd/imagen/log created."
fi
#
if [ -f /usr/adm/wtmp ]; then
   echo "/usr/adm/wtmp already exists - do nothing."
else
   touch /usr/adm/wtmp
   chmod 666 /usr/adm/wtmp
   echo "/usr/adm/wtmp created."
fi
#
# Make links for man pages.
# Link /usr/man/catl to /usr/local/man/catl on //plumbum, //todah
# and //flatland.
# Link the man pages on //aurum to //flatland/bsd4.3/usr/man and
# //flatland/bsd4.3/usr/apollo/man respectively.
# Make links in /usr/local/man/catl to /usr/local/doc/*.out on //plumbum,
# //todah and //flatland.
#
if [ $host = plumbum -o $host = todah -o $host = flatland ]; then
   if [ "$clean" = "clean" ]; then
      rm -f /bsd4.3/usr/man/catl
      echo "/bsd4.3/usr/man/catl removed."
   fi
   if [ -d /bsd4.3/usr/man/catl ]; then
      echo "/bsd4.3/usr/man/catl already exists - do nothing."
   else
      ln -s ../../../usr/local/man/catl /bsd4.3/usr/man/catl
      echo "/bsd4.3/usr/man/catl linked to /usr/local/man/catl."
   fi
   cwd=`pwd`
   cd /usr/local/doc
   for i in *.out
   do
      ibase=`basename $i .out`
      if [ "$clean" = "clean" ]; then
         rm -f /usr/local/man/catl/$ibase.l
         echo "/usr/local/man/catl/$ibase.l removed."
      fi
      if [ -f /bsd4.3/usr/man/catl/$ibase.l ]; then
         echo "/bsd4.3/usr/man/catl/$ibase.l already exists - do nothing."
      else
         ln -s /usr/local/doc/$i /usr/local/man/catl/$ibase.l
         echo "/usr/local/man/catl/$ibase.l linked to /usr/local/doc/$i."
      fi
   done
   cd $cwd
fi
if [ $host = aurum ]; then
   if [ "$clean" = "clean" ]; then
      rm -f /bsd4.3/usr/man
      echo "/bsd4.3/usr/man removed."
      rm -f /usr/X11/man
      echo "/usr/X11/man removed."
      rm -f /usr/apollo/man
      echo "/usr/apollo/man removed."
   fi
   if [ -d /bsd4.3/usr/man ]; then
      echo "/bsd4.3/usr/man already exists - do nothing."
   else
      ln -s //flatland/bsd4.3/usr/man /bsd4.3/usr/man
      echo "/bsd4.3/usr/man linked to //flatland/bsd4.3/usr/man."
   fi
   if [ -d /usr/X11/man ]; then
      echo "/usr/X11/man already exists - do nothing."
   else
      ln -s //flatland/usr/X11/man /usr/X11/man
      echo "/usr/X11/man linked to //flatland/usr/X11/man."
   fi
   if [ -d /usr/apollo/man ]; then
      echo "/usr/apollo/man already exists - do nothing."
   else
      ln -s //flatland/usr/apollo/man /usr/apollo/man
      echo "/usr/apollo/man linked to //flatland/usr/apollo/man."
   fi
fi
if [ $host = aqua ]; then
   if [ "$clean" = "clean" ]; then
      rm -f /bsd4.3/usr/man
      echo "/bsd4.3/usr/man removed."
      rm -f /usr/X11/man
      echo "/usr/X11/man removed."
      rm -f /usr/apollo/man
      echo "/usr/apollo/man removed."
   fi
fi
#
# Make links for /usr/msgs to /alchemy/usr/msgs.
# Make sure that /usr/msgs is a link to ../$(SYSTYPE)/usr/msgs.
#
if [ "$clean" = "clean" ]; then
   rm -f /usr/msgs
   echo "/usr/msgs removed."
   rm -f /bsd4.3/usr/msgs
   echo "/bsd4.3/usr/msgs removed."
fi
if [ -d /bsd4.3/usr/msgs ]; then
   echo "/bsd4.3/usr/msgs already exists - do nothing."
else
   ln -s /alchemy/usr/msgs /bsd4.3/usr/msgs
   echo "/bsd4.3/usr/msgs linked to /alchemy/usr/msgs."
fi
if [ -d /usr/msgs ]; then
      echo "/usr/msgs already exists - do nothing."
else
   ln -s '../$(SYSTYPE)/usr/msgs' /usr/msgs
   echo '/usr/msgs linked to ../$(SYSTYPE)/usr/msgs.'
fi
#
# Make links between Apollo-supplied /usr/... and /usr/local/...
# on all nodes.
#
if [ "$clean" = "clean" ]; then
   rm -f /usr/lib/tmac/tmac.utchemdoc
   echo "/usr/lib/tmac/tmac.utchemdoc removed."
   rm -f /usr/lib/tmac/tmac.*vcat
   echo "/usr/lib/tmac/tmac.*vcat removed."
fi
if [ -f /usr/lib/tmac/tmac.utchemdoc ]; then
   echo "/usr/lib/tmac/tmac.utchemdoc already exists - do nothing."
else
   ln -s /usr/local/lib/tmac/tmac.utchemdoc /usr/lib/tmac/tmac.utchemdoc
   echo "/usr/lib/tmac/tmac.utchemdoc (re)linked."
fi
if [ -f /usr/lib/tmac/tmac.psh_vcat ]; then
   echo "/usr/lib/tmac/tmac.psh_vcat already exists - do nothing."
else
   ln -s /usr/local/lib/tmac/tmac.psh_vcat /usr/lib/tmac/tmac.psh_vcat
   echo "/usr/lib/tmac/tmac.psh_vcat (re)linked."
fi
if [ -f /usr/lib/tmac/tmac.pst_vcat ]; then
   echo "/usr/lib/tmac/tmac.pst_vcat already exists - do nothing."
else
   ln -s /usr/local/lib/tmac/tmac.pst_vcat /usr/lib/tmac/tmac.pst_vcat
   echo "/usr/lib/tmac/tmac.pst_vcat (re)linked."
fi
if [ -f /usr/lib/tmac/tmac.vcat ]; then
   echo "/usr/lib/tmac/tmac.vcat already exists - do nothing."
else
   ln -s /usr/local/lib/tmac/tmac.vcat /usr/lib/tmac/tmac.vcat
   echo "/usr/lib/tmac/tmac.vcat (re)linked."
fi
#
# Make links between /tftp/... and /usr/local/tftpd/tftp/....
# on //plumbum and //aurum only.
#
if [ $host = plumbum -o $host = aurum ]; then
   if [ "$clean" = "clean" ]; then
      rm -f /tftp/cisco.confg
      echo "/tftp/cisco.confg removed."
      rm -f /tftp/ventus.confg
      echo "/tftp/ventus.confg removed."
   fi
   if [ -f /tftp/cisco.confg ]; then
      echo "/tftp/cisco.confg already exists - do nothing."
   else
      ln -s /usr/local/tftpd/tftp/cisco.confg /tftp/cisco.confg
      echo "/tftp/cisco.confg linked to /usr/local/tftpd/tftp/cisco.confg"
   fi
   if [ -f /tftp/ventus.confg ]; then
      echo "/tftp/ventus.confg already exists - do nothing."
   else
      ln -s /usr/local/tftpd/tftp/ventus.confg /tftp/ventus.confg
      echo "/tftp/ventus.confg linked to /usr/local/tftpd/tftp/ventus.confg"
   fi
fi
#
# Make link between /usr/spool/mail and /alchemy/usr/mail on all nodes.
#
if [ "$clean" = "clean" ]; then
   rm -f /usr/spool/mail
   echo "/usr/spool/mail removed."
fi
if [ -d /usr/spool/mail ]; then
   echo "/usr/spool/mail already exists - do nothing."
else
   ln -s /alchemy/usr/mail /usr/spool/mail
   echo "/usr/spool/mail linked to /alchemy/usr/mail"
fi
#
# Make links for /usr/X11/lib to /usr/local on all systems.
#
f1=/usr/local/Master.uwmrc
f2=/usr/X11/lib/uwm/system.uwmrc
if [ "$clean" = "clean" ]; then
   rm -f $f2
   echo "$f2 removed."
fi
test -L $f2
if [ "$?" = 0 ]; then
   echo "$f2 already is a link - do nothing."
else
   rm -f $f2
   echo "$f2 removed."
   ln -s $f1 $f2
   echo "$f2 linked to $f1."
fi
#
# Make links for /usr/include/X11/* to
# /alchemy/usr/local/include/X11R4/X11/* on all systems.
#
if [ -d /alchemy/usr/local/include/X11R4/X11 ]; then
   f1=/alchemy/usr/local/include/X11R4/X11
   cwd=`pwd`
   cd $f1
   f2=/usr/include/X11
   if [ ! -d "$f2" ]; then
      echo "*** Directory $f2 not found. ***"
   else
      for i in *
      do
         if [ -f $f2/$i -o -d $f2/$i -o -h $f2/$i ]; then
            echo "$f2/$i already exists - do nothing."
         else
            ln -s $f1/$i $f2/$i
            echo "$f2/$i linked to $f1/$i."
         fi
      done
   fi
   cd $cwd
fi
#
# Make links for /usr/X11/include/bitmaps/*.xbm to ~system/xbm on all systems.
#
if [ -d ~system/xbm ]; then
   f1=~system/xbm
   f2=/usr/X11/include/bitmaps
   cwd=`pwd`
   cd $f1
   for i in *.xbm
   do
      if [ "$clean" = "clean" ]; then
         rm -f $f2/$i
         echo "$f2/$i removed."
      fi
      if [ -f $f2/$i ]; then
         echo "$f2/$i already exists - do nothing."
      else
         ln -s $f1/$i $f2/$i
         echo "$f2/$i linked to $f1/$i."
      fi
   done
   cd $cwd
fi
#
# Make /usr/spool/news directory structure on all systems.
# On all nodes it is a link to /$masternews/news.
#
f1=/$masternews/news
f2=/usr/spool/news
if [ "$clean" = "clean" ]; then
   if [ -f $f2 ]; then
      rm -f $f2
      echo "File $f2 removed."
   else
      rmdir $f2
      echo "Directory $f2 removed."
   fi
fi
test -L $f2
if [ "$?" = 0 ]; then
   echo "$f2 already is a link - do nothing."
else
   if [ -f $f2 ]; then
      rm -f $f2
      echo "File $f2 removed."
   else
      rmdir $f2
      echo "Directory $f2 removed."
   fi
   ln -s $f1 $f2
   echo "$f2 linked to $f1."
fi
#
# Make link between /g88 and //plumbum/u0/mgauss/g88 on //plumbum only.
# Create the Gaussian88 scratch directory (/tmp/g88scratch)
# if it doesn't already exist.
#
if [ $host = plumbum ]; then
   if [ "$clean" = "clean" ]; then
      rm -f /g88
      echo "/g88 removed."
      rm -r /tmp/g88scratch
      echo "/tmp/g88scratch removed."
   fi
   if [ -d /g88 ]; then
      echo "/g88 already exists - do nothing."
   else
      ln -s //plumbum/u0/mgauss/g88 /g88
      echo "/g88 linked to //plumbum/u0/mgauss/g88."
   fi
   if [ -d /tmp/g88scratch ]; then
      echo "/tmp/g88scratch already exists - do nothing."
   else
      mkdir /tmp/g88scratch
      chmod 777 /tmp/g88scratch
      chacl -df ug=PU,z=PI,o=U /tmp/g88scratch
      echo "/tmp/g88scratch re-created."
   fi
fi
#
# Make link between /usr/games/tetris_scores and /usr/local/lib/tetris_scores,
# except on plumbum.
#
if [ $host != plumbum ]; then
   if [ "$clean" = "clean" ]; then
      rm -f /usr/games/tetris_scores
      echo "/usr/games/tetris_scores removed."
   fi
   if [ -f /usr/games/tetris_scores ]; then
      echo "/usr/games/tetris_scores already exists - do nothing."
   else
      ln -s /usr/local/lib/tetris_scores /usr/games/tetris_scores
      echo "/usr/games/tetris_scores linked to /usr/local/lib/tetris_scores."
   fi
fi
#
# Make /etc/tftpd setuid user.none.
#
if [ -f /etc/tftpd ]; then
   echo "Making /etc/tftpd setuid user.none."
   /etc/chown user.none /etc/tftpd
   /bin/chmod 4755 /etc/tftpd
fi
#
# Replace /bin/sh with /bin/ksh.
#
diff /bin/sh /bin/ksh >/dev/null 2>&1
if [ "$?" = "0" ]; then
   echo "/bin/sh and /bin/ksh already identical - do nothing."
else
   echo "/bin/sh and /bin/ksh are different - replacing /bin/sh."
   rm -f /bin/sh
   cp -p /bin/ksh /bin/sh
fi
#
# Disable the following commands:
# /bin/passwd (use /usr/local/binspecial/passwd instead),
# /usr/bin/yppasswd (use /usr/local/binspecial/passwd instead).
#
for f in /bin/passwd /usr/bin/yppasswd
do
   if [ -x $f ]; then
      chmod 000 $f
      echo "$f disabled."
   else
      echo "$f already disabled - do nothing."
   fi
done
#
#for f in 
#do
#   if [ -f $f ]; then
#      mv $f $f.bad
#      echo "$f disabled."
#   else
#      echo "$f already disabled - do nothing."
#   fi
#done
#
# Make links for /usr/dict/words.{dir,pag} to /alchemy/usr/local/dict.
#
if [ "$clean" = "clean" ]; then
   rm -f /usr/dict/words.dir /usr/dict/words.pag
   echo "/usr/dict/words.{dir,pag} removed."
fi
if [ -f /usr/dict/words.dir ]; then
   echo "/usr/dict/words.dir already exists - do nothing."
else
   ln -s /alchemy/usr/local/dict/words.dir /usr/dict/words.dir
   echo "/usr/dict/words.dir linked to /alchemy/usr/local/dict/words.dir."
fi
if [ -f /usr/dict/words.pag ]; then
   echo "/usr/dict/words.pag already exists - do nothing."
else
   ln -s /alchemy/usr/local/dict/words.pag /usr/dict/words.pag
   echo "/usr/dict/words.pag linked to /alchemy/usr/local/dict/words.pag."
fi
#
exit 0
