Skip to content

Commit 6d00d28

Browse files
committed
Shellcheck applied - renumbered adam_multiple (with no changes :P)
1 parent cb3ebdb commit 6d00d28

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

userdata/renumber.sh

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@ if [ ! $# -eq 1 ]; then
55
exit 1
66
fi
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
1111
fi
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
1818
fi
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=""
2424
fi
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
2929
fi
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

@@ -45,26 +45,26 @@ fi
4545
mac_coord="012345670101"
4646
mac_node_pre="012345670A"
4747
mac_lan="012345670001"
48-
mac_wlan="012345670002"
48+
#mac_wlan="012345670002"
4949

5050
# Scan domain_objects for mapping
5151
echo ""
5252
echo "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
5959
fi
6060
echo " - Found coordinator at ${coord}"
6161

6262
echo ""
6363
echo "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 "'")
6565
nodecount=$(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
7070
fi
@@ -74,7 +74,8 @@ echo " - Found ${nodecount} nodes"
7474
echo ""
7575
echo "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

7980
echo ""
8081
echo "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}"
9092
done
9193

9294
echo ""
9395
echo "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"
9698
else
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}"
99101
fi
100102

101103
echo ""
102104
echo "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}"
106111
else
107112
echo "All ok"
108113
fi

0 commit comments

Comments
 (0)