dnsmasq: init: get rid of test -a and test -o

Refer to shellcheck SC2166.  There are just too many caveats that are
shell-dependent on test -a and test -o to use them.

Signed-off-by: Henrique de Moraes Holschuh <henrique@nic.br>
This commit is contained in:
Henrique de Moraes Holschuh 2020-02-29 23:31:45 -03:00 committed by Hans Dedecker
parent dd166960f4
commit f81403c433

View File

@ -207,7 +207,7 @@ filter_dnsmasq() {
# use entry when no instance entry set, or if it matches # use entry when no instance entry set, or if it matches
config_get found_cfg "$cfg" "instance" config_get found_cfg "$cfg" "instance"
if [ -z "$found_cfg" -o "$found_cfg" = "$match_cfg" ]; then if [ -z "$found_cfg" ] || [ "$found_cfg" = "$match_cfg" ]; then
$func $cfg $func $cfg
fi fi
} }
@ -326,10 +326,10 @@ dhcp_host_add() {
config_get ip "$cfg" ip config_get ip "$cfg" ip
config_get hostid "$cfg" hostid config_get hostid "$cfg" hostid
[ -n "$ip" -o -n "$name" -o -n "$hostid" ] || return 0 [ -z "$ip" ] && [ -z "$name" ] && [ -z "$hostid" ] && return 0
config_get_bool dns "$cfg" dns 0 config_get_bool dns "$cfg" dns 0
[ "$dns" = "1" -a -n "$ip" -a -n "$name" ] && { [ "$dns" = "1" ] && [ -n "$ip" ] && [ -n "$name" ] && {
echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE_TMP echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE_TMP
} }
@ -343,13 +343,13 @@ dhcp_host_add() {
for m in $mac; do append macs "$m" ","; done for m in $mac; do append macs "$m" ","; done
fi fi
if [ $DNSMASQ_DHCP_VER -eq 6 -a -n "$duid" ]; then if [ $DNSMASQ_DHCP_VER -eq 6 ] && [ -n "$duid" ]; then
# --dhcp-host=id:00:03:00:01:12:00:00:01:02:03,[::beef],lap # --dhcp-host=id:00:03:00:01:12:00:00:01:02:03,[::beef],lap
# one (virtual) machine gets one DUID per RFC3315 # one (virtual) machine gets one DUID per RFC3315
duids="id:${duid// */}" duids="id:${duid// */}"
fi fi
if [ -z "$macs" -a -z "$duids" ]; then if [ -z "$macs" ] && [ -z "$duids" ]; then
# --dhcp-host=lap,192.168.0.199,[::beef] # --dhcp-host=lap,192.168.0.199,[::beef]
[ -n "$name" ] || return 0 [ -n "$name" ] || return 0
macs="$name" macs="$name"
@ -416,7 +416,7 @@ dhcp_this_host_add() {
dhcp_domain_add "" "$routername" "$lanaddr" dhcp_domain_add "" "$routername" "$lanaddr"
fi fi
if [ -n "$ulaprefix" -a -n "$lanaddrs6" ] ; then if [ -n "$ulaprefix" ] && [ -n "$lanaddrs6" ] ; then
for lanaddr6 in $lanaddrs6 ; do for lanaddr6 in $lanaddrs6 ; do
case "$lanaddr6" in case "$lanaddr6" in
"${ulaprefix%%:/*}"*) "${ulaprefix%%:/*}"*)
@ -472,7 +472,7 @@ dhcp_boot_add() {
config_get servername "$cfg" servername config_get servername "$cfg" servername
config_get serveraddress "$cfg" serveraddress config_get serveraddress "$cfg" serveraddress
[ -n "$serveraddress" -a ! -n "$servername" ] && return 0 [ -n "$serveraddress" ] && [ ! -n "$servername" ] && return 0
xappend "--dhcp-boot=${networkid:+net:$networkid,}${filename}${servername:+,$servername}${serveraddress:+,$serveraddress}" xappend "--dhcp-boot=${networkid:+net:$networkid,}${filename}${servername:+,$servername}${serveraddress:+,$serveraddress}"
@ -566,7 +566,7 @@ dhcp_add() {
fi fi
if [ $DNSMASQ_DHCP_VER -eq 6 -a "$ra" = "server" ] ; then if [ $DNSMASQ_DHCP_VER -eq 6 ] && [ "$ra" = "server" ] ; then
# Note: dnsmasq cannot just be a DHCPv6 server (all-in-1) # Note: dnsmasq cannot just be a DHCPv6 server (all-in-1)
# and let some other machine(s) send RA pointing to it. # and let some other machine(s) send RA pointing to it.
@ -805,13 +805,13 @@ dnsmasq_start()
$PROG --version | grep -osqE "^Compile time options:.* DHCPv6( |$)" && DHCPv6CAPABLE=1 || DHCPv6CAPABLE=0 $PROG --version | grep -osqE "^Compile time options:.* DHCPv6( |$)" && DHCPv6CAPABLE=1 || DHCPv6CAPABLE=0
if [ -x /usr/sbin/odhcpd -a -x /etc/init.d/odhcpd ] ; then if [ -x /usr/sbin/odhcpd ] && [ -x /etc/init.d/odhcpd ] ; then
local odhcpd_is_main odhcpd_is_enabled local odhcpd_is_main odhcpd_is_enabled
config_get odhcpd_is_main odhcpd maindhcp 0 config_get odhcpd_is_main odhcpd maindhcp 0
/etc/init.d/odhcpd enabled && odhcpd_is_enabled=1 || odhcpd_is_enabled=0 /etc/init.d/odhcpd enabled && odhcpd_is_enabled=1 || odhcpd_is_enabled=0
if [ "$odhcpd_is_enabled" -eq 0 -a "$DHCPv6CAPABLE" -eq 1 ] ; then if [ "$odhcpd_is_enabled" -eq 0 ] && [ "$DHCPv6CAPABLE" -eq 1 ] ; then
# DHCP V4 and V6 in DNSMASQ # DHCP V4 and V6 in DNSMASQ
DNSMASQ_DHCP_VER=6 DNSMASQ_DHCP_VER=6
elif [ "$odhcpd_is_main" -gt 0 ] ; then elif [ "$odhcpd_is_main" -gt 0 ] ; then
@ -834,7 +834,7 @@ dnsmasq_start()
if [ -x /etc/init.d/dhcpd ] ; then if [ -x /etc/init.d/dhcpd ] ; then
/etc/init.d/dhcpd enabled && DNSMASQ_DHCP_VER=0 /etc/init.d/dhcpd enabled && DNSMASQ_DHCP_VER=0
fi fi
if [ -x /etc/init.d/dhcpd6 -a "$DNSMASQ_DHCP_VER" -gt 0 ] ; then if [ -x /etc/init.d/dhcpd6 ] && [ "$DNSMASQ_DHCP_VER" -gt 0 ] ; then
/etc/init.d/dhcpd6 enabled && DNSMASQ_DHCP_VER=4 /etc/init.d/dhcpd6 enabled && DNSMASQ_DHCP_VER=4
fi fi
fi fi
@ -920,13 +920,13 @@ dnsmasq_start()
fi fi
config_get leasefile $cfg leasefile "/tmp/dhcp.leases" config_get leasefile $cfg leasefile "/tmp/dhcp.leases"
[ -n "$leasefile" -a \! -e "$leasefile" ] && touch "$leasefile" [ -n "$leasefile" ] && [ ! -e "$leasefile" ] && touch "$leasefile"
config_get_bool cachelocal "$cfg" cachelocal 1 config_get_bool cachelocal "$cfg" cachelocal 1
config_get_bool noresolv "$cfg" noresolv 0 config_get_bool noresolv "$cfg" noresolv 0
if [ "$noresolv" != "1" ]; then if [ "$noresolv" != "1" ]; then
config_get resolvfile "$cfg" resolvfile /tmp/resolv.conf.d/resolv.conf.auto config_get resolvfile "$cfg" resolvfile /tmp/resolv.conf.d/resolv.conf.auto
[ -n "$resolvfile" -a ! -e "$resolvfile" ] && touch "$resolvfile" [ -n "$resolvfile" ] && [ ! -e "$resolvfile" ] && touch "$resolvfile"
xappend "--resolv-file=$resolvfile" xappend "--resolv-file=$resolvfile"
[ "$resolvfile" = "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=1 [ "$resolvfile" = "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=1
resolvdir="$(dirname "$resolvfile")" resolvdir="$(dirname "$resolvfile")"
@ -1087,7 +1087,7 @@ dnsmasq_stop()
config_get_bool noresolv "$cfg" noresolv 0 config_get_bool noresolv "$cfg" noresolv 0
config_get resolvfile "$cfg" "resolvfile" config_get resolvfile "$cfg" "resolvfile"
[ "$noresolv" = 0 -a "$resolvfile" = "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=1 [ "$noresolv" = 0 ] && [ "$resolvfile" = "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=1
config_get_bool localuse "$cfg" localuse "$localuse" config_get_bool localuse "$cfg" localuse "$localuse"
[ "$localuse" -gt 0 ] && ln -sf "/tmp/resolv.conf.d/resolv.conf.auto" /tmp/resolv.conf [ "$localuse" -gt 0 ] && ln -sf "/tmp/resolv.conf.d/resolv.conf.auto" /tmp/resolv.conf
@ -1101,7 +1101,7 @@ add_interface_trigger()
config_get interface "$1" interface config_get interface "$1" interface
config_get_bool ignore "$1" ignore 0 config_get_bool ignore "$1" ignore 0
[ -n "$interface" -a $ignore -eq 0 ] && procd_add_interface_trigger "interface.*" "$interface" /etc/init.d/dnsmasq reload [ -n "$interface" ] && [ $ignore -eq 0 ] && procd_add_interface_trigger "interface.*" "$interface" /etc/init.d/dnsmasq reload
} }
service_triggers() service_triggers()
@ -1129,7 +1129,7 @@ start_service() {
local type="$1" local type="$1"
local name="$2" local name="$2"
if [ "$type" = "dnsmasq" ]; then if [ "$type" = "dnsmasq" ]; then
if [ -n "$instance" -a "$instance" = "$name" ]; then if [ -n "$instance" ] && [ "$instance" = "$name" ]; then
instance_found=1 instance_found=1
fi fi
fi fi
@ -1158,7 +1158,7 @@ stop_service() {
local type="$1" local type="$1"
local name="$2" local name="$2"
if [ "$type" = "dnsmasq" ]; then if [ "$type" = "dnsmasq" ]; then
if [ -n "$instance" -a "$instance" = "$name" ]; then if [ -n "$instance" ] && [ "$instance" = "$name" ]; then
instance_found=1 instance_found=1
fi fi
fi fi