#!/bin/sh
# fsadapt  -- adapt a Debian 2.0 r2 installation for FS
# $Id: fsadapt,v 4.1 2001/07/12 13:03:22 amn Exp $

# What          When                  Who
# $Log: fsadapt,v $
# Revision 4.1  2001/07/12 13:03:22  amn
# The first attempt for FS Linux 4 fsadapt.
#
# Revision 3.10  2000/06/22 07:29:56  amn
# Just changing the revision number on top of screen.
#
# Revision 3.9  2000/06/20 06:37:00  amn
# lilobkp MBR target must be sdb, not sda.
#
# Revision 3.8  2000/06/15 12:31:13  amn
# For lilobkp.conf auto-sed-edit double backslashes were needed.
#
# Revision 3.7  2000/06/09 13:52:13  amn
# Added replacing XF86_Mach64, [X] for liloconf, tar backup LILO conf.
#
# Revision 3.6  1998/11/13 11:23:23  amn
# Corrected gpib patch contents, added after-login govt warnings.
#
# Revision 3.5  1998/11/12 09:15:26  amn
# Updated Linux-gpib from 2.03 to 2.04 ("SLOW_DOWN_IO()").
#
# Revision 3.4  1998/11/11 12:33:07  amn
# Added command line parameters and numerous corrections.
#
# Revision 3.3  1998/10/30 20:00:31  amn
# X-basckspace-delete, net services off, smailconfig, and many others.
#
# Revision 3.2  1998/10/29 10:32:32  amn
# Changed magicfilter file location, X-sed, and mke2fs-/usr2-detection.
#
# Revision 3.1  1998/10/27 14:45:11  amn
# For Debian 2.0 r2: changed all 'patch' usages et al.
#
# Revision 2.5  1998/02/10 15:02:27  amn
# Updated version number in backdrop, added /dev/tape.
#
# Revision 2.4  1998/02/09 15:04:53  amn
# Updating backdrop version number, syncing RCS version number.
#
# Revision 2.2  1998/02/05 13:30:42  amn
# fort77, ibProto.h, Vikom Pro, blank passwd of user1, config kernel 2.0.30
# only, no networking clears netconfig-generated /etc/resolv.conf, updated
# backdrop version number.
#
# Revision 2.1  1997/10/22 18:01:50  root
# Testing for existence of /etc/printcap before moving it to .orig.
#
# Revision 2.0  1997/10/22 12:56:53  root
# Completely revised for Debian 1.3.1.r3.
#
# Revision 1.14  1996/03/05  12:14:28  root
# For fsadapt-1.12, provide an XF86Config alternative for 21" Nokia.
#
# Revision 1.13  1995/12/01  20:27:37  root
# For fsadapt-1.11, enable copying updatred X servers from fsadapt directory.
#
# Revision 1.12  1995/12/01  19:59:48  root
# As released on 5-Sep-95.
#
# Revision 1.11  1995/09/05  12:44:05  root
# Final Setp 5 release changes.
#
# Revision 1.10  1995/08/29  13:51:29  root
# Name change from fsup to fsadapt.
#
# Revision 1.9  1995/08/29  10:11:43  root
# Blank password check at the beginning, /da, /db, 3c59x, corrected
# rc.serial (in phase 2 instead of 1), prepackaged root/oper/prog/powerdown.
#
# Revision 1.8  1995/08/22  16:18:52  root
# I.e., powerdown script copying, CD-ROM in fstab, passwd escape hatch etc.
#
# Revision 1.7  1995/08/04  17:32:47  root
# Oper, prog, powerdown defaults were always off.
#
# Revision 1.6  1995/08/04  14:54:19  root
# 'Click' to 'select', 'rc.serial', 'powerdown', XF86Config_S3,
# cancel from phase 1, etc.
#
# Revision 1.5  1995/08/02  16:34:00  root
# Name changed from 'update-sw230-to-fs' int 'fsadapt',
# standard /etc/gpib.conf, Linux kernel version 1.2.12 etc.
#
# Revision 1.4  1995/06/12  15:45:03  root
# Bash 1.14.4(1) is still broken for 'f77' use, returns 'Error 4' in make.
#
# Revision 1.3  1995/06/12  15:13:15  root
# Must delete a directory before copying over with 'cp -a'.
#
# Revision 1.2  1995/06/12  15:07:28  root
# Added Linux 1.2.9 support.
#
# Revision 1.1  1995/06/12  07:49:58  root
# Initial revision
#
# 1995-06-07  amn  Selecting target dir/dev, X setup.
# 1995-06-06  amn  Original version.

readonly DIALOG="dialog --backtitle FS/Debian/Linux-fsadapt-4.1"
readonly PATCHOPTS="-s -p1 --set-utc"
readonly MFLOC="/etc/magicfilter"

# Process command line arguments.
NODIALOGS=""
PHASE1=""
PHASE2=""
PHASE3=""
SHOWPHASE1=""
SHOWPHASE2=""
SHOWPHASE3=""
while [ "$1" != "" ]; do
  case $1 in
    "-n")
      NODIALOGS=1
      shift
      ;;
    "-1")
      SHOWPHASE1=1
      shift
      while [ "$1" != "" ]; do
        case $1 in
          -*)
            break;
            ;;
          *)
            PHASE1="${PHASE1} $1"
            ;;
        esac
        shift
      done
      ;;
    "-2")
      SHOWPHASE2=1
      shift
      while [ "$1" != "" ]; do
        case $1 in
          -*)
            break;
            ;;
          *)
            PHASE2="${PHASE2} $1"
            ;;
        esac
        shift
      done
      ;;
    "-3")
      SHOWPHASE3=1
      shift
      while [ "$1" != "" ]; do
        case $1 in
          -*)
            break;
            ;;
          *)
            PHASE3="${PHASE3} $1"
            ;;
        esac
        shift
      done
      ;;
    *)
      echo "fsadapt: usage: fsadapt [-n] [-1 opt1...] [-2 opt2...] [-3 opt3...]" >&2
      exit
      ;;
  esac
done

# If no dialog requested in command line, show all.
if [ ! "$SHOWPHASE1" -a ! "$SHOWPHASE2" -a ! "$SHOWPHASE3" ]; then
  SHOWPHASE1=1
  SHOWPHASE2=1
  SHOWPHASE3=1
fi

# Check for blank root password and refuse to continue unless set.
blank_root=`grep '^root::' /etc/passwd`
blank_oper=`grep '^oper::' /etc/passwd`
unset_oper=`grep '^oper:\*:' /etc/passwd`
blank_prog=`grep '^prog::' /etc/passwd`
unset_prog=`grep '^prog:\*:' /etc/passwd`
has_user1=`grep '^user1:' /etc/passwd`
if [ "$has_user1" ]; then
  user1_text=", 'user1'"
else
  user1_text=""
fi
blank_user1=`grep '^user1::' /etc/passwd`
unset_user1=`grep '^user1:\*:' /etc/passwd`
##if [ "$blank_root" -o "$blank_oper" -o "$blank_prog" -o "$blank_user1" -o "$unset_oper" -o "$unset_prog" -o "$unset_user1" ]; then
if [ "$blank_root" -o "$blank_oper" -o "$blank_prog" -o "$blank_user1" ]; then
  if [ "$NODIALOGS" ]; then
    echo "fsadapt: must set passwords for ('root', 'oper', 'prog'${user1_text}) first" >&2
    exit
  else
    ${DIALOG} --title "Check user accounts and passwords" \
      --msgbox \
"\nYou _must_ set passwords for all default user accounts\n\
('root', 'oper', 'prog'${user1_text})\n\
before continuing the update process.\n\n\
Invoke the command 'passwd' for each of them.\n" \
      17 74
    if [ $? = 255 ]; then
      : # Undocumented skip-over by pressing a certain key in dialog...
    else
      exit
    fi
  fi
fi

# Determine the absolute path to the directory name where this script resides.
SRCS=${0%fsadapt}
if [ x$SRCS = x ]; then
  SRCS="./"
fi
if [ ${SRCS#/} = $SRCS ]; then  # it doesn't start with a '/'
  SRCS=`pwd`/$SRCS
fi

# Establish default update target (a future (or current) FS root file system).
if [ x$1 = x ]; then
  NEW_ROOT=/
else
  NEW_ROOT=$1
fi

# Again, amn's special case: if updating the third ("larger root")
# partition on my 1GB SCSI disk, default the root device to that...
if [ $NEW_ROOT = /s5/ ]; then
  NEW_ROOT_DEVICE=/dev/sda5
else
  NEW_ROOT_DEVICE=/dev/sda1
fi
NEW_SWAP_DEVICE=/dev/sda2
NEW_USR2_DEVICE=/dev/sda3

# Try to get the "true and right" device names from 'mount' output
# if we are running $NEW_ROOT = /, i.e. a "living" system.
# (xxx: Doesn't support multiple swap partitions yet...)
if [ $NEW_ROOT = / ]; then
  NEW_ROOT_DEVICE="`mount | fgrep "on / " | cut -d' ' -f1`"
  if fgrep "swap" /etc/fstab >/dev/null; then
    NEW_SWAP_DEVICE="`fgrep "swap" /etc/fstab | cut -d' ' -f1`"
  fi
  # Must be a local real Ext2 file system.
  if mount | fgrep "/usr2" | fgrep "ext2" | grep '^/dev' >/dev/null; then
    NEW_USR2_DEVICE="`mount | fgrep "/usr2" | cut -d' ' -f1`"
  fi
fi

# There must be a Debian-specific '/var/lib/dpkg'
# on the new target root file system.
if [ ! -d ${NEW_ROOT}var/lib/dpkg ]; then
  if [ "$NODIALOGS" ]; then
    echo "fsadapt: target new root directory ($NEW_ROOT) not valid" >&2
    exit
  else
    ${DIALOG} --title "Target root file system problem" \
      --msgbox \
"\nThe target directory for the new root file system ($NEW_ROOT)\n\
either doesn't exist\n\
or it doesn't contain Debian 2.2 r2 installed on it.\n\
\n\
Please check the target directory (note the need for trailing '/')\n\
and possibly supply the correct directory name as the first\n\
parameter to this script ($0).\n\
\n\
Select 'OK' to exit and retry." \
      17 74
    exit
  fi
fi

# Now show the root, swap, usr2 settings and provide a way to back out.
if [ "$NODIALOGS" ]; then
  :
else
  ${DIALOG} --title "fsadapt: current root / swap / usr2 settings" \
    --yesno \
"\nWe are about to update a Debian 2.2 r2 + Linux 2.2.19\n\
installation to support running FS9.\
\n\
Target directory\n\
i.e. where the new root file system is mounted now:  $NEW_ROOT\n\
\n\
Target root file system device:    $NEW_ROOT_DEVICE\n\
Swap partition that will be used:  $NEW_SWAP_DEVICE\n\
Partition for '/usr2':             $NEW_USR2_DEVICE\n\
\n\
If these are correct, select 'Yes'.
Select 'No' to cancel this script ($0)." \
      17 74
  if [ $? != 0 ]; then
    exit
  fi
fi


# Ensure that mount points are created.
mkdir -p ${NEW_ROOT}da ${NEW_ROOT}db ${NEW_ROOT}dosa ${NEW_ROOT}cdrom


# Determine if the various kernel and conf file patches have been applied.

# Default verbosity (none).
VERBO=''
VERBOQ='--quiet'

# Debian 2.0 prefers to keep /usr/include/linux|asm in synch with glibc,
# and drivers must -I/usr/src/linux/include to get access to kernel stuff.
## Fix /usr/include/linux symlink.
## xxx: maybe later perform like fsadapt-1.14 kernel-1.2.8.patch 
##      alias mount root readonly/rtx 990/latency enabler.
##      (fgrep 990 ${NEW_ROOT}usr/src/linux/kernel/sys.c >/dev/null)
#if [ -L ${NEW_ROOT}usr/include/linux -a -L ${NEW_ROOT}usr/include/asm ]; then
#  kernelinc_def="off"
#else
#  kernelinc_def="on"
#fi

## Linux-gpib-2.04 driver for NI ATGPIB.
#if [ ! -d ${NEW_ROOT}usr/src/linux-gpib-2.04 ]; then
#  atgpib_def="on"
#else
#  atgpib_def="off"
#fi

# Add 'rtx' / 990 group into '/etc/group'.
if (grep 'rtx:.:990' ${NEW_ROOT}etc/group >/dev/null); then
  rtxgroup_def="off"
else
  rtxgroup_def="on"
fi
# Add std accounts.
is_root=`grep '^root:' ${NEW_ROOT}etc/passwd`
is_oper=`grep '^oper:' ${NEW_ROOT}etc/passwd`
is_prog=`grep '^prog:' ${NEW_ROOT}etc/passwd`
if [ "$is_root" -a "$is_oper" -a "$is_prog" ]; then
  stdaccts_def="off"
else
  stdaccts_def="on"
fi

# Create '/etc/lilo.conf', unless it has correct kind of 'boot=/dev/sda' line.
liloconf_def="on"
if [ -r ${NEW_ROOT}etc/lilo.conf ]; then
  if (grep '^boot=.*a' ${NEW_ROOT}etc/lilo.conf >/dev/null); then
    liloconf_def="off"
  fi
fi

## If fort77 is of version 1.15 and doesn't have 'gcc -E -' fix, fix it.
#fort77_def="off"
#if (fgrep '$version = "1.15"' ${NEW_ROOT}usr/bin/fort77 >/dev/null); then
#  if (fgrep 'gcc -E - -trad' ${NEW_ROOT}usr/bin/fort77 >/dev/null); then
#    :
#  else
#    fort77_def="on"
#  fi
#fi

# Has telnet '-h'?
noident_def="off"
if (fgrep '/usr/sbin/in.telnetd -h' ${NEW_ROOT}etc/inetd.conf >/dev/null); then
  noident_def="off"
fi

# Has wu-ftpd '-l'?
ftpdlog_def="off"
if (fgrep '/usr/sbin/ftpd -l' ${NEW_ROOT}etc/inetd.conf >/dev/null); then
  ftpdlog_def="off"
fi

# Do we have 'GOVERNMENT' prompts?
govt_def="off"

# Present a checklist of the patches to do.
if [ "$NODIALOGS" ]; then
  :  # Use PHASE1 params from command line.
elif [ "$SHOWPHASE1" ]; then
#  atgpib    "Install NI AT-GPIB driver and library" $atgpib_def
#  fort77    "Patch version 1.15 of fort77 command" $fort77_def
  ${DIALOG} --title "FS Adaptation: Modifications" \
    --checklist \
"An 'X' indicates that this action can safely be performed now.
(You may choose to uncheck a given action for specific reasons.)
\n\
Missing 'X' indicates that this action has already been performed.\n\
Most of these can only be done _once_, so please don't put an 'X' on\n\
unless you are certain that you want and can to do that item again." \
22 76 10 \
  skip      "Skip all steps below (regardless of [X] marks)" off \
  verbose   "Show names of files being processed in 'fsadapt'" off \
  rcboot    "Adjust 'rc.boot' to run FS-specific programs in boot" "on" \
  rtxgroup  "Add 'rtx' group to '/etc/group'" $rtxgroup_def \
  stdaccts  "Add 'oper' and 'prog' to '/etc/passwd'" $stdaccts_def \
  liloconf  "Put a simple LILO configuration into '/etc/lilo.conf'" $liloconf_def \
  fstab     "Make sure that '/etc/fstab' includes '/usr2' etc" "on" \
  noident   "Remove host and op.sys info from login prompts" $noident_def \
  ftpdlog   "Enable additional logging of FTP sessions served" $ftpdlog_def \
  govt      "Add 'U.S. Government' warnings to login prompts" $govt_def \
  2>/tmp/reply
  # Cancel?
  if [ $? != 0 ]; then
    rm -f /tmp/reply
    exit
  fi
  PHASE1=`cat /tmp/reply | sed 's!\"!!g' `
else
  PHASE1="skip"
fi
#--
  PATCH_ERRS=${SRCS}patch-results-`date +'%Y%m%d%H%M%S'`
  echo -e "Output of patch commands during the FS updating process\\n`date`\\n" > $PATCH_ERRS
  for i in $PHASE1; do
    case $i in
      skip)
break
;;
      verbose)
VERBO='-v'
VERBOQ=''
;;
#      kernelinc)
### kernel-1.2.8.patch alias mount root readonly/rtx 990/latency enabler.
##(cd ${NEW_ROOT}usr/src/linux; patch ${PATCHOPTS} <${SRCS}kernel-1.2.8.patch) 2>> $PATCH_ERRS
## After new kernel stuff is in place, adjust /usr/include/linux symlink.
#for SUBD in linux asm; do
#  if [ -L ${NEW_ROOT}usr/include/${SUBD} ]; then
#    rm -f ${NEW_ROOT}usr/include/${SUBD}
#  else
#    mv ${VERBO} -f ${NEW_ROOT}usr/include/${SUBD} ${NEW_ROOT}usr/include/${SUBD}.orig
#  fi
#  ln ${VERBO} -s ../src/linux/include/${SUBD} ${NEW_ROOT}usr/include/${SUBD}
#done
### And then we do a cruel thing, namely zap (possible) previous
### configuration choices and replace the default main configurator
### with choices of our own.
##rm -f ${NEW_ROOT}usr/src/linux/.config
##if [ ! -e ${NEW_ROOT}usr/src/linux/arch/i386/config.in.replaced ]; then
##  mv ${VERBO} ${NEW_ROOT}usr/src/linux/arch/i386/config.in ${NEW_ROOT}usr/src/linux/arch/i386/config.in.replaced
##fi
### (this is Linux kernel version specific, so use direct version number
###  to deliberately break this on new versions...)
##cp ${VERBO} -p ${SRCS}replacement-config-in ${NEW_ROOT}usr/src/linux-1.2.12/arch/i386/config.in
#;;
      atgpib)
# Linux-gpib-2.04 driver for NI ATGPIB.
pushd ${NEW_ROOT}usr/src >/dev/null
rm -rf linux-gpib* \
  ${NEW_ROOT}usr/include/gpib ${NEW_ROOT}usr/lib/libgpib.a
tar ${VERBO} -xzf ${SRCS}linux-gpib-2.04a.base.tar.gz 
mv ${VERBO} linux-gpib linux-gpib-2.04
ln ${VERBO} -s linux-gpib-2.04 linux-gpib
ln ${VERBO} -s ../src/linux-gpib/include ${NEW_ROOT}usr/include/gpib
ln ${VERBO} -s ../src/linux-gpib/lib/libgpib.a ${NEW_ROOT}usr/lib/libgpib.a
# Make GPIB driver use MODEVERSION kernel symbols.
(cd linux-gpib; patch ${PATCHOPTS} <${SRCS}linux-gpib-2.04a-base.patch) 2>> $PATCH_ERRS
### Make /usr/bin/dialog available as /bin/dialog for gpib configurator.
##if [ ! -e ${NEW_ROOT}bin/dialog ]; then
##  ln ${VERBO} -s ../usr/bin/dialog ${NEW_ROOT}bin/dialog
##fi
# Replace the default '/etc/gpib.conf' with our version with 32 devices.
if [ ! -e linux-gpib/util/templates/gpib.conf.dist ]; then
  mv ${VERBO} -f linux-gpib/util/templates/gpib.conf linux-gpib/util/templates/gpib.conf.dist
fi
cp ${VERBO} -a ${SRCS}replacement-gpib-conf-template linux-gpib/util/templates/gpib.conf
popd >/dev/null
# Copy the precompiled 'gpib0.o' into the system.
cp ${VERBO} -p ${SRCS}gpib0.o /lib/modules/`uname -r`/misc
depmod ${VERBO} -a -e
rmmod gpib0 >/dev/null 2>&1
insmod ${VERBO} gpib0
# Patch for incorrectly tar-expanded /etc/gpib.conf files:
if [ -e ${NEW_ROOT}etc/gpib.conf ]; then
  chown ${VERBO} root.990 ${NEW_ROOT}etc/gpib.conf
  chmod ${VERBO} 664 ${NEW_ROOT}etc/gpib.conf
fi
;;
      rcboot)
# This used to have a bootup/time disabling of powerdown sudo passwd query:
##mkdir -p -m 700 /tmp/.odus /var/run/sudo
##touch -t 123123592037 /tmp/.odus/powerdow /var/run/sudo/powerdow[n]
# Add establishing FS shared memory to '/etc/rc.boot/' directory.
# Make a link to FS-specific rc script executed during boot.
rm ${VERBO} -f ${NEW_ROOT}etc/rc.boot/fs
ln ${VERBO} -s /usr2/fs/misc/rc.fs ${NEW_ROOT}etc/rc.boot/fs
;;
      rtxgroup)
# Add 'rtx' / 990 group into '/etc/group'.
if (grep 'rtx:.:990' ${NEW_ROOT}etc/group >/dev/null); then
  :
else
  addgroup --gid 990 rtx
fi
;;
      stdaccts)
# Add std accounts into '/etc/passwd'.
if [ ! "$is_oper" ]; then
  echo 'oper:*:501:990:VLBI Operator:/home/oper:/usr/bin/tcsh' >> ${NEW_ROOT}etc/passwd
fi
mkdir -p ${NEW_ROOT}home/oper
chown ${VERBO} 501.990 ${NEW_ROOT}home/oper
if [ ! "$is_prog" ]; then
  echo 'prog:*:502:990:FS Programmer:/home/prog:/usr/bin/tcsh' >> ${NEW_ROOT}etc/passwd
fi
mkdir -p ${NEW_ROOT}home/prog
chown ${VERBO} 502.990 ${NEW_ROOT}home/prog
;;
      liloconf)
# Now we create a typical '/etc/lilo.conf' (similar to Debian 2.2 defaults).
cat >${NEW_ROOT}etc/lilo.conf <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
# LILO configuration produced by $0
# on `date`.
# ---------------
# /etc/lilo.conf - See: `lilo(8)' and `lilo.conf(5)',
# ---------------       `install-mbr(8)', `/usr/share/doc/lilo/',
#                       and `/usr/share/doc/mbr/'.

# +---------------------------------------------------------------+
# |                        !! Reminder !!                         |
# |                                                               |
# | Don't forget to run `lilo' after you make changes to this     |
# | conffile, `/boot/bootmess.txt', or install a new kernel.  The |
# | computer will most likely fail to boot if a kernel-image      |
# | post-install script or you don't remember to run `lilo'.      |
# |                                                               |
# +---------------------------------------------------------------+

# Support LBA for large hard disks.
#
lba32

# Specifies the boot device.  This is where Lilo installs its boot
# block.  It can be either a partition, or the raw device, in which
# case it installs in the MBR, and will overwrite the current MBR.
#
boot=${NEW_ROOT_DEVICE%[0-9]}  # the whole disk, i.e. use MBR of that disk

# Specifies the device that should be mounted as root. (`/')
#
root=${NEW_ROOT_DEVICE}

# Enable map compaction:
# Tries to merge read requests for adjacent sectors into a single
# read request. This drastically reduces load time and keeps the
# map smaller.  Using `compact' is especially recommended when
# booting from a floppy disk.  It is disabled here by default
# because it doesn't always work.
#
# compact

linear        # enables LILO boot regardless of BIOS LBA translations on/off

# Installs the specified file as the new boot sector
#
install=/boot/boot.b

# Specifies the location of the map file
#
map=/boot/map

# You can set a password here, and uncomment the `restricted' lines
# in the image definitions below to make it so that a password must
# be typed to boot anything but a default configuration.  If a
# command line is given, other than one specified by an `append'
# statement in `lilo.conf', the password will be required, but a
# standard default boot will not require one.
#
# This will, for instance, prevent anyone with access to the
# console from booting with something like `Linux init=/bin/sh',
# and thus becoming `root' without proper authorization.
#
# Note that if you really need this type of security, you will
# likely also want to use `install-mbr' to reconfigure the MBR
# program, as well as set up your BIOS to disallow booting from
# removable disk or CD-ROM, then put a password on getting into the
# BIOS configuration as well.  Please RTFM `install-mbr(8)'.
#
# password=tatercounter2000

# Specifies the number of deciseconds (0.1 seconds) LILO should
# wait before booting the first image.
#
delay=20

# You can put a customized boot message up if you like.  If you use
# `prompt', and this computer may need to reboot unattended, you
# must specify a `timeout', or it will sit there forever waiting
# for a keypress.  `single-key' goes with the `alias' lines in the
# `image' configurations below.  eg: You can press `1' to boot
# `Linux', `2' to boot `LinuxOLD', if you uncomment the `alias'.
#
# message=/boot/bootmess.txt
#	prompt
#	single-key
#	delay=100
#	timeout=100

# Specifies the VGA text mode at boot time. (normal, extended, ask, <mode>)
#
# vga=ask
# vga=9
#
vga=normal

# Kernel command line options that apply to all installed images go
# here.  See: The `boot-prompt-HOWO' and `kernel-parameters.txt' in
# the Linux kernel `Documentation' directory.
#
# append=""
## For SCSI emulation of CD-R writer:  /amn 22-Jul-2000
#append="hdc=ide-scsi"
# FS Linux 3 used to need Digiboard parameters.
#append="digi=E,PC/Xi,D,8,120,D0000"

# Boot up Linux by default.
#
default=Linux

image=/vmlinuz
	label=Linux
	read-only
#	restricted
#	alias=1

image=/vmlinuz.old
	label=LinuxOLD
	read-only
	optional
#	restricted
#	alias=2

# If you have another OS on this machine to boot, you can uncomment the
# following lines, changing the device name on the `other' line to
# where your other OS' partition is.
#
# other=/dev/hda4
#	label=HURD
#	restricted
#	alias=3
EOF-marker-with-no-quoted-chars-to-get-var-expansion
;;
      fstab)
# Add swap, '/usr2', '/dosa', '/proc' into '/etc/fstab'.
if (fgrep 'swap' ${NEW_ROOT}etc/fstab >/dev/null); then
  :
else
  echo $NEW_SWAP_DEVICE '  swap   swap  defaults  1  1' >> ${NEW_ROOT}etc/fstab
fi

# Dialog about running 'mkswap' on this partition.
# (No point showing the dialog if we know we are running with
#  that swap partition enabled.)
if [ $NEW_SWAP_DEVICE != `fgrep "swap" ${NEW_ROOT}etc/fstab | cut -d' ' -f1` ]; then
  ${DIALOG} --title "Prepare this swap partition with 'mkswap'?" \
    --yesno \
"You need to run 'mkswap' on any new swap partition at least once.\n\
\n\
However, you _cannot_ run 'mkswap' on a partition
that is currently in use.  (This would crash the system.)\n\
\n\
If you want to run 'mkswap' on $NEW_SWAP_DEVICE, please select 'Yes'.
\n\
If $NEW_SWAP_DEVICE is currently in use for swapping,
please select 'No'." \
    17 74
  if [ $? = 0 ]; then
    mkswap $NEW_SWAP_DEVICE
  fi
fi

if (fgrep '/usr2' ${NEW_ROOT}etc/fstab >/dev/null); then
  :
else
  mkdir -p ${NEW_ROOT}usr2
  echo $NEW_USR2_DEVICE '  /usr2  ext2  defaults  1  1' >> ${NEW_ROOT}etc/fstab
fi
# Try to ensure that the partition is formatted.
# (Mounting an unformatted partition can cause horrid things
#  actually only if it has "old" ext2 file system after resizing a partition.)
if (mount | fgrep $NEW_USR2_DEVICE >/dev/null); then
  :
else
  ${DIALOG} --title "Prepare this '/usr2' partition with 'mke2fs'?" \
    --yesno \
"You need to run 'mke2fs' on any new Linux partition at least once.\n\
\n\
However, you _cannot_ run 'mke2fs' on a partition
that is currently in use.  (This would crash the system.)\n\
\n\
If you think it is safe to run 'mke2fs' on $NEW_USR2_DEVICE,\n\
(and it is OK to _wipe out_ the current contents of that partition)\n\
please select 'Yes'.\n\
\n\
If $NEW_USR2_DEVICE is currently in use (mounted),\n\
please select 'No'." \
    17 74
  if [ $? = 0 ]; then
    /sbin/mke2fs $NEW_USR2_DEVICE
  fi
fi  # if the /usr2 device is not currently mounted

if (fgrep '/cdrom' ${NEW_ROOT}etc/fstab >/dev/null); then
  :
else
  mkdir -p ${NEW_ROOT}cdrom
  echo '/dev/cdrom  /cdrom iso9660 ro,noauto,user  0 0' >> ${NEW_ROOT}etc/fstab
fi

if (fgrep '/dosa' ${NEW_ROOT}etc/fstab >/dev/null); then
  :
else
  mkdir -p ${NEW_ROOT}dosa
  echo '/dev/fd0    /dosa  vfat    noauto,user  0 0' >> ${NEW_ROOT}etc/fstab
fi

if (fgrep '/proc' ${NEW_ROOT}etc/fstab >/dev/null); then
  :
else
  mkdir -p ${NEW_ROOT}proc
  echo 'none        /proc  proc  defaults  1  1' >> ${NEW_ROOT}etc/fstab
fi
;;
      fort77)
if (fgrep '$version = "1.15"' ${NEW_ROOT}usr/bin/fort77 >/dev/null); then
  if (fgrep 'gcc -E - -trad' ${NEW_ROOT}usr/bin/fort77 >/dev/null); then
    :
  else
    (cd ${NEW_ROOT}usr/bin; patch ${PATCHOPTS} <${SRCS}patch-fort77-1.15) 2>> $PATCH_ERRS
  fi
fi
;;
      noident)
if (fgrep '/usr/sbin/in.telnetd -h' ${NEW_ROOT}etc/inetd.conf >/dev/null); then
  :
else
  sed -e "s,/usr/sbin/in.telnetd,/usr/sbin/in.telnetd -h," ${NEW_ROOT}etc/inetd.conf >${NEW_ROOT}etc/inetd.conf.new
  mv ${VERBO} -f ${NEW_ROOT}etc/inetd.conf.new ${NEW_ROOT}etc/inetd.conf
fi
cat >${NEW_ROOT}etc/issue <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
Welcome to FS9 Kernel 4 on \l.

EOF-marker-with-no-quoted-chars-to-get-var-expansion
cat >${NEW_ROOT}etc/issue.net <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
Welcome to FS9 Kernel 4 on %t.

EOF-marker-with-no-quoted-chars-to-get-var-expansion
;;
      ftpdlog)
if (fgrep '/usr/sbin/ftpd -l' ${NEW_ROOT}etc/inetd.conf >/dev/null); then
  :
else
  sed -e "s,/usr/sbin/ftpd,/usr/sbin/ftpd -l," ${NEW_ROOT}etc/inetd.conf >${NEW_ROOT}etc/inetd.conf.new
  mv ${VERBO} -f ${NEW_ROOT}etc/inetd.conf.new ${NEW_ROOT}etc/inetd.conf
fi
;;
#      powerdown)
#cp ${VERBO} -a ${SRCS}powerdown ${NEW_ROOT}bin/powerdown
##xxx: must change to auto-edit /etc/sudoers
#cp ${VERBO} -a ${SRCS}sudoers ${NEW_ROOT}etc/sudoers
#;;
      govt)
cat >/tmp/govt.$$ <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
------------------------------------------------------------------------------

                           U.S. GOVERNMENT COMPUTER
            If not authorized to access this system, disconnect now.

                   YOU SHOULD HAVE NO EXPECTATION OF PRIVACY
By continuing, you consent to your keystrokes and data content being monitored.

------------------------------------------------------------------------------
EOF-marker-with-no-quoted-chars-to-get-var-expansion
# Login prompt:
if (fgrep 'GOVERNMENT' ${NEW_ROOT}etc/issue >/dev/null); then
  :
else
  cat /tmp/govt.$$ >>${NEW_ROOT}etc/issue
fi
# Network login prompt:
if (fgrep 'GOVERNMENT' ${NEW_ROOT}etc/issue.net >/dev/null); then
  :
else
  cat /tmp/govt.$$ >>${NEW_ROOT}etc/issue.net
fi
# FTP server:
if (fgrep 'GOVERNMENT' ${NEW_ROOT}etc/wu-ftpd-academ/welcome.msg >/dev/null); then
  :
else
  cat /tmp/govt.$$ >>${NEW_ROOT}etc/wu-ftpd-academ/welcome.msg
fi
# Normal login screens after login (incl. xterm).
if (fgrep 'GOVERNMENT' ${NEW_ROOT}etc/govtwarn.txt >/dev/null); then
  :
else
  cat /tmp/govt.$$ >>${NEW_ROOT}etc/govtwarn.txt
fi
if (fgrep 'etc/govtwarn.txt' ${NEW_ROOT}etc/profile >/dev/null); then
  :
else
  echo 'cat /etc/govtwarn.txt' >>${NEW_ROOT}etc/profile
fi
if (fgrep 'etc/govtwarn.txt' ${NEW_ROOT}etc/csh.login >/dev/null); then
  :
else
  echo 'cat /etc/govtwarn.txt' >>${NEW_ROOT}etc/csh.login
fi
rm -f /tmp/govt.$$
;;
      *)
        echo "fsadapt: unknown phase 1 operation ($i)" >&2
        exit
;;
    esac
  done
#--

# Wait for return if in verbose mode (to see the messages before
# 'dialog' is fired up again).
if [ $VERBO ]; then
  echo -n "Please press RETURN to continue. "; read $ans
fi


# Next: things that cannot be done before we have booted 
# with our NEW_ROOT / phase 2.

# Check that we are running off the "real" future '/' root,
# with correct '/etc/lilo.conf' (to safely install recompiled kernel.)
# (We built '/etc/lilo.conf' in the first phase, so it should be ok.)
if [ $NEW_ROOT != / ]; then
  ${DIALOG} --title "Need to reboot to continue installation" \
    --msgbox \
"\nPlease reboot the machine\n\
with a FS9 Linux boot floppy with 'rescue root=$NEW_ROOT_DEVICE' boot option\n\
to run with the new root file system on $NEW_ROOT_DEVICE.
\n\
After the reboot, continue the update process\n\
by rerunning this script ($0)." \
    17 74

  # Check for blank root password and show a reminder.
  if (grep '^root::' ${NEW_ROOT}etc/passwd >/dev/null); then
    ${DIALOG} --title "Check user accounts and passwords" \
      --msgbox \
"\nPlease remember to set a password for 'root'\n\
_immediately_ after the reboot and when you have logged in\n\
as 'root' the first time\n\
by invoking the command 'passwd'.\n"\
      15 74
  fi

  # Rest of this script _must not_ be run if not on the new root.
  rm -f /tmp/reply
  exit
fi

# Finally, back to the "running with the real root on" business...

# xxx: Hmm, we could try to set up default stuff/confs
# in '~oper/' and '~/prog', including
# - 'setenv EDITOR' to a favorite choice + putting in 'edit'/'e'
#    aliases to invoke this "pre-selected" editor,
# - FS-specific login settings, PATH?
# But note that '~oper/' and '~/prog' might actually be on '/usr2'
# and thus come with FS package...

# Selecting defaults for phase 2 of updating.

# Create '/etc/lilobkp.conf'?  (Always, for now.)
lilobkp_def="on"
#if [ -r ${NEW_ROOT}etc/lilobkp.conf ]; then
#  if (fgrep 'digi=' ${NEW_ROOT}etc/lilobkp.conf >/dev/null); then
#    lilobkp_def="off"
#  fi
#fi

# Check network service status:
if (grep '^discard' /etc/inetd.conf >/dev/null); then
  netdiscard_def="off"
else
  netdiscard_def="off"
fi
if (grep '^daytime' /etc/inetd.conf >/dev/null); then
  netdaytime_def="off"
else
  netdaytime_def="off"
fi
if (grep '^time' /etc/inetd.conf >/dev/null); then
  nettime_def="off"
else
  nettime_def="off"
fi
if (grep '^talk' /etc/inetd.conf >/dev/null); then
  nettalk_def="off"
else
  nettalk_def="off"
fi
if (grep '^ntalk' /etc/inetd.conf >/dev/null); then
  netntalk_def="off"
else
  netntalk_def="off"
fi
if (grep '^finger' /etc/inetd.conf >/dev/null); then
  netfinger_def="off"
else
  netfinger_def="off"
fi
# Check for 'oper':
if (grep '^oper:' /etc/passwd >/dev/null); then
  oper_account_def="off"
else
  oper_account_def="on"
fi
# Check for 'prog':
if (grep '^prog:' /etc/passwd >/dev/null); then
  prog_account_def="off"
else
  prog_account_def="on"
fi
# Try to figure out recommendations if these need to be done.
if [ -r /usr/src/linux-gpib/.config.stat ]; then
  config_gpib_def="off"
else
  config_gpib_def="on"
fi
if [ -r /usr/src/linux/.config -a -r /usr/src/linux/fs42.cfg -a -r /usr/src/linux/include/linux/modversions.h ]; then
  config_kernel_def="off"
else
  config_kernel_def="on"
fi
# Has ibProto.h been generated?
if [ -r /usr/include/gpib/ibProto.h ]; then
  comp_gpib_def="off"
else
  comp_gpib_def="on"
fi
# Enable '/etc/rc.boot/0setserial' for Boca BB2016 / Vikom Pro.
if [ -r /etc/rc.boot/0setserial -o -e /etc/rc.boot/0setserial.not-needed ]; then
  rcserial_def="off"
else
  rcserial_def="on"
fi

# Present a checklist which of the following to do.
if [ "$NODIALOGS" ]; then
  :  # Use PHASE2 params from command line.
elif [ "$SHOWPHASE2" ]; then
#  config_gpib   "Configure 'linux-gpib' driver and library" $config_gpib_def
#  comp_gpib     "Recompile 'linux-gpib' driver and library" $comp_gpib_def
  ${DIALOG} --title "FS Adaptation: Setup" \
    --checklist \
"Which of the following you would like to do?\n\
\n\
(Recommended options are shown with 'X';\n\
all of these can be safely attempted again and again.)" \
20 76 10 \
  skip          "Skip all steps below (regardless of [X] marks)" off \
  lilobkp       "Create '/etc/lilobkp.conf' for tar backups" $lilobkp_def \
  oper_account  "Create user account 'oper'" $oper_account_def \
  prog_account  "Create user account 'prog'" $prog_account_def \
  set_perms     "Set device permissions (serial, digi, gpib)" "on" \
  config_kernel "Configure Linux kernel (make config/dep/clean)" $config_kernel_def \
  comp_kernel   "Recompile Linux kernel (make-kpkg)" "off" \
  disk_space    "Clean up '.o' files created by 'comp_*' above" off \
  rcserial      "Enable 'rc.serial' to be run for Boca/Vikom" $rcserial_def \
  netdiscard    "Disable internal 'discard' net service" $netdiscard_def \
  netdaytime    "Disable internal 'daytime' net service" $netdaytime_def \
  nettime       "Disable internal 'time' net service " $nettime_def \
  nettalk       "Disable 'talk' net service" $nettalk_def \
  netntalk      "Disable 'ntalk' net service" $netntalk_def \
  netfinger     "Disable 'fingerd' net service" $netfinger_def \
  2>/tmp/reply
  # Cancel?
  if [ $? != 0 ]; then
    rm -f /tmp/reply
    exit
  fi
  PHASE2=`cat /tmp/reply | sed 's!\"!!g' `
else
  PHASE2="skip"
fi
#--
  for i in $PHASE2; do
    case $i in
      skip)
break
;;
# Auto-edit existing /etc/lilo.conf for second-disk LILO installation.
# (Used in making tar-based backups.)
      lilobkp)
sed -f - ${NEW_ROOT}etc/lilo.conf > ${NEW_ROOT}etc/lilobkp.conf <<EOF
/^boot=/i\\
disk=/dev/sdb bios=0x80
s,^boot=/dev/sda,boot=/dev/sdb,
s,=/,=/db/,
EOF
;;
      oper_account)
# Add user 'oper'.
${DIALOG} --title "Please add 'oper' account" \
  --msgbox \
"\nYou need to set up a user account 'oper'\n\
for normal FS operations.\n\
\n\
An interactive command 'adduser' will be invoked\n\
after you select 'Ok'."\
  15 74
adduser --uid 501 --gid 990 --gecos 'VLBI Operator' oper
chsh -s /usr/bin/tcsh oper
;;
      prog_account)
# Add user 'prog'.
${DIALOG} --title "Please add 'prog' account" \
  --msgbox \
"\nYou need to set up a user account 'prog'\n\
for FS programming work.\n\
\n\
An interactive command 'adduser' will be invoked\n\
after you select 'Ok'."\
  15 74
adduser --uid 502 --gid 990 --gecos 'FS Programmer' prog
chsh -s /usr/bin/tcsh prog
;;
      config_gpib)
# Configure linux-gpib.
rm -f /etc/gpib.conf
(cd /usr/src/linux-gpib; make clean; make config)
chown ${VERBO} root.990 /etc/gpib.conf
chmod ${VERBO} 664 /etc/gpib.conf
# Wait for return if in verbose mode (to see the messages before
# 'dialog' is fired up again).
if [ $VERBO ]; then
  echo -n "Please press RETURN to continue. "; read $ans
fi
;;
      set_perms)
#Finally corrected in Debian 2.2: st is now 'root.tape'!
## Give world r/w access to SCSI tape drives.
## (Debian 2.0 /dev/*st* devices are owned by root.disk,
##  so putting oper,prog into 'tape' group wouldn't suffice.)
#chmod ${VERBO} a+rw /dev/*st[0-7]*
#Finally provided in Debian 2.2!
#if [ ! -e /etc/rmt ]; then
#  ln ${VERBO} -s ../usr/sbin/rmt /etc/rmt
#fi
# Make /dev/tape by default a symlink to the first SCSI tape.
# (This is used by 'mt' as default tape device.)
if [ ! -e /dev/tape ]; then
  ln ${VERBO} -s nst0 /dev/tape
fi
# Enable 'oper', 'prog' access to floppy, serial, and other devices.
#for GRP in dialout cdrom floppy tape audio backup dos; do  # no dos in Hamm
for GRP in dialout cdrom floppy tape audio backup; do
  adduser ${VERBOQ} oper $GRP
  adduser ${VERBOQ} prog $GRP
done
# Permissions of /dev/ttyS*, /dev/ttyD* (Digi), /dev/gpib*.
# (This can be run only after configuring linux-gpib
#  which creates these device special files.)
## Old: chmod ${VERBO} a=rw /dev/cua* /dev/tty[dD]* /dev/gpib*
## New: we create new copies of device special files.
pushd /dev >/dev/null
for line in 4 5 6 7 8 9 10 11 12 13 14 15; do
  ./MAKEDEV ${VERBO} ttyS$line
done
./MAKEDEV ${VERBO} digi
popd >/dev/null
###(cd /dev; chown ${VERBO} root.rtx gpib0/master; chmod ${VERBO} ug=rw gpib0/master)
# Wait for return if in verbose mode (to see the messages before
# 'dialog' is fired up again).
if [ $VERBO ]; then
  echo -n "Please press RETURN to continue. "; read $ans
fi
;;
      config_kernel)
# Configure kernel.
cp ${VERBO} -a ${SRCS}fs42.cfg /usr/src/linux/fs42.cfg
# xxx: any new kernel source package will contain '.config'...
if [ ! -e /usr/src/kernel-source-2.2.19/.config ]; then
  cp ${VERBO} -a ${SRCS}fs42.cfg /usr/src/kernel-source-2.2.19/.config
fi
(cd /usr/src/linux; make menuconfig; make clean; make dep; make clean)
;;
      comp_kernel)
# Recompile kernel.
# "traditional": (cd /usr/src/linux; make zImage)
(cd /usr/src/linux; rm -f stamp-configure; rm-f stamp-image; make-kpkg --revision fslcl1 binary-arch)
# xxx: (cd /usr/src; dpkg --install kernel-package*fslcl1.deb)
;;
      comp_gpib)
# Recompile linux-gpib.
# This requires that kernel has been re-configured (modversions.h available).
(cd /usr/src/linux-gpib; make; cp ${VERBO} -p driver/gpib0.o /lib/modules/`uname -r`/misc)
depmod ${VERBO} -a -e
# xxx: modconf?
# Wait for return if in verbose mode (to see the messages before
# 'dialog' is fired up again).
if [ $VERBO ]; then
  echo -n "Please press RETURN to continue. "; read $ans
fi
;;
      disk_space)
pushd /usr/src >/dev/null
pushd linux >/dev/null
# This will leave the much needed (gpib recompilation) modversions.h
# stuff around:
make clean
popd >/dev/null
pushd linux-gpib >/dev/null
# And this will effectively zap gpib configuration...:
make clean
popd >/dev/null
popd >/dev/null
;;
      rcserial)
# Enable '/etc/rc.boot/0setserial' for Boca BB2016 or Vikom Pro
# to be run in boot.
${DIALOG} --title "Really enable Boca BB2016 / Vikom Pro?" \
  --menu \
"\nAlthough this script offers installing '/etc/rc.boot/0setserial'\n\
to recognize Boca BB2016 or Vikom Pro multiport RS232 cards,\n\
you should do this _only_ if you really have such a card\n\
in your PC (or are planning to edit the installed file manually).
\n\
If you have a Boca BB2016 or Vikom Pro, please select 'Yes'.
\n\
If you don't have a Boca BB2016 nor Vikom Pro, please select 'No'.\n" \
      19 74 3 \
  Yes   "Yes, I want '/etc/rc.boot/0setserial' to run for Boca BB2016" \
  No    "No, I don't need it" \
  Defer "I'm not sure yet, ask again in a later run of 'fsadapt'" \
2>/tmp/reply
if [ $? = 0 ]; then
  pushd /etc/rc.boot >/dev/null
  if [ `cat /tmp/reply` = Yes ]; then
    cp ${VERBO} -a ${SRCS}replacement-0setserial 0setserial
  elif [ `cat /tmp/reply` = No ]; then
    if [ -r 0setserial ]; then
      mv ${VERBO} -f 0setserial 0setserial.not-needed
    else
      # To signify the default [ ] off:
      touch 0setserial.not-needed
    fi
  elif [ `cat /tmp/reply` = Defer ]; then
    if [ -r 0setserial ]; then
      mv ${VERBO} -f 0setserial 0setserial.defer
    fi
  fi
  popd >/dev/null
fi
;;
      netdiscard)
update-inetd --disable discard --multi
;;
      netdaytime)
update-inetd --disable daytime --multi
;;
      nettime)
update-inetd --disable time --multi
;;
      nettalk)
update-inetd --disable talk
;;
      netntalk)
update-inetd --disable ntalk
;;
      netfinger)
update-inetd --disable finger
;;
      *)
        echo "fsadapt: unknown phase 2 operation ($i)" >&2
        exit
;;
    esac
  done
#--


# Next: phase 3, things that may be done later again.

# Selecting defaults for phase 3 of updating.

# Check if our network settings are right.
if [ -e /etc/hostname-assumed-correct ]; then
  netconfig_def="off"
else
  netconfig_def="on"
fi
# LILO conffile available?
if [ -r /etc/lilo.conf ]; then
  lilo_def="on"
else
  lilo_def="off"
fi
# X config already done?
if [ -e /etc/X11/config.no-x-yet ]; then
  setup_x_def="on"
else
  setup_x_def="off"
fi
# CD-ROM type selected?
if [ -e /dev/cdrom.selected ]; then
  set_cdrom_def="off"
else
  set_cdrom_def="on"
fi
# /etc/printcap already there
if [ -e /etc/printcap ]; then
  printer_def="off"
else
  printer_def="on"
fi

# Present a checklist which of the following to do.
if [ "$NODIALOGS" ]; then
  :  # Use PHASE3 params from command line.
elif [ "$SHOWPHASE3" ]; then
  ${DIALOG} --title "FS Adaptation: Settings" \
    --checklist \
"Which of the following you would like to do?\n\
\n\
(Recommended options are shown with 'X';\n\
all of these can be safely attempted again and again.)" \
20 76 10 \
  drivers       "Select loadable drivers (incl. network)" "on" \
  netconfig     "Alter TCP/IP configuration (IP numbers)" $netconfig_def \
  lilo          "Make sure LILO is properly installed" $lilo_def \
  gpmconfig     "Select virtual console gpm mouse type" on \
  setup_x       "Select X Window System server/configuration" $setup_x_def \
  printer       "Setup your printer for 'lpr' use" $printer_def \
  set_cdrom     "Select your CD-ROM type" $set_cdrom_def \
  eximconfig    "Change configuration of 'exim' email system" off \
  2>/tmp/reply
  # Cancel?
  if [ $? != 0 ]; then
    rm -f /tmp/reply
    exit
  fi
  PHASE3=`cat /tmp/reply | sed 's!\"!!g' `
else
  PHASE3="skip"
fi
#--
  for i in $PHASE3; do
    case $i in
      skip)
break
;;
      drivers)
# Copy the precompiled 'gpib0.o' if a newly compiled one is not already there.
if [ ! -e /lib/modules/`uname -r`/misc/gpib0.o ]; then
  cp ${VERBO} -p ${SRCS}gpib0.o /lib/modules/`uname -r`/misc
fi
depmod ${VERBO} -a -e
${DIALOG} --title "Selecting loadable device drivers" \
  --msgbox \
"\nYou should ensure that a network device driver\n\
which corresponds to your network interface card is loaded\n\
and that the 'gpib0.o' NI ATGPIB driver is loaded\n\
(if you have a NI ATGPIB board installed).\n\
\n\
An interactive command 'modconf' will be invoked\n\
after you select 'Ok'.  It updates the module list\n\
of modules to load during boot in '/etc/modules' for you."\
  15 74
modconf
;;
      netconfig)
${DIALOG} --title "Check the TCP/IP network settings" \
  --menu \
"\nThe current TCP/IP networking settings are for the machine:\n\n\
    `cat /etc/hostname`\n\n\
If this is correct, select 'Correct'.\n\n\
If this is _not_ correct, disconnect the Ethernet cable and\n\
select 'Netconfig' to invoke the 'netconfig' script.\n\
(You can also defer setting up IP numbers to a later 'fsadapt' run.)\n" \
    19 74 3 \
  Correct     "Yes, the settings are correct for this machine" \
  Netconfig   "No, I want to run 'netconfig' now to set up IP addresses" \
  Defer       "No, but I don't know the IP numbers yet, defer to later" \
2>/tmp/reply
if [ $? = 0 ]; then
  if [ `cat /tmp/reply` = Defer ]; then
    : # Nothing
  else
    if [ `cat /tmp/reply` = Netconfig ]; then
      ${SRCS}netconfig
    fi
    touch /etc/hostname-assumed-correct
  fi
fi
;;
      lilo)
# Install LILO.
/sbin/lilo
# Wait for return if in verbose mode (to see the messages before
# 'dialog' is fired up again).
if [ $VERBO ]; then
  echo -n "Please press RETURN to continue. "; read $ans
fi
;;
      gpmconfig)
# Try to stop, make sure by killing,...
/etc/init.d/gpm stop >/dev/null 2>&1
gpm -k >/dev/null 2>&1
# ...configure...
gpmconfig
# ...try to stop, make sure by killing,...
/etc/init.d/gpm stop >/dev/null 2>&1
gpm -k >/dev/null 2>&1
# ...and finally start with new parameters.
/etc/init.d/gpm start
;;
      setup_x)
# Present a menu of X Window System servers and config files.
xconfigok=0
while [ $xconfigok = 0 ]; do

${DIALOG} --title "Setup X Window System" --menu "Select your SVGA card / monitor type:" 17 76 10 \
  No_X         "Leave X setup undetermined, will choose later" \
  xf86config   "Run 'xf86config' to build the conf" \
`(cd ${SRCS}xf86configs; ls -1 */*) | sed -e 's!^\(.*\)$!\1 \1!'` \
2>/tmp/reply
if [ $? = 0 ]; then
  SEL=`cat /tmp/reply`
  if [ $SEL = "No_X" ]; then
    if [ -e /etc/X11/config ]; then
      mv ${VERBO} -f /etc/X11/config /etc/X11/config.no-x-yet
      mv ${VERBO} -f /etc/X11/XF86Config /etc/X11/XF86Config.no-x-yet
    fi
    xconfigok=1
    break
  fi
  # Put xdm-capable basic X config back in before configuration attempts.
  if [ -e /etc/X11/config.no-x-yet ]; then
    mv ${VERBO} -f /etc/X11/config.no-x-yet /etc/X11/config
  else
    cp ${VERBO} -p ${SRCS}backup-x-config /etc/X11/config
  fi
  # Get rid of renamed wrong/old XF86Config.
  rm ${VERBO} -f /etc/X11/XF86Config.no-x-yet
  # Configure using xf86config or prepackaged conf files.
  if [ $SEL = "xf86config" ]; then
    xf86config
  else
    if [ -e ${SRCS}xf86configs/${SEL} ]; then
      if [ -e /etc/X11/XF86Config ]; then
        mv ${VERBO} -f /etc/X11/XF86Config /etc/X11/XF86Config.old
      fi
      # Get mouse type from gpm:
      if [ -r /etc/gpm.conf ]; then
        source /etc/gpm.conf
        case $type in
          ms)   MTYPE="Microsoft" ;;
          bare) MTYPE="Microsoft" ;;
          msc)  MTYPE="MouseSystems" ;;
          mman) MTYPE="MouseMan" ;;
          logi) MTYPE="Logitech" ;;
          ps2)  MTYPE="PS/2" ;;
          mm)   MTYPE="MMSeries" ;;
          *)    MTYPE="MouseMan" ;;
        esac
      else
        MTYPE="MouseMan"
      fi
      sed -e "s,MouseMan,${MTYPE}," ${SRCS}xf86configs/${SEL} > /etc/X11/XF86Config
      # Making the selected server the new default server.
      cat >/tmp/Xserver.$$ <<EOF
/usr/bin/X11/XF86_NONE
EOF
      tail +2 /etc/X11/Xserver >>/tmp/Xserver.$$
      mv ${VERBO} -f /tmp/Xserver.$$ /etc/X11/Xserver
      CARD=${SEL%/*}
      /var/lib/dpkg/info/xserver-${CARD}.postinst

      # Update Mach64 X server for latest ATI cards to 3.3.6.
      cmp --silent ${SRCS}/XF86_Mach64 /usr/X11R6/bin/XF86_Mach64
      if [ $? != 0 ]; then  # different, replace
        mv ${VERBO} -f /usr/X11R6/bin/XF86_Mach64 /usr/X11R6/bin/XF86_Mach64.Debian
        cp -a ${VERBO} ${SRCS}/XF86_Mach64 /usr/X11R6/bin/XF86_Mach64
      fi
    fi
  fi
else
  # Cancel selected, get out of loop:
  xconfigok=1
fi

# Test the new config:
if [ $xconfigok = 0 ]; then
		echo -n 'Do you want to test the configuration? (y/n) [y] '
		read input
		if [ "$input" = "n" ]
		then
		    testconfig=0
		else
		    testconfig=1
		fi
		
		if [ $testconfig = 1 ]
		then
		    echo
		    echo 'The X server will start in 10 seconds. If the configuration'
		    echo 'file is correct, you should see a grey patterned screen'
		    echo 'with an X shaped cursor in the middle. The mouse should'
		    echo 'move the cursor.'
		    echo
		    echo 'If the virtual screen resolution is higher than the default'
		    echo 'one, you may not be able to see the cursor immediately.'
		    echo 'It should become visible when you move the mouse.'
		    echo
		    echo 'This display should disappear after another 10 seconds; you'
		    echo 'will then be asked whether the test worked.'
		    echo
		    echo 'Waiting 10 seconds before starting X server...'
		    sleep 10
		    echo 'Starting X server...'
		    /usr/X11R6/bin/X :9 &
		    xserverpid=$!
		    sleep 11
		    set +e
		    kill $!
		    set -e
		    sleep 3
		    echo -n 'Did the X server work properly? (y/n) [n] '
		    read input
		    if [ "$input" = "y" ]
		    then
			xconfigok=1
		    else
			xconfigok=0
			rm -f /etc/X11/XF86Config
			mv ${VERBO} -f /etc/X11/config /etc/X11/config.no-x-yet
		    fi
		else
		    # Assume the file is ok without testing
		    xconfigok=1
		fi
fi

done
cp ${VERBO} -a ${SRCS}replacement-Xresources /etc/X11/Xresources
;;
      printer)
if [ ! -e /etc/printcap.orig ]; then
  if [ -e /etc/printcap ]; then
    mv ${VERBO} -f /etc/printcap /etc/printcap.orig
  fi
fi
rm -f /etc/printcap

${DIALOG} --title "Printer Configuration Overview" --msgbox \
"Configuring printers includes the following three steps:\n\
\n\
1) Selecting the default paper size (a4, letter)\n\
   with 'paperconfig'.\n\
2) Creating local printer queues with 'magicifilterconfig'.\n\
   You should create local queues for remote printers, too,\n\
   but use '/dev/null' as printer port (instead of '/dev/lp1').\n\
3) Creating remote \"feeder\" queues for local '/dev/null'\n\
   printers created in step 2 above.\n\
\n\
These steps will now be invoked automatically in a row." 16 70

paperconfig --force

magicfilterconfig

while true; do

${DIALOG} --title "Local name for a remote printer" --inputbox \
"Please enter a local name of a remote printer\n\
(a printer you just configured to use /dev/null\n\
as its printing port device) for which you will want to\n\
supply remote host and printer queue information now.\n\n\
Just press Enter if you have no remote printers." 13 60 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
MYPR="`cat /tmp/reply`"
rm -f /tmp/reply

if [ x$MYPR = x ]; then
  break
fi

${DIALOG} --title "Filter name" --inputbox \
"Please enter the name of the filter program you selected\n\
when you configured this printer ('$MYPR')\n\
to use '/dev/null' in 'magicfilterconfig'.\n\n\
(Use the short name without trailing '-filter'.)" 13 60 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
MYFILT="`cat /tmp/reply`-filter"
rm -f /tmp/reply

${DIALOG} --title "Remote computer name" --inputbox \
"Please enter the TCP/IP name of the computer \
to which the remote printer is connected." 12 60 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
RMHOST="`cat /tmp/reply`"
rm -f /tmp/reply

${DIALOG} --title "Remote printer name" --inputbox \
"Please enter the printer queue name on $RMHOST \
you wish to use as $MYPR on this computer.  \
(This printer must accept binary/'raw' data.)  \
Please remember to enable remote access in $RMHOST's '/etc/hosts.lpd' \
(or equivalent)." 12 60 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
RMPR="`cat /tmp/reply`"
rm -f /tmp/reply

cat >> /etc/printcap <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
${MYPR}queue:\\
        :lp=:mx#0:rm=$RMHOST:rp=$RMPR:\\
        :sd=/var/spool/lpd/${MYPR}queue:\\
        :lf=/var/log/lpd/lp-errs:
EOF-marker-with-no-quoted-chars-to-get-var-expansion
mkdir -p /var/spool/lpd/${MYPR}queue
chown root.lp /var/spool/lpd/${MYPR}queue
chmod ug=rwx,o=rx /var/spool/lpd/${MYPR}queue
cat > ${MFLOC}/${MYFILT}-to-${MYPR}queue <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
#!/bin/sh
# ${MYFILT}-to-${MYPR}queue -- an 'if=' script for a local printer ${MYPR}.
# ${MYPR} sends bytestreams to a remote printer ${MYPR}queue with lpr.
#
# This lpd 'if=' input filter script gets the following arguments:
# args: [-c] -wwidth -llength -iindent -n login -h host acct-file
#
# It would be nice to convey lpr user account onto the second lpr:
###${MFLOC}/${MYFILT} \$\@ | su login -c \'lpr -P${MYPR}queue\'

${MFLOC}/${MYFILT} \$\@ | lpr -P${MYPR}queue
EOF-marker-with-no-quoted-chars-to-get-var-expansion
chmod a+x ${MFLOC}/${MYFILT}-to-${MYPR}queue

${DIALOG} --title "Need to manually edit /etc/printcap" --msgbox \
"You still need to manually edit your '/etc/printcap' file\n\
to enable the remote printer '${MYPR}'.\n\
\n\
Locate the 'if=${MFLOC}/${MYFILT}' entry that corresponds\n\
to printer '${MYPR}' and change it to read:\n\
'if=${MFLOC}/${MYFILT}-to-${MYPR}queue'.\n\
\n\
(You can do this now in another virtual console,\n\
 use 'Alt-Fn' keys to switch consoles.)" 15 70

done

lpc restart all
;;
      set_cdrom)
${DIALOG} --title "Configuring CD-ROM link (/dev/cdrom)" \
--menu "\nWhat type of CD-ROM drive do you have?\n" 15 71 6 \
"none" "No CD-ROM drive installed" \
"scd0" "Any SCSI CD-ROM drive" \
"hda"  "IDE, as master on primary interface (SWT default)" \
"hdb"  "IDE, as slave on primary interface" \
"hdc"  "IDE, as master on secondary interface" \
"hdd"  "IDE, as slave on secondary interface" \
 2> /tmp/cdtype
if [ $? = 1 -o $? = 255 ]; then
 rm -f /tmp/cdtype
else
 CD_ROM_TYPE="`cat /tmp/cdtype`"
 rm -f /tmp/cdtype
 if [ -b /dev/$CD_ROM_TYPE ]; then
  (cd /dev; chown ${VERBO} root.cdrom $CD_ROM_TYPE; ln ${VERBO} -sf $CD_ROM_TYPE cdrom)
  touch /dev/cdrom.selected
 fi
fi
;;
      eximconfig)
eximconfig --force
;;
      disk_space)
pushd /usr/src >/dev/null
pushd linux >/dev/null
# This will leave the much needed (gpib recompilation) modversions.h
# stuff around:
make clean
popd >/dev/null
pushd linux-gpib >/dev/null
# And this will effectively zap gpib configuration...:
make clean
popd >/dev/null
popd >/dev/null
;;
      *)
        echo "fsadapt: unknown phase 3 operation ($i)" >&2
        exit
;;
    esac
  done
#--

# xxx: (perhaps remove /usr-'.orig' files)
rm -f /tmp/reply
