@@ -5,36 +5,36 @@ if [ ! $# -eq 1 ]; then
55 exit 1
66fi
77
8- if [ ! -d ./$1 ]; then
9- echo " Directory $1 not found, bailing out"
8+ if [ ! -d " ./${1} " ]; then
9+ echo " Directory ${1} not found, bailing out"
1010 exit 2
1111fi
1212
13- domain_objects=" ./$1 /core.domain_objects.xml"
13+ domain_objects=" ./${1} /core.domain_objects.xml"
1414
15- if [ ! -f ${domain_objects} ]; then
16- echo " Directory $1 has no domain_objects, unable to continue"
15+ if [ ! -f " ${domain_objects} " ]; then
16+ echo " Directory ${1} has no domain_objects, unable to continue"
1717 exit 3
1818fi
1919
20- modules=" ./$1 /core.modules.xml"
21- if [ ! -f ${modules} ]; then
20+ modules=" ./${1} /core.modules.xml"
21+ if [ ! -f " ${modules} " ]; then
2222 echo " Directory has no modules, only changing domain_objects"
2323 modules=" "
2424fi
2525
26- if [ ! $( grep " 0123456789AB" ${domain_objects} | wc -l ) -gt 0 ]; then
26+ if [ ! " $( grep -c " 0123456789AB" " ${domain_objects} " ) " -gt 0 ]; then
2727 echo " File domain_objects, has no unnumbered mac-placeholders, bailing out"
2828 exit 4
2929fi
3030
31- if [ $( grep -E " 012345670[A01]" ${domain_objects} | wc -l ) -gt 0 ]; then
31+ if [ " $( grep -c - E " 012345670[A01]" " ${domain_objects} " ) " -gt 0 ]; then
3232 echo " File domain_objects, already has numbered mac-placeholders, bailing out"
3333 echo " "
3434 echo " Checking for strays out of curtasy"
35- if [ $( grep -EB1 " 0123456789AB" ${domain_objects} ${modules} | wc -l ) -gt 1 ]; then
35+ if [ " $( grep -c - EB1 " 0123456789AB" " ${domain_objects} " " ${modules} " ) " -gt 1 ]; then
3636 echo " Strays detected: (dumping found items)"
37- grep -EB1 " 0123456789AB" ${domain_objects} ${modules}
37+ grep -EB1 " 0123456789AB" " ${domain_objects} " " ${modules} "
3838 fi
3939
4040
4545mac_coord=" 012345670101"
4646mac_node_pre=" 012345670A"
4747mac_lan=" 012345670001"
48- mac_wlan=" 012345670002"
48+ # mac_wlan="012345670002"
4949
5050# Scan domain_objects for mapping
5151echo " "
5252echo " Searching for Zigbee coordinator:"
53- coord=$( grep -EB1 " 0123456789AB" ${domain_objects} | grep -E " <zig_bee_coord" | cut -f 2 -d " '" )
54- coordcount=$( echo ${coord} | wc -l)
53+ coord=$( grep -EB1 " 0123456789AB" " ${domain_objects} " | grep -E " <zig_bee_coord" | cut -f 2 -d " '" )
54+ coordcount=$( echo " ${coord} " | wc -l)
5555
56- if [ ${coordcount} -gt 1 ]; then
56+ if [ " ${coordcount} " -gt 1 ]; then
5757 echo " More than 1 coordinator node found, bailing out"
5858 exit 99
5959fi
6060echo " - Found coordinator at ${coord} "
6161
6262echo " "
6363echo " Searching for Zigbee nodes:"
64- nodes=$( grep -EB1 " 0123456789AB" ${domain_objects} | grep -E " <zig_bee_node" | cut -f 2 -d " '" )
64+ nodes=$( grep -EB1 " 0123456789AB" " ${domain_objects} " | grep -E " <zig_bee_node" | cut -f 2 -d " '" )
6565nodecount=$( echo " ${nodes} " | wc -l)
6666
67- if [ ${nodecount} -gt 98 ]; then
67+ if [ " ${nodecount} " -gt 98 ]; then
6868 echo " More than 98 nodes found, bailing out (not handling hex-counting yet)"
6969 exit 98
7070fi
@@ -74,7 +74,8 @@ echo " - Found ${nodecount} nodes"
7474echo " "
7575echo " Changing coordinator!"
7676# Coordinator change
77- sed -i" .bck" ' /' ${coord} ' /{n;s#0123456789AB#' ${mac_coord} ' #;}' ${domain_objects} ${modules}
77+ # shellcheck disable=2086
78+ sed -i" .bck" ' /' ${coord} ' /{n;s#0123456789AB#' ${mac_coord} ' #;}' " ${domain_objects} " " ${modules} "
7879
7980echo " "
8081echo " Changing nodes!"
@@ -86,23 +87,27 @@ for node_id in ${nodes}; do
8687 if [ ${counter} -lt 10 ]; then
8788 counter=" 0${counter} "
8889 fi
89- sed -i" .bck" ' /' ${node_id} ' /{n;s#0123456789AB#' ${mac_node_pre}${counter} ' #;}' ${domain_objects} ${modules}
90+ # shellcheck disable=2086
91+ sed -i" .bck" ' /' ${node_id} ' /{n;s#0123456789AB#' ${mac_node_pre}${counter} ' #;}' " ${domain_objects} " " ${modules} "
9092done
9193
9294echo " "
9395echo " Checking for leftover macs (except expected gateway mac)"
94- if [ $( grep " 0123456789AB" ${domain_objects} | wc -l ) -gt 1 ]; then
96+ if [ " $( grep -c " 0123456789AB" " ${domain_objects} " ) " -gt 1 ]; then
9597 echo " Unable to change gateway mac for ${domain_objects} => do this manually"
9698else
9799 echo " Modifying main network address (assuming LAN)"
98- sed -i" .bck" ' s#0123456789AB#' ${mac_lan} ' #' ${domain_objects}
100+ sed -i" .bck" ' s#0123456789AB#' ${mac_lan} ' #' " ${domain_objects} "
99101fi
100102
101103echo " "
102104echo " Checking for strays"
103- if [ $( grep -EB1 " 0123456789AB" ${domain_objects} ${modules} | wc -l) -gt 1 ]; then
105+ domaincount=$( grep -c -EB1 " 0123456789AB" " ${domain_objects} " )
106+ modulecount=$( grep -c -EB1 " 0123456789AB" " ${modules} " )
107+ totalcount=$(( domaincount+ modulecount))
108+ if [ " ${totalcount} " -gt 1 ]; then
104109 echo " Strays detected: (dumping found items)"
105- grep -EB1 " 0123456789AB" ${domain_objects} ${modules}
110+ grep -EB1 " 0123456789AB" " ${domain_objects} " " ${modules} "
106111else
107112 echo " All ok"
108113fi
0 commit comments