-
Notifications
You must be signed in to change notification settings - Fork 0
/
entitybuilder_fromFile
72 lines (56 loc) · 1.83 KB
/
entitybuilder_fromFile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# This is a wrapper for the entitybulder.
# It takes an input file with a list of devices and calls the entitybulder
# for each line. See example file for help
configfile="./entitybuilder_fromFile.conf"
justPrint=0
while getopts "c:f:jl" opt; do
case $opt in
c) configfile=$OPTARG
;;
f) listFile=$OPTARG
;;
j) justPrint=1
;;
l) listCreatedFilesOnly="-l"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
## Check for required options
[ ! -e "$configfile" ] && { echo "Configuration file not found: entitybuilder_fromFile.conf"; exit 1; }
source "$configfile"
[ ! -e "$progEntitybuilder" ] && { echo "Program not found: entitybuilder"; exit 1; }
[ ! -d "$habasepath" ] && { echo "Home Assistant base path not found"; exit 1; }
[ ! -e "$listFile" ] && { echo "-f file does not exist"; exit 1; }
linearray=
while read -r listFileLine; do
linearray=( ${linearray[@]} $listFileLine )
done <<<"$(egrep -v '(^#|^$)' $listFile)"
for line in ${linearray[@]}; do
# Handle command
lineplit=( ${line//,/ } )
rewriteCustomization=
if [[ "${lineplit[5]}" == "true" ]]; then
rewriteCustomization="-C"
fi
if [[ "$justPrint" == 1 ]]; then
echo bash $progEntitybuilder $listCreatedFilesOnly -p $habasepath -x ${lineplit[0]} -c ${lineplit[1]} -m ${lineplit[2]} -n ${lineplit[3]} -H ${lineplit[4]} $rewriteCustomization
else
bash $progEntitybuilder $listCreatedFilesOnly -p $habasepath \
-x ${lineplit[0]} -c ${lineplit[1]} -m ${lineplit[2]} -n ${lineplit[3]} \
-H ${lineplit[4]} $rewriteCustomization
if [ $? == 1 ]; then
echo "Generating failed: ${lineplit[0]} ${lineplit[2]}"
break
fi
fi
done