#!/bin/sh
# 08/23/96 fsf frank@ssax.com 
# Boy, I wish zsh or ksh was the standard shell for linux
PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:.
ICONDIR=/usr/include/X11/pixmaps
BACKGROUNDDIR=/usr/lib/X11/afterstep/backgrounds

clear
echo "    ###############################"
echo "    # AfterStep v1.0 Installation #"
echo "    ###############################"
echo "This Installation must be run as root..."
echo "If you are not root, press control-C and"
echo "either login as root or su to root."
echo "Otherwise, press <Enter> and sit back"
echo "while your system is being upgraded to"
echo "AfterStep!"
read OK
echo
echo "Are you using an 8bpp display? (Y/N) - Answer Y if uncertain."
read ANSWER
echo
echo -E "Enter up to ten users who will be using AfterStep (eg, frank dan root):"
echo "  ------------------------------ NOTE ------------------------------"
echo "  Each will receive new .xsession, .xinitrc, .Xdefaults, and .steprc"
echo "  files.  Existing files will be saved and appended with a .before"
echo "  extension.  Press <Enter> if you would like to finish without"
echo "  configuring any users."
echo "  ------------------------------------------------------------------"
read users
./MakeMakefiles
make all
make install
make install.man
echo
echo "Installing icons..."
echo
if [ ! $ANSWER = "y" ] && [ ! $ANSWER = "Y" ]; then
  cp ./icons/*.xpm $ICONDIR
else
  cp ./icons/8bit/*.xpm $ICONDIR
fi
chmod 644 $ICONDIR/*.xpm
echo "Installing backgrounds..."
echo
mkdir $BACKGROUNDDIR
ln -s $BACKGROUNDDIR /backgrounds
cp ./backgrounds/* $BACKGROUNDDIR
chmod 644 $BACKGROUNDDIR/*.jpg
echo "Finished installing the binaries, manpages, and images!"
echo

if [ ! "$users" ]; then 
  echo
  echo "Installation is complete.  If you have had any trouble"
  echo "with this procedure, I can be reached via email at"
  echo "frank@ssax.com ... Happy stepping!"
  echo
  exit 
fi

for i in $users; do
  if [ -d /home/$i ]; then
    HOMEDIR=/home/$i
  elif [ -d /users/$i ]; then
    HOMEDIR=/users/$i
  else
    echo "Enter the home directory for user $i:"
    read HOMEDIR
  fi
    
  echo "Creating a default configuration for $i..."
  if [ -f $HOMEDIR/.xsession ]; then
    mv $HOMEDIR/.xsession $HOMEDIR/.xsession.before
  fi

  if [ -f $HOMEDIR/.xinitrc ]; then
    mv $HOMEDIR/.xinitrc $HOMEDIR/.xinitrc.before
  fi

  if [ -f $HOMEDIR/.Xdefaults ]; then
    mv $HOMEDIR/.Xdefaults $HOMEDIR/.Xdefaults.before
  fi

  if [ -f $HOMEDIR/.steprc ]; then
    mv $HOMEDIR/.steprc $HOMEDIR/.steprc.before
  fi

  cp ./install/xsession $HOMEDIR/.xsession
  chown $i $HOMEDIR/.xsession
  chmod 755 $HOMEDIR/.xsession

  cp ./install/xinitrc $HOMEDIR/.xinitrc
  chown $i $HOMEDIR/.xinitrc
  chmod 755 $HOMEDIR/.xinitrc

  cp ./install/Xdefaults $HOMEDIR/.Xdefaults
  chown $i $HOMEDIR/.Xdefaults

  if [ ! $ANSWER = "y" ] && [ ! $ANSWER = "Y" ]; then
    cp sample.steprc $HOMEDIR/.steprc
    chown $i $HOMEDIR/.steprc
  else
    cp ./install/sample.steprc.8bit.hangulfont $HOMEDIR/.steprc
    chown $i $HOMEDIR/.steprc
  fi
done

echo
echo "Installation is complete.  If you have had any trouble"
echo "with this procedure, I can be reached via email at"
echo "frank@ssax.com ... Happy stepping!"
echo
