On Mon, Jul 03, 2017 at 10:47:31PM +0000, Robert Peichaer wrote:
Dokument explicitely possible outputs and tweak the sed expressions
to remove the superfluous whitespaces. I guess that does the trick.

Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1019
diff -u -p -p -u -r1.1019 install.sub
--- install.sub 2 Jul 2017 12:45:43 -0000       1.1019
+++ install.sub 3 Jul 2017 22:34:04 -0000
@@ -896,13 +896,16 @@ __EOT
}

# Obtain and output the inet information related to interface $1.
-# Should output '<UP/DOWN> <addr> <netmask> <rest of inet line>'.
+# Outputs one of:
+# <DOWN>
+# <UP>
+# <UP>\n<addr> <netmask> <rest of inet line>[\n<more addr lines>]
v4_info() {
        ifconfig $1 inet | sed -n '
                1s/.*<UP,.*/UP/p
                1s/.*<.*/DOWN/p
-               /inet/s/netmask//
-               /inet/s///p'
+               /inet/s/netmask //
+               /.inet /s///p'
}

# Convert a netmask in hex format ($1) to dotted decimal format.
@@ -981,14 +984,17 @@ v4_config() {
}

# Obtain and output the inet6 information related to interface $1.
-# Should output '<UP/DOWN> <addr> <prefixlen> <rest of inet line> '.
+# Outputs one of:
+# <DOWN>
+# <UP>
+# <UP>\n<addr> <prefixlen> <rest of inet6 line>[\n<more addr lines>]
v6_info() {
        ifconfig $1 inet6 | sed -n '
                1s/.*<UP,.*/UP/p
                1s/.*<.*/DOWN/p
                /scopeid/d
-               /inet6/s/prefixlen//
-               /inet6/s///p'
+               /inet6/s/prefixlen //
+               /.inet6 /s///p'
}

/.inet / is nicer than my [:space:] take, yes. Looking again at the
format now <UP> and <DOWN> seem slightly off since they're meant literal
in contrast to <addr> and the rest.

I still prefer the { } somehow but that's just a matter of taste here
I guess. How about this updated diff?

Feedback/OK?

Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1019
diff -u -p -r1.1019 install.sub
--- install.sub 2 Jul 2017 12:45:43 -0000       1.1019
+++ install.sub 3 Jul 2017 23:34:22 -0000
@@ -895,14 +895,16 @@ __EOT
        mv /etc/resolv.conf.tail /tmp/i/resolv.conf.tail
}

-# Obtain and output the inet information related to interface $1.
-# Should output '<UP/DOWN> <addr> <netmask> <rest of inet line>'.
+# Obtain and output the inet information related to interface $1 in the form
+# UP|DOWN
+# [<addr> <netmask> <rest of inet line>]
+# [more inet lines]
v4_info() {
        ifconfig $1 inet | sed -n '
-               1s/.*<UP,.*/UP/p
-               1s/.*<.*/DOWN/p
-               /inet/s/netmask//
-               /inet/s///p'
+               1{      s/.*<UP,.*/UP/p
+                       s/.*<.*/DOWN/p; }
+               /.inet /{s///
+                        s/netmask //p; }'
}

# Convert a netmask in hex format ($1) to dotted decimal format.
@@ -980,15 +982,17 @@ v4_config() {
        esac
}

-# Obtain and output the inet6 information related to interface $1.
-# Should output '<UP/DOWN> <addr> <prefixlen> <rest of inet line> '.
+# Obtain and output the inet6 information related to interface $1. in the form
+# UP|DOWN
+# [<addr> <prefixlen> <rest of inet6 line>]
+# [more inet6 lines]
v6_info() {
        ifconfig $1 inet6 | sed -n '
-               1s/.*<UP,.*/UP/p
-               1s/.*<.*/DOWN/p
-               /scopeid/d
-               /inet6/s/prefixlen//
-               /inet6/s///p'
+               1{      s/.*<UP,.*/UP/p
+                       s/.*<.*/DOWN/p; }
+               /.inet6 /{s///
+                         /scopeid/d
+                         s/prefixlen //p; }'
}

# Set up IPv6 default route on interface $1.

Reply via email to