#!/usr/bin/bash
#
# Backup virtual system
# Copyright (C) 2019-2024 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact: dreibh@simula.no

# Bash options:
set -e


# ###### Main program #######################################################
if [ $# -lt 2 ] ; then
   echo >&2 "Usage: $0 precedence vsystem1 [...]"
   exit 1
fi

PRECEDENCE="$1"
if [[ ! "$PRECEDENCE" =~ ^[0-9][0-9]$ ]] ; then
   echo >&2 "ERROR: Precedence must be a two-digit number from 00 to 99!"
   exit 1
fi
shift

while [ "$1" != "" ] ; do
   VM_NAME="$1"
   TEMPLATE="$PRECEDENCE-$VM_NAME"

   echo "Creating template $TEMPLATE"
   (
      echo "NAME=\"$VM_NAME"\"
      echo "STARTDELAY=10"
      echo "STOPDELAY=30"
      echo "NUMCPUS=1"
      echo "OPTIONS=\"default\""
      echo "# AUTO_UPDATE_BOOTCD=\"default\""
   ) >"$TEMPLATE"

   shift
done
