Skip to content

Commit

Permalink
Fix shellcheck issues in hosts-yaml-to-aaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
okurz committed Apr 22, 2024
1 parent 8c06e9a commit d64e563
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ all:
.PHONY: test
test: checkstyle test-unit

# for now no tests anymore in test/ after retry moved to github.com/okurz/retry
.PHONY: test-unit
test-unit: test-more-bash
prove -r test/
# prove -r test/

test-more-bash:
git clone https://github.com/ingydotnet/test-more-bash.git --depth 1 -b 0.0.5
Expand All @@ -19,4 +20,4 @@ test-shellcheck:
@which shellcheck >/dev/null 2>&1 || echo "Command 'shellcheck' not found, can not execute shell script checks"
# many files report errors so far hence only including a fixed list so far
#shellcheck -x $$(file --mime-type * | sed -n 's/^\(.*\):.*text\/x-shellscript.*$$/\1/p')
#shellcheck -x count-fail-ratio ## moved to https://github.com/okurz/retry
shellcheck -x hosts-yaml-to-aaaa
16 changes: 8 additions & 8 deletions hosts-yaml-to-aaaa
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Options:
-o, --offline Output also host entries for hosts that are
offline or do not respond to a ping request.
-p <path>, --path <path> set different <path> to a hosts.yaml file,
by default '$path'
by default '$default_path'
-P <P>, --prefix <P> IPv6 address prefix, default '$default_prefix'
-u, --unique Output no already existing AAAA records if found
in <dns_path>.
Expand Down Expand Up @@ -59,25 +59,25 @@ while true; do
esac
done

path="${path:-${1:-$default_prefix}}"
base=$(basename $(dirname $path))
path="${path:-${1:-$default_path}}"
base="$(basename "$(dirname "$path")")"
domain="${base//_/.}"
default_dns_path="salt/profile/dns/files/${base#*_}/dns-$domain"
dns_path="${dns_path:-$default_dns_path}"

export prefix

yq -r 'to_entries[] | [.key, .value.mac] | @tsv' $path | while read -r host mac; do
ip=$(mac-to-ipv6 $mac)
yq -r 'to_entries[] | [.key, .value.mac] | @tsv' "$path" | while read -r host mac; do
ip=$(mac-to-ipv6 "$mac")
ip=${ip,,}
if [ "$unique" = "true" ]; then
grep -q $ip $dns_path && continue
grep -q "$ip" "$dns_path" && continue
fi
if [ "$offline" != "true" ]; then
ping -q -c1 $ip >/dev/null || continue
ping -q -c1 "$ip" >/dev/null || continue
fi
if [ "$reverse" = "true" ]; then
sipcalc -r $ip | sed -n "s/ip6\.arpa\./& 14400 PTR $host.$domain./p"
sipcalc -r "$ip" | sed -n "s/ip6\.arpa\./& 14400 PTR $host.$domain./p"
continue
else
echo "$host AAAA $ip"
Expand Down

0 comments on commit d64e563

Please sign in to comment.