#!/bin/sh

function usage2 () {
    echo "Start the script using:"
    echo "  $SCRIPT_NAME source destination"
    echo "where SOURCE is the mirrored S.u.S.E. Linux root"
    echo "directory"
    echo "and DESTINATION is the directory used for client"
    echo "nfs installation."
    exit 0
}

function usage () {
    echo ""
    echo "To be able  to use your mirrored  S.u.S.E. Linux"
    echo "as a  nfs  installation  source,  there  are two"
    echo "steps that need to be done."
    echo "1.  Change the file permissions for the files in"
    echo "suse/setup/tools to make these files executable."
    echo "2. Unpack the installation system contained in the"
    echo "file suse/inst-sys.tar.gz since the files within cant"
    echo "be transferred via ftp (devices etc)."
    echo ""
    echo "This script can do the work for you.  It sets up"
    echo "a complete copy of the tree  using hard links to"
    echo "keep mirror  from removing the files  within the"
    echo "installation system."
    echo ""
    usage2 
}

SCRIPT_NAME=`basename $0`

if [ $# -ne 2 ]; then
    usage
elif [ ! -d $1/suse/setup/tools ]; then
    usage2
fi

if [ ! -d $2 ]; then
    mkdir -p $2
fi

cp -al $1/* $2

if [ ! -d $2/suse/setup/tools ]; then
    echo "failed building directory tree"
    exit 1
fi

for file in $2/suse/setup/tools/* ; do
    chmod 755 $file
done

cd $2/suse

tar xzf inst-sys.tar.gz

rm inst-sys.tar.gz

