Update the nsswitch.conf -> host.conf generator to handle criteria,

continuation lines, extra whitespace, and to use the last matching
 line in the file.  This syncs the host.conf generation with how
 the nsswitch.conf is parsed.
Only print " host.conf" instead of a multi-line message, since this
 happens on every boot.
This commit is contained in:
Bill Fenner 2001-11-07 00:33:56 +00:00
parent 70982dca88
commit 85c9d676b5
7 changed files with 112 additions and 70 deletions

View File

@ -41,8 +41,7 @@ network_pass1() {
# Generate host.conf for compatibility # Generate host.conf for compatibility
# #
if [ -f "/etc/nsswitch.conf" ]; then if [ -f "/etc/nsswitch.conf" ]; then
echo '' echo -n ' host.conf'
echo 'Generating /etc/host.conf for compatibility'
generate_host_conf /etc/nsswitch.conf /etc/host.conf generate_host_conf /etc/nsswitch.conf /etc/host.conf
fi fi
@ -880,16 +879,23 @@ BEGIN {
xlat["files"] = "hosts"; xlat["files"] = "hosts";
xlat["dns"] = "bind"; xlat["dns"] = "bind";
xlat["nis"] = "nis"; xlat["nis"] = "nis";
cont = 0;
} }
/^hosts:/ { sub(/^[\t ]*hosts:/, "") || cont {
print "# Auto-generated, do not edit"; if (!cont)
for (n = 2; n <= NF; ++n) srcs = ""
if ($n in xlat) sub(/#.*/, "")
print xlat[$n]; gsub(/[][]/, " & ")
quit; cont = sub(/\\$/, "")
srcs = srcs " " $0
} }
// { END {
next; 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 ' <$nsswitch_conf >$host_conf
} }

View File

@ -41,8 +41,7 @@ network_pass1() {
# Generate host.conf for compatibility # Generate host.conf for compatibility
# #
if [ -f "/etc/nsswitch.conf" ]; then if [ -f "/etc/nsswitch.conf" ]; then
echo '' echo -n ' host.conf'
echo 'Generating /etc/host.conf for compatibility'
generate_host_conf /etc/nsswitch.conf /etc/host.conf generate_host_conf /etc/nsswitch.conf /etc/host.conf
fi fi
@ -880,16 +879,23 @@ BEGIN {
xlat["files"] = "hosts"; xlat["files"] = "hosts";
xlat["dns"] = "bind"; xlat["dns"] = "bind";
xlat["nis"] = "nis"; xlat["nis"] = "nis";
cont = 0;
} }
/^hosts:/ { sub(/^[\t ]*hosts:/, "") || cont {
print "# Auto-generated, do not edit"; if (!cont)
for (n = 2; n <= NF; ++n) srcs = ""
if ($n in xlat) sub(/#.*/, "")
print xlat[$n]; gsub(/[][]/, " & ")
quit; cont = sub(/\\$/, "")
srcs = srcs " " $0
} }
// { END {
next; 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 ' <$nsswitch_conf >$host_conf
} }

View File

@ -41,8 +41,7 @@ network_pass1() {
# Generate host.conf for compatibility # Generate host.conf for compatibility
# #
if [ -f "/etc/nsswitch.conf" ]; then if [ -f "/etc/nsswitch.conf" ]; then
echo '' echo -n ' host.conf'
echo 'Generating /etc/host.conf for compatibility'
generate_host_conf /etc/nsswitch.conf /etc/host.conf generate_host_conf /etc/nsswitch.conf /etc/host.conf
fi fi
@ -880,16 +879,23 @@ BEGIN {
xlat["files"] = "hosts"; xlat["files"] = "hosts";
xlat["dns"] = "bind"; xlat["dns"] = "bind";
xlat["nis"] = "nis"; xlat["nis"] = "nis";
cont = 0;
} }
/^hosts:/ { sub(/^[\t ]*hosts:/, "") || cont {
print "# Auto-generated, do not edit"; if (!cont)
for (n = 2; n <= NF; ++n) srcs = ""
if ($n in xlat) sub(/#.*/, "")
print xlat[$n]; gsub(/[][]/, " & ")
quit; cont = sub(/\\$/, "")
srcs = srcs " " $0
} }
// { END {
next; 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 ' <$nsswitch_conf >$host_conf
} }

View File

@ -41,8 +41,7 @@ network_pass1() {
# Generate host.conf for compatibility # Generate host.conf for compatibility
# #
if [ -f "/etc/nsswitch.conf" ]; then if [ -f "/etc/nsswitch.conf" ]; then
echo '' echo -n ' host.conf'
echo 'Generating /etc/host.conf for compatibility'
generate_host_conf /etc/nsswitch.conf /etc/host.conf generate_host_conf /etc/nsswitch.conf /etc/host.conf
fi fi
@ -880,16 +879,23 @@ BEGIN {
xlat["files"] = "hosts"; xlat["files"] = "hosts";
xlat["dns"] = "bind"; xlat["dns"] = "bind";
xlat["nis"] = "nis"; xlat["nis"] = "nis";
cont = 0;
} }
/^hosts:/ { sub(/^[\t ]*hosts:/, "") || cont {
print "# Auto-generated, do not edit"; if (!cont)
for (n = 2; n <= NF; ++n) srcs = ""
if ($n in xlat) sub(/#.*/, "")
print xlat[$n]; gsub(/[][]/, " & ")
quit; cont = sub(/\\$/, "")
srcs = srcs " " $0
} }
// { END {
next; 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 ' <$nsswitch_conf >$host_conf
} }

View File

@ -41,8 +41,7 @@ network_pass1() {
# Generate host.conf for compatibility # Generate host.conf for compatibility
# #
if [ -f "/etc/nsswitch.conf" ]; then if [ -f "/etc/nsswitch.conf" ]; then
echo '' echo -n ' host.conf'
echo 'Generating /etc/host.conf for compatibility'
generate_host_conf /etc/nsswitch.conf /etc/host.conf generate_host_conf /etc/nsswitch.conf /etc/host.conf
fi fi
@ -880,16 +879,23 @@ BEGIN {
xlat["files"] = "hosts"; xlat["files"] = "hosts";
xlat["dns"] = "bind"; xlat["dns"] = "bind";
xlat["nis"] = "nis"; xlat["nis"] = "nis";
cont = 0;
} }
/^hosts:/ { sub(/^[\t ]*hosts:/, "") || cont {
print "# Auto-generated, do not edit"; if (!cont)
for (n = 2; n <= NF; ++n) srcs = ""
if ($n in xlat) sub(/#.*/, "")
print xlat[$n]; gsub(/[][]/, " & ")
quit; cont = sub(/\\$/, "")
srcs = srcs " " $0
} }
// { END {
next; 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 ' <$nsswitch_conf >$host_conf
} }

View File

@ -41,8 +41,7 @@ network_pass1() {
# Generate host.conf for compatibility # Generate host.conf for compatibility
# #
if [ -f "/etc/nsswitch.conf" ]; then if [ -f "/etc/nsswitch.conf" ]; then
echo '' echo -n ' host.conf'
echo 'Generating /etc/host.conf for compatibility'
generate_host_conf /etc/nsswitch.conf /etc/host.conf generate_host_conf /etc/nsswitch.conf /etc/host.conf
fi fi
@ -880,16 +879,23 @@ BEGIN {
xlat["files"] = "hosts"; xlat["files"] = "hosts";
xlat["dns"] = "bind"; xlat["dns"] = "bind";
xlat["nis"] = "nis"; xlat["nis"] = "nis";
cont = 0;
} }
/^hosts:/ { sub(/^[\t ]*hosts:/, "") || cont {
print "# Auto-generated, do not edit"; if (!cont)
for (n = 2; n <= NF; ++n) srcs = ""
if ($n in xlat) sub(/#.*/, "")
print xlat[$n]; gsub(/[][]/, " & ")
quit; cont = sub(/\\$/, "")
srcs = srcs " " $0
} }
// { END {
next; 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 ' <$nsswitch_conf >$host_conf
} }

View File

@ -41,8 +41,7 @@ network_pass1() {
# Generate host.conf for compatibility # Generate host.conf for compatibility
# #
if [ -f "/etc/nsswitch.conf" ]; then if [ -f "/etc/nsswitch.conf" ]; then
echo '' echo -n ' host.conf'
echo 'Generating /etc/host.conf for compatibility'
generate_host_conf /etc/nsswitch.conf /etc/host.conf generate_host_conf /etc/nsswitch.conf /etc/host.conf
fi fi
@ -880,16 +879,23 @@ BEGIN {
xlat["files"] = "hosts"; xlat["files"] = "hosts";
xlat["dns"] = "bind"; xlat["dns"] = "bind";
xlat["nis"] = "nis"; xlat["nis"] = "nis";
cont = 0;
} }
/^hosts:/ { sub(/^[\t ]*hosts:/, "") || cont {
print "# Auto-generated, do not edit"; if (!cont)
for (n = 2; n <= NF; ++n) srcs = ""
if ($n in xlat) sub(/#.*/, "")
print xlat[$n]; gsub(/[][]/, " & ")
quit; cont = sub(/\\$/, "")
srcs = srcs " " $0
} }
// { END {
next; 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 ' <$nsswitch_conf >$host_conf
} }