#!/bin/sh
#
# This script installs the sample desktop described 
# in the second edition of "The Complete FreeBSD"
#
# It's not very clever, since it's supposed to be a sample
# I encourage you to improve on what it does.
if [ ! -d /usr/X11R6/bin ]; then
  echo This script installs the sample X11 desktop.
  echo
  echo Before you can run it, you must install X11.  See the chapter
  echo \"Setting up X11\".
  echo
  echo When you have installed the software, please start this script again.
  exit 1
fi
installdir=`dirname $0`			# Get the name of the directory from which we're running
if [ "$installdir" = "" ]; then		# current directory,
  installdir=`pwd`
fi
rm -f /var/tmp/desktop-install-log
# Look for the CD-ROM
CD=`egrep ^[^#].*cd9660 /etc/fstab | head -n 1 | awk '{print $2}'`
echo CD-ROM: $CD
if [ "$CD" = "" ]; then
  echo "Can't find a CD-ROM drive.  Please enter the name of a directory"
  echo -n "where the packages can be found: "
  read CD
else
# Make sure it's mounted
  mount $CD 2>/dev/null >/dev/null
  CD=$CD/packages/All
fi
if [ ! -d $CD ]; then
  echo "Can't find the packages directory $CD"
  echo Please check that you have the correct CD-ROM mounted
  exit 1
fi
cd $CD
for i in bash-2* emacs-20* fvwm-2* netscape-navigator-4.0* less-* xearth* xfm* xpm*; do
  if [ ! -f $i ]; then
     echo "Sorry, I can't find " $i;
  else
    echo Installing $i*
    pkg_add $i* | tee -a /var/tmp/desktop-install-log
  fi
done
I=`whoami`
if [ $I = root ]; then
  while [ 1 ]; do
    echo Enter the name of a user to install the desktop configuration files.
    echo Press \'Enter\' to stop
    read user
    if [ $user != "" ]; then
      su $user -c $installdir/install-rcfiles
    fi
  done
else
  $installdir/install-rcfiles $I
fi
