#!/bin/sh

OSTYPEID=`cmk list ostypes keyword="Debian GNU/Linux 8 (64-bit)" | jq -r .ostype[0].id`
HVM=true

if [ none = "kvm" ]; then
    OSTYPEID=`cmk list ostypes keyword="Debian GNU/Linux 7(64-bit)" | jq -r .ostype[0].id`
    HVM=false
fi

TEMPLATERESULT=`cmk register template ostypeid=$OSTYPEID url="http://templates.cs.amito.com/systemVM/amito-systemvm-4.11-20190221170858-deploy.sh" zoneid=-1 name="amito-systemvm-4.11-20190221170858" displaytext="amito-systemvm-4.11-20190221170858" format=VHD passwordenabled=false hypervisor=XenServer ispublic=false isfeatured=false requireshvm=`
TEMPLATEID=`echo "$TEMPLATERESULT" | jq -r '.template[0].id'`
cmk update configuration name=router.template.xenserver value=amito-systemvm-4.11-20190221170858 

echo "$TEMPLATERESULT" | jq '.'

echo
echo "When finished, run the following on the DB server for this CloudStack instance"
echo "UPDATE vm_template SET type = 'SYSTEM' WHERE uuid = '$TEMPLATEID' AND type = 'USER';"
