#!/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
rm -f /var/tmp/desktop-install-log
# Look for the CD-ROM
CD=`grep cd9660 /etc/fstab | head -n 1 | awk '{print $2}'`
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"
  exit 1
fi
cd $CD
for i in bash-2 emacs fvwm-2 less- xearth xfm xpm; do
  echo Installing $i*
  pkg_add $i* | tee -a /var/tmp/desktop-install-log
done
I=`who am i | sed 's: .*::'`
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 ./install-rcfiles
    fi
  done
else
  ./install-rcfiles $I
fi
