#!/bin/sh
#
# $Id: //depot/prod/ontap/curly/files/install_netapp#1 $
#
# Copyright (c) 1996-1997 Network Appliance, Inc.
# All rights reserved.
#

#  NOTE: This script must be kept as 100% generic and portable as
#  possible across *all* Unixes. Since we can't test on all Unixes,
#  please be very careful. Try to assume *only* a very vanilla bourne
#  shell and vanilla /bin utilities.
#

#  Die on any failure.
#
set -e

#  We won't even rely on basename being around!
#
MYNAME=install_netapp

USAGE="\
usage: $MYNAME [-k] <dest_dir>
  -k  (keep) do not remove tar_image and $MYNAME"

KEEP="${KEEP:=0}"

if [ $# -eq 2 ]
  then
    if [ "$1" = "-k" ]
      then KEEP=1; shift;
      else echo "$USAGE"; exit 1
      fi
  fi
      
if [ $# -ne 1 ]
  then echo "$USAGE"; exit 1; fi

DEST="$1";

if [ ! -d "$DEST" ]
  then echo "$MYNAME: \"$DEST\" is not a directory."; exit 1; fi

if [ ! -w "$DEST" ]
  then echo "$MYNAME: \"$DEST\" is not writable."; exit 1; fi

UNCOMPRESS="${UNCOMPRESS:=uncompress}"
UNCOMPRESSOPTS="${UNCOMPRESSOPTS:=}"

PATH="$PATH:/bin:/usr/bin:/usr/ucb"

if [ -f tar_image.Z ]
  then
    echo "$MYNAME: $UNCOMPRESS $UNCOMPRESSOPTS tar_image.Z"
    $UNCOMPRESS $UNCOMPRESSOPTS tar_image.Z
  fi

if [ ! -f tar_image ]
  then echo "$MYNAME: no file \"tar_image\"."; exit 1; fi

here=`/bin/pwd`

TAR="${TAR:=tar}"

echo "$MYNAME: cd \"$DEST\""
cd "$DEST"

echo "$MYNAME: rm -f etc/boot/netapp-x86 etc/boot/netapp-alpha"
rm -f etc/boot/netapp-x86 etc/boot/netapp-alpha

echo "$MYNAME: $TAR xvf \"$here/tar_image\""
$TAR xvf "$here/tar_image"

if [ $KEEP -eq 0 ]
  then
    echo "$MYNAME: cd \"$here\"; rm -f tar_image $MYNAME"
    cd $here; rm -f tar_image $MYNAME
  fi

exit 0
