From 679669b36f775b3325493ca6e34bf161e2f22a91 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Sun, 28 Apr 2024 01:08:11 +0200 Subject: [PATCH] Add item builder in it_v1 --- samples/it_v1/item_builder/gen.sh | 57 ++++++++++++++++++++++++++++ samples/it_v1/item_builder/item.sh | 12 ++++++ samples/it_v1/item_builder/item.yaml | 10 +++++ 3 files changed, 79 insertions(+) create mode 100755 samples/it_v1/item_builder/gen.sh create mode 100644 samples/it_v1/item_builder/item.sh create mode 100644 samples/it_v1/item_builder/item.yaml diff --git a/samples/it_v1/item_builder/gen.sh b/samples/it_v1/item_builder/gen.sh new file mode 100755 index 0000000..d7cc8c4 --- /dev/null +++ b/samples/it_v1/item_builder/gen.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +help() { + echo "gen.sh template script numstart numend [numsize=1]" +} + +if [ "${1}" == "-h" ] || [ "${1}" == "--help" ]; then + help + exit 0 +fi +if [ ${#} -lt 4 ] || [ ${#} -gt 5 ]; then + echo "Arguments count error" + echo "" + help + exit 1 +fi + +declare -r MODEL=${1} +declare -r SCRIPT=${2} +declare -r NUMSTART=${3} +declare -r NUMEND=${4} +declare NUMSIZE=${5} + +if [ "${NUMSTART}" -gt "${NUMEND}" ]; then + echo "NUMSTART is greather than NUMEND" + echo "" + help + exit 1 +fi + +if [ ! -f "${MODEL}" ]; then + echo "Model file not found" + echo "" + help + exit 1 +fi + +if [ ! -f "${SCRIPT}" ]; then + echo "Script file not found" + echo "" + help + exit 1 +fi + +if [ "${NUMSIZE}" == "" ]; then + NUMSIZE=1 +fi + +for ((i=NUMSTART;i<=NUMEND;i++)); do + NUM=${i} + while [ "${#NUM}" -lt "${NUMSIZE}" ]; do + NUM=0"${NUM}" + done + cp "${MODEL}" "${MODEL/.yaml/-${NUM}.yaml}" + sed -i "/^name:/c\name: '${MODEL/.yaml/-${NUM}}'" "${MODEL/.yaml/-${NUM}.yaml}" + bash "${SCRIPT}" "${MODEL/.yaml/-${NUM}.yaml}" "${NUMSTART}" "${NUMEND}" "${NUM}" +done diff --git a/samples/it_v1/item_builder/item.sh b/samples/it_v1/item_builder/item.sh new file mode 100644 index 0000000..f49f1b4 --- /dev/null +++ b/samples/it_v1/item_builder/item.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +declare -r FILE=${1} +declare -r NUMSTART=${2} +declare -r NUMEND=${3} +declare -r NUM=${4} +declare -r NUMDIFF=$((NUMSTART + NUM - NUMSTART)) + +# Custom code +# sed -i "/^name:/c\name: 'crazy-${NUM}'" "${FILE}" +IP=$((230 + NUMDIFF)) +sed -i s/YY/${IP}/ "${FILE}" diff --git a/samples/it_v1/item_builder/item.yaml b/samples/it_v1/item_builder/item.yaml new file mode 100644 index 0000000..6874122 --- /dev/null +++ b/samples/it_v1/item_builder/item.yaml @@ -0,0 +1,10 @@ +name: '' +maintainer: '' +model: 'Item' +location: 'Wall' +interfaces: + - name: 'LAN' + ip: '10.10.10.YY' + mask: '255.255.255.0' + gw: '10.10.10.1' + dns: [ '10.10.10.1' ]