[type/__interface] Error if expected environment variables are unset

This commit is contained in:
Dennis Camera 2020-08-26 15:52:13 +02:00
parent 3f3680db3a
commit ed59547448
5 changed files with 80 additions and 80 deletions

View file

@ -27,31 +27,31 @@ opt_from_param() {
# Only first line will be read. # Only first line will be read.
opt_format \ opt_format \
"${1:?'option name missing'}" \ "${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 # Boolean flags
if test -f "${__object}/parameter/onboot" if test -f "${__object:?}/parameter/onboot"
then then
set -- "$@" --onboot set -- "$@" --onboot
fi fi
if test -f "${__object}/parameter/hotplug" if test -f "${__object:?}/parameter/hotplug"
then then
set -- "$@" --hotplug set -- "$@" --hotplug
fi fi
if test -f "${__object}/parameter/name" if test -f "${__object:?}/parameter/name"
then then
set -- "$@" --name "$(cat "${__object}/parameter/name")" set -- "$@" --name "$(cat "${__object:?}/parameter/name")"
fi fi
# Generate appropriate parameters based on bootproto # Generate appropriate parameters based on bootproto
bootproto=$(cat "${__object}/parameter/bootproto") bootproto=$(cat "${__object:?}/parameter/bootproto")
case $bootproto case $bootproto
in in
(dhcp) (dhcp)
@ -60,16 +60,16 @@ in
(static) (static)
set -- "$@" --bootproto static set -- "$@" --bootproto static
if test -s "${__object}/parameter/address" if test -s "${__object:?}/parameter/address"
then then
while read -r _addr while read -r _addr
do do
set -- "$@" --address "${_addr}" set -- "$@" --address "${_addr}"
done <"${__object}/parameter/address" done <"${__object:?}/parameter/address"
unset _addr unset _addr
fi fi
if test -s "${__object}/parameter/gateway" if test -s "${__object:?}/parameter/gateway"
then then
set -- "$@" --option "$(opt_from_param GATEWAY gateway)" set -- "$@" --option "$(opt_from_param GATEWAY gateway)"
fi fi
@ -82,24 +82,24 @@ in
;; ;;
esac esac
if test -s "${__object}/parameter/comment" if test -s "${__object:?}/parameter/comment"
then then
set -- "$@" --comment "$(cat "${__object}/parameter/comment")" set -- "$@" --comment "$(cat "${__object:?}/parameter/comment")"
fi fi
if test -s "${__object}/parameter/onchange" if test -s "${__object:?}/parameter/onchange"
then then
set -- "$@" --onchange "$(cat "${__object}/parameter/onchange")" set -- "$@" --onchange "$(cat "${__object:?}/parameter/onchange")"
fi fi
if test -s "${__object}/parameter/extra-config" if test -s "${__object:?}/parameter/extra-config"
then then
while read -r _opt while read -r _opt
do do
set -- "$@" --option "${_opt}" set -- "$@" --option "${_opt}"
done <"${__object}/parameter/extra-config" done <"${__object:?}/parameter/extra-config"
unset _opt unset _opt
fi fi
# Instantiate backend type # Instantiate backend type
__interface_ifcfg "${__object_id}" "$@" __interface_ifcfg "${__object_id:?}" "$@"

View file

@ -27,31 +27,31 @@ opt_from_param() {
# Only first line will be read. # Only first line will be read.
opt_format \ opt_format \
"${1:?'option name missing'}" \ "${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 # Boolean flags
if test -f "${__object}/parameter/onboot" if test -f "${__object:?}/parameter/onboot"
then then
set -- "$@" --auto set -- "$@" --auto
fi fi
if test -f "${__object}/parameter/hotplug" if test -f "${__object:?}/parameter/hotplug"
then then
set -- "$@" --hotplug set -- "$@" --hotplug
fi fi
if test -f "${__object}/parameter/name" if test -f "${__object:?}/parameter/name"
then then
set -- "$@" --name "$(cat "${__object}/parameter/name")" set -- "$@" --name "$(cat "${__object:?}/parameter/name")"
fi fi
# Generate appropriate parameters based on bootproto # Generate appropriate parameters based on bootproto
bootproto=$(cat "${__object}/parameter/bootproto") bootproto=$(cat "${__object:?}/parameter/bootproto")
case $bootproto case $bootproto
in in
(dhcp) (dhcp)
@ -60,16 +60,16 @@ in
(static) (static)
set -- "$@" --method static set -- "$@" --method static
if test -s "${__object}/parameter/address" if test -s "${__object:?}/parameter/address"
then then
while read -r _value while read -r _value
do do
set -- "$@" --option "$(opt_format address "${_value}")" set -- "$@" --option "$(opt_format address "${_value}")"
done <"${__object}/parameter/address" done <"${__object:?}/parameter/address"
unset _value unset _value
fi fi
if test -s "${__object}/parameter/gateway" if test -s "${__object:?}/parameter/gateway"
then then
set -- "$@" --option "$(opt_from_param gateway gateway)" set -- "$@" --option "$(opt_from_param gateway gateway)"
fi fi
@ -82,22 +82,22 @@ in
;; ;;
esac esac
if test -s "${__object}/parameter/comment" if test -s "${__object:?}/parameter/comment"
then then
set -- "$@" --comment "$(cat "${__object}/parameter/comment")" set -- "$@" --comment "$(cat "${__object:?}/parameter/comment")"
fi fi
if test -s "${__object}/parameter/onchange" if test -s "${__object:?}/parameter/onchange"
then then
set -- "$@" --onchange "$(cat "${__object}/parameter/onchange")" set -- "$@" --onchange "$(cat "${__object:?}/parameter/onchange")"
fi fi
if test -s "${__object}/parameter/extra-config" if test -s "${__object:?}/parameter/extra-config"
then then
while read -r _opt while read -r _opt
do do
set -- "$@" --option "${_opt}" set -- "$@" --option "${_opt}"
done <"${__object}/parameter/extra-config" done <"${__object:?}/parameter/extra-config"
unset _opt unset _opt
fi fi
@ -106,4 +106,4 @@ if test -s "${__object:?}/stdin"
then then
exec <"${__object:?}/stdin" exec <"${__object:?}/stdin"
fi fi
__interface_ifupdown.d "${__object_id}" "$@" __interface_ifupdown.d "${__object_id:?}" "$@"

View file

@ -27,29 +27,29 @@ opt_from_param() {
# Only first line will be read. # Only first line will be read.
opt_format \ opt_format \
"${1:?'option name missing'}" \ "${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 # Boolean flags
test -f "${__object}/parameter/onboot" || { test -f "${__object:?}/parameter/onboot" || {
echo "WARNING: ${__type##*/}: The systemd backend only supports --onboot." >&2 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 echo "WARNING: ${__type##*/}: The systemd backend only supports --hotplug." >&2
} }
if test -f "${__object}/parameter/name" if test -f "${__object:?}/parameter/name"
then then
set -- "$@" --name "$(cat "${__object}/parameter/name")" set -- "$@" --name "$(cat "${__object:?}/parameter/name")"
fi fi
# Generate appropriate parameters based on bootproto # Generate appropriate parameters based on bootproto
bootproto=$(cat "${__object}/parameter/bootproto") bootproto=$(cat "${__object:?}/parameter/bootproto")
case $bootproto case $bootproto
in in
(dhcp*) (dhcp*)
@ -64,16 +64,16 @@ in
(static) (static)
set -- "$@" --option 'Network.DHCP=false' set -- "$@" --option 'Network.DHCP=false'
if test -s "${__object}/parameter/address" if test -s "${__object:?}/parameter/address"
then then
while read -r _value while read -r _value
do do
set -- "$@" --option "$(opt_format Network.Address "${_value}")" set -- "$@" --option "$(opt_format Network.Address "${_value}")"
done <"${__object}/parameter/address" done <"${__object:?}/parameter/address"
unset _value unset _value
fi fi
if test -s "${__object}/parameter/gateway" if test -s "${__object:?}/parameter/gateway"
then then
set -- "$@" --option "$(opt_from_param Network.Gateway gateway)" set -- "$@" --option "$(opt_from_param Network.Gateway gateway)"
fi fi
@ -86,12 +86,12 @@ in
;; ;;
esac esac
if test -s "${__object}/parameter/comment" if test -s "${__object:?}/parameter/comment"
then then
set -- "$@" --option "$(opt_from_param Network.Description comment)" set -- "$@" --option "$(opt_from_param Network.Description comment)"
fi fi
case $(cat "${__object}/parameter/onchange") case $(cat "${__object:?}/parameter/onchange")
in in
(leave) (leave)
;; ;;
@ -104,14 +104,14 @@ in
exit 1 exit 1
esac esac
if test -s "${__object}/parameter/extra-config" if test -s "${__object:?}/parameter/extra-config"
then then
while read -r _opt while read -r _opt
do do
set -- "$@" --option "${_opt}" set -- "$@" --option "${_opt}"
done <"${__object}/parameter/extra-config" done <"${__object:?}/parameter/extra-config"
unset _opt unset _opt
fi fi
# Instantiate backend type # Instantiate backend type
__systemd_networkd_network "${__object_id}" "$@" __systemd_networkd_network "${__object_id:?}" "$@"

View file

@ -27,27 +27,27 @@ opt_from_param() {
# Only first line will be read. # Only first line will be read.
opt_format \ opt_format \
"${1:?'option name missing'}" \ "${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") onchange_action=$(cat "${__object:?}/parameter/onchange")
state=$(cat "${__object}/parameter/state") state=$(cat "${__object:?}/parameter/state")
obj_name="network.${__object_id}" obj_name="network.${__object_id:?}"
onchange_action() { onchange_action() {
case $onchange_action case $onchange_action
in in
(refresh) (refresh)
printf "ifup '%s'\n" "${__object_id}" printf "ifup '%s'\n" "${__object_id:?}"
;; ;;
(up) (up)
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo 'isifup()(up=0; . /usr/share/libubox/jshn.sh && json_load "$(ifstatus "$1")" && json_get_var up up; return $((!up)))' 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) (down)
printf "ifdown '%s'\n" "${__object_id}" printf "ifdown '%s'\n" "${__object_id:?}"
;; ;;
(leave) (leave)
# ignore # ignore
@ -62,25 +62,25 @@ onchange_action() {
set -- --state "${state}" --transaction "${obj_name}" set -- --state "${state}" --transaction "${obj_name}"
if test -s "${__object}/parameter/comment" if test -s "${__object:?}/parameter/comment"
then then
set -- "$@" --option "$(opt_from_param _comment comment)" set -- "$@" --option "$(opt_from_param _comment comment)"
fi fi
if test -f "${__object}/parameter/name" if test -f "${__object:?}/parameter/name"
then then
set -- "$@" --option "$(opt_from_param ifname name)" set -- "$@" --option "$(opt_from_param ifname name)"
else else
set -- "$@" --option "$(opt_format ifname "${__object_id}")" set -- "$@" --option "$(opt_format ifname "${__object_id:?}")"
fi fi
set -- "$@" --option "$(opt_format auto "$( set -- "$@" --option "$(opt_format auto "$(
! test -f "${__object}/parameter/onboot"; echo $?)")" ! test -f "${__object:?}/parameter/onboot"; echo $?)")"
set -- "$@" --option "$(opt_format force_link "$( set -- "$@" --option "$(opt_format force_link "$(
test -f "${__object}/parameter/hotplug"; echo $?)")" test -f "${__object:?}/parameter/hotplug"; echo $?)")"
# Generate appropriate parameters based on bootproto # Generate appropriate parameters based on bootproto
bootproto=$(cat "${__object}/parameter/bootproto") bootproto=$(cat "${__object:?}/parameter/bootproto")
case $bootproto case $bootproto
in in
(dhcp) (dhcp)
@ -89,16 +89,16 @@ in
(static) (static)
set -- "$@" --option "$(opt_format proto static)" set -- "$@" --option "$(opt_format proto static)"
if test -s "${__object}/parameter/address" if test -s "${__object:?}/parameter/address"
then then
while read -r _value while read -r _value
do do
set -- "$@" --option "$(opt_format ipaddr "${_value}")" set -- "$@" --option "$(opt_format ipaddr "${_value}")"
done <"${__object}/parameter/address" done <"${__object:?}/parameter/address"
unset _value unset _value
fi fi
if test -s "${__object}/parameter/gateway" if test -s "${__object:?}/parameter/gateway"
then then
set -- "$@" --option "$(opt_from_param gateway gateway)" set -- "$@" --option "$(opt_from_param gateway gateway)"
fi fi
@ -111,22 +111,22 @@ in
;; ;;
esac esac
if test -s "${__object}/parameter/extra-config" if test -s "${__object:?}/parameter/extra-config"
then then
while read -r _opt while read -r _opt
do do
set -- "$@" --option "${_opt}" set -- "$@" --option "${_opt}"
done <"${__object}/parameter/extra-config" done <"${__object:?}/parameter/extra-config"
unset _opt unset _opt
fi fi
# Instantiate backend type # Instantiate backend type
__uci_section "${obj_name}" --type network.interface "$@" __uci_section "${obj_name}" --type network.interface "$@"
if test -s "${__object}/parameter/onchange" if test -s "${__object:?}/parameter/onchange"
then then
require=__uci_commit/"${obj_name}" \ require=__uci_commit/"${obj_name}" \
__check_messages "interface_${__object_id}_onchange" \ __check_messages "interface_${__object_id:?}_onchange" \
--pattern "^__uci_commit/network.${__object_id}:" \ --pattern "^__uci_commit/network.${__object_id:?}:" \
--execute "$(onchange_action)" --execute "$(onchange_action)"
fi fi

View file

@ -28,17 +28,17 @@ invalid_param() { die "$@"; }
invalid_paramf() { dief "$@"; } invalid_paramf() { dief "$@"; }
os=$(cat "${__global}/explorer/os") os=$(cat "${__global:?}/explorer/os")
# Check parameters # Check parameters
bootproto=$(cat "${__object}/parameter/bootproto") bootproto=$(cat "${__object:?}/parameter/bootproto")
case $bootproto case $bootproto
in in
(dhcp) (dhcp)
# Check parameters # Check parameters
! test -f "${__object}/parameter/address" \ ! test -f "${__object:?}/parameter/address" \
|| invalid_param '--address is invalid for --bootproto dhcp' || 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' || invalid_param '--gateway is invalid for --bootproto dhcp'
;; ;;
(static) (static)
@ -52,15 +52,15 @@ in
;; ;;
esac esac
if test -f "${__object}/parameter/type" if test -f "${__object:?}/parameter/type"
then then
impl_type=$(cat "${__object}/parameter/type") impl_type=$(cat "${__object:?}/parameter/type")
else else
# Guess the type based on the operating system # Guess the type based on the operating system
case $os case $os
in in
(debian) (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 \ test "${os_major}" -ge 7 \
|| die 'Debian versions older than 7 (wheezy) are not supported' || die 'Debian versions older than 7 (wheezy) are not supported'
@ -76,18 +76,18 @@ else
impl_type=uci impl_type=uci
;; ;;
(*) (*)
if test -s "${__object}/explorer/has_networkctl" if test -s "${__object:?}/explorer/has_networkctl"
then then
impl_type=systemd impl_type=systemd
else else
die "Don't know how to manage interfaces on: ${os}" dief "Don't know how to manage interfaces on: %s\n" "${os}"
fi fi
;; ;;
esac esac
fi fi
# Hand over to backend-specific implementation # 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}" test -x "${manifest_file}" || dief 'Unknown type: %s\n' "${impl_type}"
# Run backend-specific script # Run backend-specific script