modulecmd: check availability of a module reviewed

Entries in the system- and blocklist can now use glob pattern.
The blocklist is now checked before the system list.
This commit is contained in:
2023-11-17 15:47:02 +01:00
parent adbceb602f
commit 693c38b3b0
+30 -8
View File
@@ -352,17 +352,39 @@ is_available(){
- the blocklist is empty or the hostname is NOT in the list
"
local -n ref_cfg="$1"
local -- rel_stages="$2"
local -- relstages="$2"
local -- system="$3"
local -- hostname="$4"
[[ ":${rel_stages}:" =~ ":${ref_cfg['rel_stage']}:" ]] || return 1
if [[ "${ref_cfg['systems']}" != "" ]]; then
[[ "${ref_cfg['systems']//$'\n'/:}:" =~ "${system}" ]] || return 1
fi
if [[ "${ref_cfg['blocklist']}" != "" ]]; then
[[ "${ref_cfg['blocklist']//$'\n'/:}:" =~ "${hostname}" ]] && return 1
fi
check_relstage(){
[[ ":${relstages}:" =~ ":${ref_cfg['relstage']}:" ]]
}
check_blocklist(){
[[ -z ${ref_cfg['blocklist']} ]] && return 0
local -- s=''
for s in ${ref_cfg['blocklist']}; do
if [[ "${system}" == $s ]] || [[ "${HOSTNAME}" == $s ]]; then
return 0
fi
done
return 1
}
check_systems(){
[[ -z ${ref_cfg['systems']} ]] && return 0
local -- s=''
for s in ${ref_cfg['systems']}; do
if [[ "${system}" == $s ]] || [[ "${HOSTNAME}" == $s ]]; then
return 0
fi
done
return 1
}
set -o noglob
check_relstage && check_blocklist && check_systems
local -i ec=$?
set +o noglob
return ${ec}
}
#