mirror of
https://github.com/MatMoul/dokytree.git
synced 2024-12-23 08:06:11 +00:00
Add item builder in it_v1
This commit is contained in:
parent
30519a4d24
commit
679669b36f
57
samples/it_v1/item_builder/gen.sh
Executable file
57
samples/it_v1/item_builder/gen.sh
Executable 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
|
12
samples/it_v1/item_builder/item.sh
Normal file
12
samples/it_v1/item_builder/item.sh
Normal 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}"
|
10
samples/it_v1/item_builder/item.yaml
Normal file
10
samples/it_v1/item_builder/item.yaml
Normal 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' ]
|
Loading…
Reference in New Issue
Block a user