#!/bin/sh
#
# "SystemImager" - Copyright (C) 1999-2001 Brian Elliott Finley <brian@systemimager.org>
#   Others who have contributed to this code (in alphabetical order):
#     dann frazier <dannf@ldl.fc.hp.com>
#     James Oakley <joakley@solutioninc.com>
#
#
# This file is: installclient
#   Interactively installs the SystemImager client files, and takes care of
#   upgrade issues.
#

# set some variables
DESTDIR=""
COMMAND_PATH=`dirname $0`
test "x$COMMAND_PATH" != "x" && cd $COMMAND_PATH

if [ ! -f ./install_lib ]; then
  echo "Couldn't find ./install_lib, exiting."
  exit 1
fi  
. ./install_lib

### BEGIN introduction
# you sure you want to install?
echo -n "Install SystemImager client? (y/[n]) "
read REPLY
case $REPLY in
  y|Y|Yes|yes|YES ) clear; echo Ok.  Installing SystemImager client... ;;
                * ) echo Install cancelled.  No files installed. && exit 1 ;;
esac

echo
sleep 2
### END introduction ###

OLD_FILES="/usr/sbin/prepareclient /usr/sbin/updateclient /usr/sbin/lsimage"
remove_old_files

CONFIG_FILES="/etc/systemimager/updateclient.local.exclude:./etc/systemimager/updateclient.local.exclude"
upgrade_config_files

### BEGIN install files
echo "Installing..."
find . -type d -mindepth 2 -exec install -d {} $DESTDIR/{} \;
find . -type f -mindepth 2 -exec install -D {} $DESTDIR/{} \;
if [ $? -ne 0 ]; then
    echo "Install failed."
    exit 1
fi
### END install files

echo "Checking for SystemConfigurator..."
which systemconfigurator > /dev/null
if [ $? -ne 0 ]; then
  delim
  echo "Warning:  The SystemImager client depends on SystemConfigurator, but"
  echo "it doesn't appear to be installed.  SystemConfigurator can be"
  echo "downloaded from:  http://sourceforge.net/projects/systemconfig"
  delim
  echo "Press <Enter> to continue..."
  read
fi  

echo "You must run \"prepareclient\" before you can retrieve this clients image."
echo -n "Do you want to run \"prepareclient\" now? ([y]/n) "
read REPLY
case $REPLY in
  n|N|No|no|NO ) echo "\"prepareclient\" not run."
                 echo "Be sure to run \"prepareclient\" before you run \"getimage\" on the imageserver."
                 exit 0
                 ;;
  * ) prepareclient ;;
esac

exit 0
