Add item builder in it_v1

This commit is contained in:
MatMoul 2024-04-28 01:08:11 +02:00
parent 30519a4d24
commit 679669b36f
3 changed files with 79 additions and 0 deletions

View File

@ -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

View File

@ -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}"

View File

@ -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' ]