#!/bin/sh

# Upgrade a Linux system by installing on a new partition and
# then copying all relevant stuff from the old partition :
# Kees Lemmens, April 2001: adapted for slw 7.2
# May 2001 : version 0.3
# ===========================================================

OLDROOT=/Old
CONFIRM="n"
DEBUG="" # use "echo " check if everything works without actual changes

prompt()
{
  if [ $CONFIRM = "n" ]; then
    /bin/echo "$1 "
    return 1
  else
    /bin/echo -n "$1 ? (y/n) "
    read ANSWER
    test $ANSWER = "y" && return 1 || return 0
  fi
}

cp_oldfile()
{
  prompt "Copy $1 to $2 " && return
  # only move oldfile to .org if there is not already another one :
  test -r $2/$1 && test -r $2/$1.org || $DEBUG mv $2/$1 $2/$1.org
  $DEBUG cp $1 $2
}

modify()
{
  diff $1 $1.new ||
  {
    prompt "Replace $1 with $1.new " && return
    $DEBUG cp $1 $1.org
    $DEBUG mv $1.new $1
  } && 
  {
    $DEBUG rm -f $1.new
  }
}
modify_exec()
{ 
  modify $1
  $DEBUG chmod 755 $1
}

misc_stuff()
{
  cd /etc; test -d mail || $DEBUG ln -s . mail 
  cd /etc; $DEBUG ln -sf group logingroup 
  
  $DEBUG touch /var/adm/lpd-errs # Our TA /etc/printcaps specify this  
}

#  check carefully if all important modules are enabled in rc.modules
#  (ethernetcard, sound, scsi, filesystems, mouse !)
#  check if the ethernetaddress in /etc/rc.d/rc.inet1 is correct

edit_fstab()
{
  CDDEV=hdc
  
  NAME=/etc/fstab
  
  cp $NAME $NAME.new
  grep -q ' /fd0' $NAME || \
    echo "/dev/fd0 /fd0   vfat    user,noauto,exec,nosuid    0 0" >>$NAME.new
  grep -q ' /cdrom' $NAME || \
    echo "/dev/$CDDEV /cdrom iso9660 user,noauto,exec,nosuid,ro 0 0" >>$NAME.new
  test -d /fd0 || $DEBUG mkdir /fd0
  
  modify $NAME
}

edit_rcM()
{
  prompt "Disable sendmail receive (-bd) " && return
  NAME=/etc/rc.d/rc.M
  sed -e 's/sendmail -bd -q15m/sendmail -q60m/' < $NAME > $NAME.new
  
  modify_exec $NAME
}

edit_inetd_conf()
{
  NAME=/etc/inetd.conf
  
  sed -e 's/rlogind$/rlogind -l -h/' \
      -e 's/rshd -L$/rshd -L -l -h/' \
      -e 's/^pop3/#pop3/'            \
      -e 's/^imap2/#imap2/'          \
    < $NAME > $NAME.new
  
  modify $NAME
  killall -HUP inetd
}

set_devaccess()
{
  $DEBUG chmod 666 /dev/cdrom /dev/fd0 /dev/modem /dev/dsp
  
}

set_100dpi_font()
{ 
  test -d /usr/lib/X11/fonts/100dpi && return
  prompt "No 100dpi fontdir : create empty one " && return
  $DEBUG mkdir /usr/lib/X11/fonts/100dpi
  echo "0" >/usr/lib/X11/fonts/100dpi/fonts.dir
}

gzip_howtos()
{
  prompt "Compress HOWTOs " && return
  echo "Starting gzip compression in the background ...."
  $DEBUG nice gzip -9r /usr/doc/Linux-*HOWTOs &
}

rm_catdirs()
{
  prompt "Remove catdirs " && return
  $DEBUG rm -rf /var/man/*
}

main()
{
  installpkg esound.tgz

  echo "linux1 root" > /root/.rhosts
 
  misc_stuff
  
  edit_fstab
  edit_rcM
  edit_inetd_conf

  set_devaccess
  set_100dpi_font
   
  gzip_howtos
  rm_catdirs

}

main


