Fix shellcheck issues

This commit is contained in:
Darko Poljak 2020-01-23 14:10:48 +01:00
parent f03299ebf3
commit a30b4e3619
2 changed files with 22 additions and 13 deletions

View File

@ -37,17 +37,20 @@ cat << DONE
DONE
if [ -f "$__object/parameter/comment" ]; then
cat "$__object/parameter/comment" | awk '{ print "# "$0 }'
awk '{ print "# "$0 }' < "$__object/parameter/comment"
fi
if [ -f "$__object/parameter/onboot" ]; then
# shellcheck disable=SC2154
printf "auto %s\n" "$name"
elif [ -f "$__object/parameter/hotplug" ]; then
# shellcheck disable=SC2154
printf "allow-hotplug %s\n" "$name"
fi
ignored_parameters="linkdelay"
manually_handled_parameters="name comment extra-config state method onboot hotplug nodns noroute no-network-wait-online symmetric-routing bond-slaves"
# shellcheck disable=SC2154
case "$method" in
dhcp)
printf "iface %s inet %s\n" "$name" "$method"
@ -62,7 +65,7 @@ case "$method" in
;;
esac
for param in $(ls "$__object/parameter/"); do
for param in "$__object"/parameter/*; do
if echo "$ignored_parameters" | grep -w -q "$param"; then
continue
fi
@ -71,14 +74,14 @@ for param in $(ls "$__object/parameter/"); do
fi
if [ -f "$type_files/name-map" ]; then
key="$(awk -v param=$param '{ if ($1 == param) {print $2;} else { print param;} }' "$type_files/name-map")"
key="$(awk -v param="$param" '{ if ($1 == param) {print $2;} else { print param;} }' "$type_files/name-map")"
else
key="$param"
fi
printf " %s %s\n" "$key" "$(cat "$__object/parameter/$param")"
done
if [ -f "$__object/parameter/bond-mode" -o -f "$__object/parameter/bond-primary" ]; then
if [ -f "$__object/parameter/bond-mode" ] || [ -f "$__object/parameter/bond-primary" ]; then
# Note: ifenslave is not needed when using ifupdown2
# install package required for bonding
__package ifenslave
@ -112,7 +115,8 @@ if [ -f "$__object/parameter/symmetric-routing" ]; then
printf ' symmetric-routing yes\n'
fi
if [ -n "$vlan" -a -n "$device" ]; then
# shellcheck disable=SC2154
if [ -n "$vlan" ] && [ -n "$device" ]; then
# Explicit parent interface for vlans
printf ' vlan-raw-device %s\n' "$device"
fi
@ -147,6 +151,7 @@ require="__directory/etc/network" \
--group root \
--mode 644
# shellcheck disable=SC2154
require="__file/etc/network/interfaces __directory/etc/network/interfaces.d" \
__file "/etc/network/interfaces.d/$interface_filename" \
--owner root \
@ -156,7 +161,7 @@ require="__file/etc/network/interfaces __directory/etc/network/interfaces.d" \
--state "$state"
if [ "$method" = "dhcp" -a -f "$__object/parameter/noroute" ]; then
if [ "$method" = "dhcp" ] && [ -f "$__object/parameter/noroute" ]; then
(
cat << DONE
# Created by cdist ${__type##*/}
@ -183,7 +188,7 @@ __file "/etc/dhcp/dhclient-enter-hooks.d/cdist-__network_interface-${name}-norou
--state "$state"
fi # end noroute
if [ "$method" = "dhcp" -a -f "$__object/parameter/nodns" ]; then
if [ "$method" = "dhcp" ] && [ -f "$__object/parameter/nodns" ]; then
(
cat << DONE
# Created by cdist ${__type##*/}

View File

@ -20,6 +20,7 @@
type_files="$__type/files/redhat"
mkdir "$__object/files"
# shellcheck disable=SC2154
interface_filename="ifcfg-${name}"
(
@ -31,7 +32,7 @@ cat << DONE
DONE
if [ -f "$__object/parameter/comment" ]; then
cat "$__object/parameter/comment" | awk '{ print "# "$0 }'
awk '{ print "# "$0 }' < "$__object/parameter/comment"
fi
printf 'DEVICE="%s"\n' "$name"
@ -72,6 +73,7 @@ fi
ignored_parameters=""
manually_handled_parameters="name comment extra-config state method onboot hotplug nodns noroute no-network-wait-online symmetric-routing"
# shellcheck disable=SC2154
case "$method" in
dhcp)
printf 'BOOTPROTO=dhcp\n'
@ -86,7 +88,7 @@ case "$method" in
;;
esac
for param in $(ls "$__object/parameter/"); do
for param in "$__object"/parameter/*; do
if echo "$ignored_parameters" | grep -w -q "$param"; then
continue
fi
@ -103,7 +105,7 @@ for param in $(ls "$__object/parameter/"); do
bond-*)
key="$(echo "${param#*bond-}" | tr - _)"
if [ "$param" = "bond-arp-ip-target" ]; then
value="$(cat "$__object/parameter/$param" | tr '\n' ,)"
value="$(tr '\n' , < "$__object/parameter/$param")"
# strip trailing comma
value="${value%,}"
else
@ -114,7 +116,7 @@ for param in $(ls "$__object/parameter/"); do
*)
# check for redhat specific name for this parameter
if [ -f "$type_files/name-map" ]; then
key="$(awk -v param=$param '{ if ($1 == param) {print $2;} else { print param;} }' "$type_files/name-map")"
key="$(awk -v param="$param" '{ if ($1 == param) {print $2;} else { print param;} }' "$type_files/name-map")"
else
key="$param"
fi
@ -125,13 +127,14 @@ for param in $(ls "$__object/parameter/"); do
esac
done
if [ -f "$__object/files/bonding_opts" ]; then
value="$(cat "$__object/files/bonding_opts" | tr '\n' ' ')"
value="$(tr '\n' ' ' < "$__object/files/bonding_opts")"
# strip trailing space
value="${value% }"
printf 'BONDING_OPTS="%s"\n' "$value"
fi
if [ -n "$vlan" -a -n "$device" ]; then
# shellcheck disable=SC2154
if [ -n "$vlan" ] && [ -n "$device" ]; then
# Enable vlan for this interface
printf 'VLAN=yes\n'
fi
@ -147,6 +150,7 @@ fi
) >> "$__object/files/$interface_filename"
# shellcheck disable=SC2154
__file "/etc/sysconfig/network-scripts/$interface_filename" \
--owner root \
--group root \