From ed5954744852015ad17e20b59e852d672acbd00d Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Wed, 26 Aug 2020 15:52:13 +0200 Subject: [PATCH] [type/__interface] Error if expected environment variables are unset --- .../__interface/files/backends/ifcfg/manifest | 34 +++++++-------- .../files/backends/ifupdown.d/manifest | 34 +++++++-------- .../files/backends/systemd/manifest | 30 ++++++------- .../__interface/files/backends/uci/manifest | 42 +++++++++---------- cdist/conf/type/__interface/manifest | 20 ++++----- 5 files changed, 80 insertions(+), 80 deletions(-) diff --git a/cdist/conf/type/__interface/files/backends/ifcfg/manifest b/cdist/conf/type/__interface/files/backends/ifcfg/manifest index 9d46b24f..a4b6dbdf 100755 --- a/cdist/conf/type/__interface/files/backends/ifcfg/manifest +++ b/cdist/conf/type/__interface/files/backends/ifcfg/manifest @@ -27,31 +27,31 @@ opt_from_param() { # Only first line will be read. opt_format \ "${1:?'option name missing'}" \ - "$(head -n 1 "${__object}/parameter/${2:?'parameter name missing'}")" + "$(head -n 1 "${__object:?}/parameter/${2:?'parameter name missing'}")" } -set -- --state "$(cat "${__object}/parameter/state")" --family inet +set -- --state "$(cat "${__object:?}/parameter/state")" --family inet # Boolean flags -if test -f "${__object}/parameter/onboot" +if test -f "${__object:?}/parameter/onboot" then set -- "$@" --onboot fi -if test -f "${__object}/parameter/hotplug" +if test -f "${__object:?}/parameter/hotplug" then set -- "$@" --hotplug fi -if test -f "${__object}/parameter/name" +if test -f "${__object:?}/parameter/name" then - set -- "$@" --name "$(cat "${__object}/parameter/name")" + set -- "$@" --name "$(cat "${__object:?}/parameter/name")" fi # Generate appropriate parameters based on bootproto -bootproto=$(cat "${__object}/parameter/bootproto") +bootproto=$(cat "${__object:?}/parameter/bootproto") case $bootproto in (dhcp) @@ -60,16 +60,16 @@ in (static) set -- "$@" --bootproto static - if test -s "${__object}/parameter/address" + if test -s "${__object:?}/parameter/address" then while read -r _addr do set -- "$@" --address "${_addr}" - done <"${__object}/parameter/address" + done <"${__object:?}/parameter/address" unset _addr fi - if test -s "${__object}/parameter/gateway" + if test -s "${__object:?}/parameter/gateway" then set -- "$@" --option "$(opt_from_param GATEWAY gateway)" fi @@ -82,24 +82,24 @@ in ;; esac -if test -s "${__object}/parameter/comment" +if test -s "${__object:?}/parameter/comment" then - set -- "$@" --comment "$(cat "${__object}/parameter/comment")" + set -- "$@" --comment "$(cat "${__object:?}/parameter/comment")" fi -if test -s "${__object}/parameter/onchange" +if test -s "${__object:?}/parameter/onchange" then - set -- "$@" --onchange "$(cat "${__object}/parameter/onchange")" + set -- "$@" --onchange "$(cat "${__object:?}/parameter/onchange")" fi -if test -s "${__object}/parameter/extra-config" +if test -s "${__object:?}/parameter/extra-config" then while read -r _opt do set -- "$@" --option "${_opt}" - done <"${__object}/parameter/extra-config" + done <"${__object:?}/parameter/extra-config" unset _opt fi # Instantiate backend type -__interface_ifcfg "${__object_id}" "$@" +__interface_ifcfg "${__object_id:?}" "$@" diff --git a/cdist/conf/type/__interface/files/backends/ifupdown.d/manifest b/cdist/conf/type/__interface/files/backends/ifupdown.d/manifest index 7a9b328b..bbdca8bb 100755 --- a/cdist/conf/type/__interface/files/backends/ifupdown.d/manifest +++ b/cdist/conf/type/__interface/files/backends/ifupdown.d/manifest @@ -27,31 +27,31 @@ opt_from_param() { # Only first line will be read. opt_format \ "${1:?'option name missing'}" \ - "$(head -n 1 "${__object}/parameter/${2:?'parameter name missing'}")" + "$(head -n 1 "${__object:?}/parameter/${2:?'parameter name missing'}")" } -set -- --state "$(cat "${__object}/parameter/state")" --family inet +set -- --state "$(cat "${__object:?}/parameter/state")" --family inet # Boolean flags -if test -f "${__object}/parameter/onboot" +if test -f "${__object:?}/parameter/onboot" then set -- "$@" --auto fi -if test -f "${__object}/parameter/hotplug" +if test -f "${__object:?}/parameter/hotplug" then set -- "$@" --hotplug fi -if test -f "${__object}/parameter/name" +if test -f "${__object:?}/parameter/name" then - set -- "$@" --name "$(cat "${__object}/parameter/name")" + set -- "$@" --name "$(cat "${__object:?}/parameter/name")" fi # Generate appropriate parameters based on bootproto -bootproto=$(cat "${__object}/parameter/bootproto") +bootproto=$(cat "${__object:?}/parameter/bootproto") case $bootproto in (dhcp) @@ -60,16 +60,16 @@ in (static) set -- "$@" --method static - if test -s "${__object}/parameter/address" + if test -s "${__object:?}/parameter/address" then while read -r _value do set -- "$@" --option "$(opt_format address "${_value}")" - done <"${__object}/parameter/address" + done <"${__object:?}/parameter/address" unset _value fi - if test -s "${__object}/parameter/gateway" + if test -s "${__object:?}/parameter/gateway" then set -- "$@" --option "$(opt_from_param gateway gateway)" fi @@ -82,22 +82,22 @@ in ;; esac -if test -s "${__object}/parameter/comment" +if test -s "${__object:?}/parameter/comment" then - set -- "$@" --comment "$(cat "${__object}/parameter/comment")" + set -- "$@" --comment "$(cat "${__object:?}/parameter/comment")" fi -if test -s "${__object}/parameter/onchange" +if test -s "${__object:?}/parameter/onchange" then - set -- "$@" --onchange "$(cat "${__object}/parameter/onchange")" + set -- "$@" --onchange "$(cat "${__object:?}/parameter/onchange")" fi -if test -s "${__object}/parameter/extra-config" +if test -s "${__object:?}/parameter/extra-config" then while read -r _opt do set -- "$@" --option "${_opt}" - done <"${__object}/parameter/extra-config" + done <"${__object:?}/parameter/extra-config" unset _opt fi @@ -106,4 +106,4 @@ if test -s "${__object:?}/stdin" then exec <"${__object:?}/stdin" fi -__interface_ifupdown.d "${__object_id}" "$@" +__interface_ifupdown.d "${__object_id:?}" "$@" diff --git a/cdist/conf/type/__interface/files/backends/systemd/manifest b/cdist/conf/type/__interface/files/backends/systemd/manifest index 9d404bcc..2e86ee4e 100755 --- a/cdist/conf/type/__interface/files/backends/systemd/manifest +++ b/cdist/conf/type/__interface/files/backends/systemd/manifest @@ -27,29 +27,29 @@ opt_from_param() { # Only first line will be read. opt_format \ "${1:?'option name missing'}" \ - "$(head -n 1 "${__object}/parameter/${2:?'parameter name missing'}")" + "$(head -n 1 "${__object:?}/parameter/${2:?'parameter name missing'}")" } -set -- --state "$(cat "${__object}/parameter/state")" +set -- --state "$(cat "${__object:?}/parameter/state")" # Boolean flags -test -f "${__object}/parameter/onboot" || { +test -f "${__object:?}/parameter/onboot" || { echo "WARNING: ${__type##*/}: The systemd backend only supports --onboot." >&2 } -test -f "${__object}/parameter/hotplug" || { +test -f "${__object:?}/parameter/hotplug" || { echo "WARNING: ${__type##*/}: The systemd backend only supports --hotplug." >&2 } -if test -f "${__object}/parameter/name" +if test -f "${__object:?}/parameter/name" then - set -- "$@" --name "$(cat "${__object}/parameter/name")" + set -- "$@" --name "$(cat "${__object:?}/parameter/name")" fi # Generate appropriate parameters based on bootproto -bootproto=$(cat "${__object}/parameter/bootproto") +bootproto=$(cat "${__object:?}/parameter/bootproto") case $bootproto in (dhcp*) @@ -64,16 +64,16 @@ in (static) set -- "$@" --option 'Network.DHCP=false' - if test -s "${__object}/parameter/address" + if test -s "${__object:?}/parameter/address" then while read -r _value do set -- "$@" --option "$(opt_format Network.Address "${_value}")" - done <"${__object}/parameter/address" + done <"${__object:?}/parameter/address" unset _value fi - if test -s "${__object}/parameter/gateway" + if test -s "${__object:?}/parameter/gateway" then set -- "$@" --option "$(opt_from_param Network.Gateway gateway)" fi @@ -86,12 +86,12 @@ in ;; esac -if test -s "${__object}/parameter/comment" +if test -s "${__object:?}/parameter/comment" then set -- "$@" --option "$(opt_from_param Network.Description comment)" fi -case $(cat "${__object}/parameter/onchange") +case $(cat "${__object:?}/parameter/onchange") in (leave) ;; @@ -104,14 +104,14 @@ in exit 1 esac -if test -s "${__object}/parameter/extra-config" +if test -s "${__object:?}/parameter/extra-config" then while read -r _opt do set -- "$@" --option "${_opt}" - done <"${__object}/parameter/extra-config" + done <"${__object:?}/parameter/extra-config" unset _opt fi # Instantiate backend type -__systemd_networkd_network "${__object_id}" "$@" +__systemd_networkd_network "${__object_id:?}" "$@" diff --git a/cdist/conf/type/__interface/files/backends/uci/manifest b/cdist/conf/type/__interface/files/backends/uci/manifest index 8c812638..21c1bd7e 100755 --- a/cdist/conf/type/__interface/files/backends/uci/manifest +++ b/cdist/conf/type/__interface/files/backends/uci/manifest @@ -27,27 +27,27 @@ opt_from_param() { # Only first line will be read. opt_format \ "${1:?'option name missing'}" \ - "$(head -n 1 "${__object}/parameter/${2:?'parameter name missing'}")" + "$(head -n 1 "${__object:?}/parameter/${2:?'parameter name missing'}")" } -onchange_action=$(cat "${__object}/parameter/onchange") -state=$(cat "${__object}/parameter/state") +onchange_action=$(cat "${__object:?}/parameter/onchange") +state=$(cat "${__object:?}/parameter/state") -obj_name="network.${__object_id}" +obj_name="network.${__object_id:?}" onchange_action() { case $onchange_action in (refresh) - printf "ifup '%s'\n" "${__object_id}" + printf "ifup '%s'\n" "${__object_id:?}" ;; (up) # shellcheck disable=SC2016 echo 'isifup()(up=0; . /usr/share/libubox/jshn.sh && json_load "$(ifstatus "$1")" && json_get_var up up; return $((!up)))' - printf "isifup '%s' || ifup '%s'\n" "${__object_id}" "${__object_id}" + printf "isifup '%s' || ifup '%s'\n" "${__object_id:?}" "${__object_id:?}" ;; (down) - printf "ifdown '%s'\n" "${__object_id}" + printf "ifdown '%s'\n" "${__object_id:?}" ;; (leave) # ignore @@ -62,25 +62,25 @@ onchange_action() { set -- --state "${state}" --transaction "${obj_name}" -if test -s "${__object}/parameter/comment" +if test -s "${__object:?}/parameter/comment" then set -- "$@" --option "$(opt_from_param _comment comment)" fi -if test -f "${__object}/parameter/name" +if test -f "${__object:?}/parameter/name" then set -- "$@" --option "$(opt_from_param ifname name)" else - set -- "$@" --option "$(opt_format ifname "${__object_id}")" + set -- "$@" --option "$(opt_format ifname "${__object_id:?}")" fi set -- "$@" --option "$(opt_format auto "$( - ! test -f "${__object}/parameter/onboot"; echo $?)")" + ! test -f "${__object:?}/parameter/onboot"; echo $?)")" set -- "$@" --option "$(opt_format force_link "$( - test -f "${__object}/parameter/hotplug"; echo $?)")" + test -f "${__object:?}/parameter/hotplug"; echo $?)")" # Generate appropriate parameters based on bootproto -bootproto=$(cat "${__object}/parameter/bootproto") +bootproto=$(cat "${__object:?}/parameter/bootproto") case $bootproto in (dhcp) @@ -89,16 +89,16 @@ in (static) set -- "$@" --option "$(opt_format proto static)" - if test -s "${__object}/parameter/address" + if test -s "${__object:?}/parameter/address" then while read -r _value do set -- "$@" --option "$(opt_format ipaddr "${_value}")" - done <"${__object}/parameter/address" + done <"${__object:?}/parameter/address" unset _value fi - if test -s "${__object}/parameter/gateway" + if test -s "${__object:?}/parameter/gateway" then set -- "$@" --option "$(opt_from_param gateway gateway)" fi @@ -111,22 +111,22 @@ in ;; esac -if test -s "${__object}/parameter/extra-config" +if test -s "${__object:?}/parameter/extra-config" then while read -r _opt do set -- "$@" --option "${_opt}" - done <"${__object}/parameter/extra-config" + done <"${__object:?}/parameter/extra-config" unset _opt fi # Instantiate backend type __uci_section "${obj_name}" --type network.interface "$@" -if test -s "${__object}/parameter/onchange" +if test -s "${__object:?}/parameter/onchange" then require=__uci_commit/"${obj_name}" \ - __check_messages "interface_${__object_id}_onchange" \ - --pattern "^__uci_commit/network.${__object_id}:" \ + __check_messages "interface_${__object_id:?}_onchange" \ + --pattern "^__uci_commit/network.${__object_id:?}:" \ --execute "$(onchange_action)" fi diff --git a/cdist/conf/type/__interface/manifest b/cdist/conf/type/__interface/manifest index 6cf71bb3..73727a2a 100755 --- a/cdist/conf/type/__interface/manifest +++ b/cdist/conf/type/__interface/manifest @@ -28,17 +28,17 @@ invalid_param() { die "$@"; } invalid_paramf() { dief "$@"; } -os=$(cat "${__global}/explorer/os") +os=$(cat "${__global:?}/explorer/os") # Check parameters -bootproto=$(cat "${__object}/parameter/bootproto") +bootproto=$(cat "${__object:?}/parameter/bootproto") case $bootproto in (dhcp) # Check parameters - ! test -f "${__object}/parameter/address" \ + ! test -f "${__object:?}/parameter/address" \ || invalid_param '--address is invalid for --bootproto dhcp' - ! test -f "${__object}/parameter/gateway" \ + ! test -f "${__object:?}/parameter/gateway" \ || invalid_param '--gateway is invalid for --bootproto dhcp' ;; (static) @@ -52,15 +52,15 @@ in ;; esac -if test -f "${__object}/parameter/type" +if test -f "${__object:?}/parameter/type" then - impl_type=$(cat "${__object}/parameter/type") + impl_type=$(cat "${__object:?}/parameter/type") else # Guess the type based on the operating system case $os in (debian) - os_major=$(grep -o '^[0-9][0-9]*' "${__global}/explorer/os_version") + os_major=$(grep -o '^[0-9][0-9]*' "${__global:?}/explorer/os_version") test "${os_major}" -ge 7 \ || die 'Debian versions older than 7 (wheezy) are not supported' @@ -76,18 +76,18 @@ else impl_type=uci ;; (*) - if test -s "${__object}/explorer/has_networkctl" + if test -s "${__object:?}/explorer/has_networkctl" then impl_type=systemd else - die "Don't know how to manage interfaces on: ${os}" + dief "Don't know how to manage interfaces on: %s\n" "${os}" fi ;; esac fi # Hand over to backend-specific implementation -manifest_file="${__type}/files/backends/${impl_type}/manifest" +manifest_file="${__type:?}/files/backends/${impl_type}/manifest" test -x "${manifest_file}" || dief 'Unknown type: %s\n' "${impl_type}" # Run backend-specific script