summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorflz <flz@FreeBSD.org>2006-03-20 18:00:14 +0000
committerflz <flz@FreeBSD.org>2006-03-20 18:00:14 +0000
commitf6add5dd6c9322cbd6d96ddcb127da71079571d1 (patch)
tree79a99767ed0880cdd92615260016665f0170ee2a /etc
parent7c3f5f4c32ab4c34a93ea952b547edff82335156 (diff)
downloadFreeBSD-src-f6add5dd6c9322cbd6d96ddcb127da71079571d1.zip
FreeBSD-src-f6add5dd6c9322cbd6d96ddcb127da71079571d1.tar.gz
- Replace awk parts with shell.
Approved by: brooks MFC after: 2 weeks
Diffstat (limited to 'etc')
-rw-r--r--etc/rc.d/nsswitch99
1 files changed, 64 insertions, 35 deletions
diff --git a/etc/rc.d/nsswitch b/etc/rc.d/nsswitch
index 3ba233b..fc2ab6a 100644
--- a/etc/rc.d/nsswitch
+++ b/etc/rc.d/nsswitch
@@ -40,17 +40,29 @@ convert_host_conf()
{
host_conf=$1; shift;
nsswitch_conf=$1; shift;
- awk ' \
- /^[:blank:]*#/ { next } \
- /(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
- /(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
- /nis/ { nsswitch[c] = "nis"; c++; next } \
- { printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
- END { \
- printf "hosts: "; \
- for (i in nsswitch) printf "%s ", nsswitch[i]; \
- printf "\n"; \
- }' < $host_conf > $nsswitch_conf
+
+ while read line; do
+ line=${line##[ ]}
+ case $line in
+ hosts|local|file)
+ _nsswitch="${_nsswitch}${_nsswitch+ }files"
+ ;;
+ dns|bind)
+ _nsswitch="${_nsswitch}${_nsswitch+ }dns"
+ ;;
+ 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()
@@ -73,30 +85,47 @@ generate_host_conf()
nsswitch_conf=$1; shift;
host_conf=$1; shift;
- awk '
-BEGIN {
- xlat["files"] = "hosts";
- xlat["dns"] = "bind";
- xlat["nis"] = "nis";
- cont = 0;
-}
-sub(/^[\t ]*hosts:/, "") || cont {
- if (!cont)
- srcs = ""
- sub(/#.*/, "")
- gsub(/[][]/, " & ")
- cont = sub(/\\$/, "")
- srcs = srcs " " $0
-}
-END {
- print "# Auto-generated from nsswitch.conf, do not edit"
- ns = split(srcs, s)
- for (n = 1; n <= ns; ++n) {
- if (s[n] in xlat)
- print xlat[s[n]]
- }
-}
-' <$nsswitch_conf >$host_conf
+ _cont=0
+ _sources=""
+ while read line; do
+ line=${line##[ ]}
+ case $line in
+ hosts:*)
+ ;;
+ *)
+ if [ $_cont -ne 1 ]; then
+ continue
+ fi
+ ;;
+ esac
+ if [ "${line%\\}" = "${line}\\" ]; then
+ _cont=1
+ fi
+ line=${line#hosts:}
+ line=${line%\\}
+ line=${line%%#*}
+ _sources="${_sources}${_sources:+ }$line"
+ done < $nsswitch_conf
+
+ echo "# Auto-generated from nsswitch.conf, do not edit" > $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()
OpenPOWER on IntegriCloud