diff --git a/changeInterface.awk b/changeInterface.awk index b50e480..51abcdb 100644 --- a/changeInterface.awk +++ b/changeInterface.awk @@ -15,7 +15,7 @@ function writeStatic(addr, nw, nm, gw) { function usage() { print "awk -f changeInterfaces.awk device= \n" \ " [address=] [gateway=] [netmask=]\n" \ - " [network=] [mode=dhcp|static] [arg=debug]" + " [network=] [mode=dhcp|static] [debug]" } BEGIN { start = 0; @@ -26,6 +26,13 @@ BEGIN { start = 0; } for (i = 2; i < ARGC; i++) { + + if (ARGV[i] == "debug") { + debug = 1; + delete ARGV[i]; + continue; + } + split(ARGV[i], pair, "="); if (pair[1] == "address") address = pair[2]; @@ -37,8 +44,6 @@ BEGIN { start = 0; netmask = pair[2]; else if (pair[1] == "device") device = pair[2]; - else if (pair[1] == "arg" && pair[2] == "debug") - debug = 1; else if (pair[1] == "mode" && pair[2] == "dhcp") dhcp = 1; else if (pair[1] == "mode" && pair[2] == "static") diff --git a/readInterfaces.awk b/readInterfaces.awk index 3124762..abb1e8e 100644 --- a/readInterfaces.awk +++ b/readInterfaces.awk @@ -6,10 +6,13 @@ BEGIN { start = 0; } for (i = 2; i < ARGC; i++) { - if (ARGV[i] == debug) { + + if (ARGV[i] == "debug") { debug = 1; + delete ARGV[i]; continue; } + split(ARGV[i], arg, "="); if (arg[1] == "device") device = arg[2]; @@ -52,13 +55,24 @@ BEGIN { start = 0; } } + if ($1 == "auto") { + static = 0; + next; + } + + # Skip comment and blank lines + if ($0 ~ /^#/ || + $0 ~ /^[ \t]*$/ ) { + next; + } + # At here, it means we are after the iface static line of # after the device we are searching for # Scan for the static content if (static) { if (debug) - print "static - ", $0, $1; + print $0 if ($1 == "address") { address = $2;