Add functions for filtered interfaces list
Add list_etcnet_iface_filtered() function. This function prints iface name if filter_func returns TRUE. Filter function will be called with an interface directory as first parameter and all additional parameters with which list_etcnet_iface_filtered() was called.
This commit is contained in:
parent
b8192ace2d
commit
88cdd0c475
@ -543,7 +543,37 @@ next_ppp()
|
||||
next_iface ppp 1
|
||||
}
|
||||
|
||||
### filter functions
|
||||
__filter_etcnet_iface_default()
|
||||
{
|
||||
local ifname="${1##*/}"
|
||||
[ -n "$ifname" -a "$ifname" != "lo" -a "$ifname" != "default" -a "$ifname" != "unknown" ]
|
||||
}
|
||||
|
||||
### list various interface types
|
||||
# list_etcnet_iface_filtered [ ifaces_dir [ filter_func [ filter_func params ... ]]]
|
||||
#
|
||||
# list_etcnet_iface_filtered() prints iface name if filter_func returns TRUE
|
||||
# filter_func will be called with an interface directory as first parameter and
|
||||
# all additional parameters with which list_etcnet_iface_filtered() was called
|
||||
list_etcnet_iface_filtered()
|
||||
{
|
||||
local dir="${1:-$etcnet_iface_dir}"
|
||||
local filter_func="${2:-__filter_etcnet_iface_default}"
|
||||
local i=
|
||||
|
||||
# Shift parameters for posterior filter_func call
|
||||
if [ $# -gt 2 ]; then
|
||||
shift 2
|
||||
else
|
||||
shift $#
|
||||
fi
|
||||
|
||||
for i in $(find "$dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null); do
|
||||
$filter_func "$i" $@ >/dev/null || continue
|
||||
echo "${i##*/}"
|
||||
done
|
||||
}
|
||||
|
||||
list_ppp()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user