#!/bin/bash
#
# set -u

source /usr/share/Landscape/LandscapeCore/bin/get_values
export PATH="$PATH:$LandscapeIn/bin"

function prepare_VMs()
{
    local usc="$1"
    ( 
        # TODO - need to check return codes
        cd /usr/share/Landscape/LandscapeCore/automate-VMs; 
        ./automate-00-createVMs --group="$usc"; 
        ./automate-00-createDisks --group="$usc"; 
        ./automate-00-createEtcHosts --group="$usc"; 
        ./automate-00-createPXE --group="$usc"; 
        ./automate-00-createShares --server --group="$usc";
    ) 
}

function install_VMs()
{
    local usc="$1"
    ( 
        # TODO - need to check return codes
        cd /usr/share/Landscape/LandscapeCore/automate-VMs; 
        ./automate-01-install-sles --group="$usc"; 
    )
}

theGROUP=""

while [ $# -gt 0 ]; do
    case "$1" in
        --group=* ) theGROUP=${1#--group=}
                    ;;
    esac
    shift
done

if [ -z "$theGROUP" ]; then
    echo "Group of nodes needs to be set with option --group=<groupname>"
    exit 2
fi

# TODO: optional disable install_VM (e.g. --prepare_only)
prepare_VMs "$theGROUP"
install_VMs "$theGROUP"



