#!/bin/sh

if [ "$#" != "0" ]; then
    echo "Usage: $0"
    exit 1
fi

if [ ! -f "VERSION" ]; then
    echo "$0: file not found: VERSION"
    exit 1
fi

if [ ! -f "lsvmprep" ]; then
    echo "$0: file not found: lsvmprep"
    exit 1
fi

srcdirname=`pwd`
destdirname=${destdir}/opt/lsvmtools-`cat VERSION`

rm -rf ${destdirname}
mkdir -p ${destdir}/opt
cp -r ${srcdirname} ${destdirname}

if [ "$?" != "0" ]; then
    echo "$0: file to create ${destdirname}"
    exit 1
fi

if [ ! -d "${destdirname}" ]; then
    echo "$0: directory does not exist: ${destdirname}"
    exit 1
fi

rm -f ${destdirname}/install

lsvmtool=${destdirname}/build/bin/lsvmtool

if [ ! -x "${lsvmtool}" ]; then
    echo "$0: lsvmtool not found: ${lsvmtool}"
    exit 1
fi

install_lsvmtool()
{
    if [ "$#" != "1" ]; then
        echo "$0: $FUNCNAME(): wrong # of args"
        exit 1
    fi

    local lsvmtool=$1

    if [ ! -x "${lsvmtool}" ]; then
        echo "$0: $FUNCNAME(): missing executable: ${lsvmtool}"
        exit 1
    fi

    local filename=/sbin/lsvmtool

    cp ${lsvmtool} ${filename}

    if [ ! -x "${filename}" ]; then
        echo "$0: $FUNCNAME(): failed to create: ${filename}"
        exit 1
    fi
}

install_lsvmtool ${lsvmtool}

rm -f ${destdirname}/build/bin/striplic

echo ""
echo "Created ${destdirname}"
echo ""
