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

View File

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