[type/__interface_ifcfg] Error if expected environment variables are not set

This commit is contained in:
Dennis Camera 2020-08-31 14:16:07 +02:00
parent 718a068d10
commit 34d62aed95

View file

@ -27,13 +27,13 @@ prefix2subnet() {
python3 -c 'for addr in __import__("sys").argv[1:]: print(__import__("ipaddress").ip_network(addr, strict=False).netmask)' "$@" python3 -c 'for addr in __import__("sys").argv[1:]: print(__import__("ipaddress").ip_network(addr, strict=False).netmask)' "$@"
} }
param2var() { param2var() {
echo "${1:?'param name missing'}" | tr '[:lower:]' '[:upper:]' | tr '-' '_' echo "${1:?'param name missing'}" | tr '[:lower:]-' '[:upper:]_'
} }
ipversion() { ipversion() {
python3 -c 'for addr in __import__("sys").argv[1:]: print(__import__("ipaddress").ip_address(addr).version)' "$@" python3 -c 'for addr in __import__("sys").argv[1:]: print(__import__("ipaddress").ip_address(addr).version)' "$@"
} }
os=$(cat "${__global}/explorer/os") os=$(cat "${__global:?}/explorer/os")
case $os case $os
in in
@ -52,17 +52,17 @@ in
;; ;;
esac esac
if test -s "${__object}/parameter/name" if test -s "${__object:?}/parameter/name"
then then
name=$(cat "${__object}/parameter/name") name=$(cat "${__object:?}/parameter/name")
else else
name=$__object_id name=${__object_id:?}
fi fi
state_should=$(cat "${__object}/parameter/state") state_should=$(cat "${__object:?}/parameter/state")
bootproto=$(cat "${__object}/parameter/bootproto") bootproto=$(cat "${__object:?}/parameter/bootproto")
onchange=$(cat "${__object}/parameter/onchange") onchange=$(cat "${__object:?}/parameter/onchange")
ifcfg_file="${NETWORK_SCRIPTS_DIR:?}/ifcfg-${__object_id}" ifcfg_file="${NETWORK_SCRIPTS_DIR:?}/ifcfg-${__object_id:?}"
onchange_action() { onchange_action() {
@ -96,9 +96,9 @@ onchange_action() {
EOF EOF
if test -f "$__object/parameter/comment" if test -f "${__object:?}/parameter/comment"
then then
awk '{ print "# " $0 }' <"$__object/parameter/comment" awk '{ print "# " $0 }' <"${__object:?}/parameter/comment"
echo echo
fi fi
@ -118,11 +118,11 @@ onchange_action() {
(suse) (suse)
_startmode=manual _startmode=manual
if test -f "${__object}/parameter/onboot" if test -f "${__object:?}/parameter/onboot"
then then
_startmode=auto _startmode=auto
fi fi
if test -f "${__object}/parameter/hotplug" if test -f "${__object:?}/parameter/hotplug"
then then
_startmode=ifplugd _startmode=ifplugd
fi fi
@ -154,7 +154,7 @@ onchange_action() {
_bonding_opts= _bonding_opts=
for _param in "${__object}"/parameter/* for _param in "${__object:?}"/parameter/*
do do
_key=$(param2var "${_param}") _key=$(param2var "${_param}")
@ -165,11 +165,11 @@ onchange_action() {
in in
(bond-master) (bond-master)
opt_format SLAVE yes opt_format SLAVE yes
opt_format MASTER "$(cat "${__object}/parameter/${_param}")" opt_format MASTER "$(cat "${__object:?}/parameter/${_param}")"
;; ;;
(bond-*) (bond-*)
_key=$(echo "${_param#bond-}" | tr '-' '_') _key=$(echo "${_param#bond-}" | tr '-' '_')
_value=$(cat "${__object}/parameter/${_param}") _value=$(cat "${__object:?}/parameter/${_param}")
if test "${_key}" = 'arp_ip_target' if test "${_key}" = 'arp_ip_target'
then then
@ -220,11 +220,11 @@ onchange_action() {
: $((n+=1)) : $((n+=1))
done done
;; ;;
esac <"${__object}/parameter/address" esac <"${__object:?}/parameter/address"
unset n _addr unset n _addr
;; ;;
(*) (*)
opt_format "${_key}" "$(cat "${__object}/parameter/${_param}")" opt_format "${_key}" "$(cat "${__object:?}/parameter/${_param}")"
;; ;;
esac esac
;; ;;
@ -237,9 +237,9 @@ onchange_action() {
opt_format BONDING_OPTS "${_bonding_opts# }" opt_format BONDING_OPTS "${_bonding_opts# }"
fi fi
if test -f "${__object}/parameter/extra-config" if test -f "${__object:?}/parameter/extra-config"
then then
cat "${__object}/parameter/extra-config" cat "${__object:?}/parameter/extra-config"
fi fi
} | __file "${ifcfg_file}" \ } | __file "${ifcfg_file}" \
--state "${state_should}" --owner root --group root --mode 0644 \ --state "${state_should}" --owner root --group root --mode 0644 \