- Replace awk parts with shell.
Approved by: brooks MFC after: 2 weeks
This commit is contained in:
parent
bc02a9764c
commit
4442f896de
@ -40,17 +40,29 @@ convert_host_conf()
|
|||||||
{
|
{
|
||||||
host_conf=$1; shift;
|
host_conf=$1; shift;
|
||||||
nsswitch_conf=$1; shift;
|
nsswitch_conf=$1; shift;
|
||||||
awk ' \
|
|
||||||
/^[:blank:]*#/ { next } \
|
while read line; do
|
||||||
/(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
|
line=${line##[ ]}
|
||||||
/(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
|
case $line in
|
||||||
/nis/ { nsswitch[c] = "nis"; c++; next } \
|
hosts|local|file)
|
||||||
{ printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
|
_nsswitch="${_nsswitch}${_nsswitch+ }files"
|
||||||
END { \
|
;;
|
||||||
printf "hosts: "; \
|
dns|bind)
|
||||||
for (i in nsswitch) printf "%s ", nsswitch[i]; \
|
_nsswitch="${_nsswitch}${_nsswitch+ }dns"
|
||||||
printf "\n"; \
|
;;
|
||||||
}' < $host_conf > $nsswitch_conf
|
nis)
|
||||||
|
_nsswitch="${_nsswitch}${_nsswitch+ }nis"
|
||||||
|
;;
|
||||||
|
'#'*)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "Warning: unrecognized line [%s]", $line > "/dev/stderr"
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
done < $host_conf
|
||||||
|
|
||||||
|
echo "hosts: $_nsswitch" > $nsswitch_conf
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_nsswitch_conf()
|
generate_nsswitch_conf()
|
||||||
@ -73,30 +85,47 @@ generate_host_conf()
|
|||||||
nsswitch_conf=$1; shift;
|
nsswitch_conf=$1; shift;
|
||||||
host_conf=$1; shift;
|
host_conf=$1; shift;
|
||||||
|
|
||||||
awk '
|
_cont=0
|
||||||
BEGIN {
|
_sources=""
|
||||||
xlat["files"] = "hosts";
|
while read line; do
|
||||||
xlat["dns"] = "bind";
|
line=${line##[ ]}
|
||||||
xlat["nis"] = "nis";
|
case $line in
|
||||||
cont = 0;
|
hosts:*)
|
||||||
}
|
;;
|
||||||
sub(/^[\t ]*hosts:/, "") || cont {
|
*)
|
||||||
if (!cont)
|
if [ $_cont -ne 1 ]; then
|
||||||
srcs = ""
|
continue
|
||||||
sub(/#.*/, "")
|
fi
|
||||||
gsub(/[][]/, " & ")
|
;;
|
||||||
cont = sub(/\\$/, "")
|
esac
|
||||||
srcs = srcs " " $0
|
if [ "${line%\\}" = "${line}\\" ]; then
|
||||||
}
|
_cont=1
|
||||||
END {
|
fi
|
||||||
print "# Auto-generated from nsswitch.conf, do not edit"
|
line=${line#hosts:}
|
||||||
ns = split(srcs, s)
|
line=${line%\\}
|
||||||
for (n = 1; n <= ns; ++n) {
|
line=${line%%#*}
|
||||||
if (s[n] in xlat)
|
_sources="${_sources}${_sources:+ }$line"
|
||||||
print xlat[s[n]]
|
done < $nsswitch_conf
|
||||||
}
|
|
||||||
}
|
echo "# Auto-generated from nsswitch.conf, do not edit" > $host_conf
|
||||||
' <$nsswitch_conf >$host_conf
|
for _s in ${_sources}; do
|
||||||
|
case $_s in
|
||||||
|
files)
|
||||||
|
echo "hosts" >> $host_conf
|
||||||
|
;;
|
||||||
|
dns)
|
||||||
|
echo "dns" >> $host_conf
|
||||||
|
;;
|
||||||
|
nis)
|
||||||
|
echo "nis" >> $host_conf
|
||||||
|
;;
|
||||||
|
*=*)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "Warning: unrecognized source [%s]", $_s > "/dev/stderr"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
nsswitch_start()
|
nsswitch_start()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user