Comment 3 for bug 948217

Revision history for this message
Steve Langasek (vorlon) wrote :

+ lines=`ifquery $i | grep -v metric | sed 's/://' | sed 's/ /[[:space:]]*/'`
+ sed -i -e "s/\(^iface.*$i.*dhcp\)/#NetworkManager#\1/" $NIF_FILE
+ for line in $lines; do
+ sed -i -e "s/^\([[:space:]]*$line\)/#NetworkManager#\1/" $NIF_FILE
+ done

This relies on two assumptions that may not hold true:

 - that the only occurrence of the line in the file is for the interface which is being disabled
 - that the contents of the line work in a sed command - i.e., they contain no special characters, including '/', '$', '*'...

I think it would be better to do a single sed command that detects the start and end of the stanza and applies the s/// to all lines in it. E.g.:

  sed -i -e"/^[[:space:]]*iface[[:space:]]\+$i[[:space:]]\+.*dhcp/,/^[[:space:]]*\(iface\|auto\|mapping\|source\|allow-\)/ { /^[[:space:]]*iface[[:space:]]\+$i[[:space:]]\+.*dhcp/ s/^/#NetworkManager#//; /^[[:space:]]*\(iface\|auto\|mapping\|source\|allow-\) ! s/^/#NetworkManager#//; }" /etc/network/interfaces

(Can probably be done more elegantly with awk than with sed)