implémentation de network_interfaces_remove_iface[s]
This commit is contained in:
		
							parent
							
								
									ca2fabf6ca
								
							
						
					
					
						commit
						7c5d6e1125
					
				
							
								
								
									
										105
									
								
								ulib/debian
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								ulib/debian
									
									
									
									
									
								
							@ -508,7 +508,6 @@ $1 == "iface" {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
$1 ~ /^(allow-)?auto$/ {
 | 
					$1 ~ /^(allow-)?auto$/ {
 | 
				
			||||||
  for (i = 2; i <= NF; i++) {
 | 
					  for (i = 2; i <= NF; i++) {
 | 
				
			||||||
print "auto: " $i ", iface=" iface
 | 
					 | 
				
			||||||
    if ($i == iface) {
 | 
					    if ($i == iface) {
 | 
				
			||||||
      have_auto = 1
 | 
					      have_auto = 1
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -518,7 +517,6 @@ print "auto: " $i ", iface=" iface
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
$1 == "allow-hotplug" {
 | 
					$1 == "allow-hotplug" {
 | 
				
			||||||
  for (i = 2; i <= NF; i++) {
 | 
					  for (i = 2; i <= NF; i++) {
 | 
				
			||||||
print "hotplug: " $i ", iface=" iface
 | 
					 | 
				
			||||||
    if ($i == iface) {
 | 
					    if ($i == iface) {
 | 
				
			||||||
      have_hotplug = 1
 | 
					      have_hotplug = 1
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -554,8 +552,109 @@ function network_interfaces_check_confip() {
 | 
				
			|||||||
    __network_interfaces_check_confip
 | 
					    __network_interfaces_check_confip
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function __network_interfaces_remove_iface() {
 | 
				
			||||||
 | 
					    awkrun -f iface="$1" '
 | 
				
			||||||
 | 
					function match_iface(iface, line) {
 | 
				
			||||||
 | 
					  if (line == "") line = $0 " "
 | 
				
			||||||
 | 
					  return line ~ (" " iface " ")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					function remove_auto_iface(iface, line) {
 | 
				
			||||||
 | 
					  if (line == "") line = $0 " "
 | 
				
			||||||
 | 
					  gsub(" " iface " ", " ", line)
 | 
				
			||||||
 | 
					  return line
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					function print_auto_iface(line) {
 | 
				
			||||||
 | 
					  if (line ~ /^(allow-)?auto *$/) {
 | 
				
			||||||
 | 
					    # une seule interface sur la ligne: ne pas l"afficher
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    # supprimer l"interface de la ligne
 | 
				
			||||||
 | 
					    sub(/ *$/, "", line)
 | 
				
			||||||
 | 
					    print line
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					function remove_hotplug_iface(iface, line) {
 | 
				
			||||||
 | 
					  if (line == "") line = $0
 | 
				
			||||||
 | 
					  if (line !~ / $/) line = line " "
 | 
				
			||||||
 | 
					  gsub(" " iface " ", " ", line)
 | 
				
			||||||
 | 
					  return line
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					function print_hotplug_iface(line) {
 | 
				
			||||||
 | 
					  if (line ~ /^allow-hotplug *$/) {
 | 
				
			||||||
 | 
					    # une seule interface sur la ligne: ne pas l"afficher
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    # supprimer l"interface de la ligne
 | 
				
			||||||
 | 
					    sub(/ *$/, "", line)
 | 
				
			||||||
 | 
					    print line
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					BEGIN {
 | 
				
			||||||
 | 
					  in_iface = 0
 | 
				
			||||||
 | 
					  found_iface = 0
 | 
				
			||||||
 | 
					  modified = 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					!found_iface && $1 == "iface" && $2 == iface && $3 == "inet" {
 | 
				
			||||||
 | 
					  in_iface = 1
 | 
				
			||||||
 | 
					  found_iface = 1
 | 
				
			||||||
 | 
					  modified = 1
 | 
				
			||||||
 | 
					  next
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					$1 == "iface" {
 | 
				
			||||||
 | 
					  in_iface = 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					$1 ~ /^(allow-)?auto$/ {
 | 
				
			||||||
 | 
					  in_iface = 0
 | 
				
			||||||
 | 
					  if (match_iface(iface)) {
 | 
				
			||||||
 | 
					    print_auto_iface(remove_auto_iface(iface))
 | 
				
			||||||
 | 
					    modified = 1
 | 
				
			||||||
 | 
					    next
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					$1 == "allow-hotplug" {
 | 
				
			||||||
 | 
					  in_iface = 0
 | 
				
			||||||
 | 
					  if (match_iface(iface)) {
 | 
				
			||||||
 | 
					    print_hotplug_iface(remove_hotplug_iface(iface))
 | 
				
			||||||
 | 
					    modified = 1
 | 
				
			||||||
 | 
					    next
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					!in_iface { print }
 | 
				
			||||||
 | 
					END {
 | 
				
			||||||
 | 
					  if (modified) exit 0
 | 
				
			||||||
 | 
					  else exit 1
 | 
				
			||||||
 | 
					}'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
function network_interfaces_remove_iface() {
 | 
					function network_interfaces_remove_iface() {
 | 
				
			||||||
    :
 | 
					    # Supprimer dans le fichier $2(=/etc/network/interfaces) toute la
 | 
				
			||||||
 | 
					    # configuration qui concerne l'interface $1
 | 
				
			||||||
 | 
					    local iface="$1" nifile="${2:-/etc/network/interfaces}"
 | 
				
			||||||
 | 
					    local tmpfile; ac_set_tmpfile tmpfile
 | 
				
			||||||
 | 
					    local modified
 | 
				
			||||||
 | 
					    if __network_interfaces_remove_iface "$iface" <"$nifile" >"$tmpfile"; then
 | 
				
			||||||
 | 
					        cat "$tmpfile" >"$nifile"
 | 
				
			||||||
 | 
					        modified=1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    ac_clean "$tmpfile"
 | 
				
			||||||
 | 
					    [ -n "$modified" ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					function network_interfaces_remove_ifaces() {
 | 
				
			||||||
 | 
					    # Supprimer dans le fichier $2(=/etc/network/interfaces) toute la
 | 
				
			||||||
 | 
					    # configuration qui concerne les interfaces du tableau $1=(ifaces)
 | 
				
			||||||
 | 
					    local -a __niri_ifaces; array_copy __niri_ifaces "${1:-ifaces}"
 | 
				
			||||||
 | 
					    local nifile="${2:-/etc/network/interfaces}"
 | 
				
			||||||
 | 
					    local workfile; ac_set_tmpfile workfile
 | 
				
			||||||
 | 
					    local tmpfile; ac_set_tmpfile tmpfile
 | 
				
			||||||
 | 
					    local iface modified
 | 
				
			||||||
 | 
					    cat "$nifile" >"$workfile"
 | 
				
			||||||
 | 
					    for iface in "${__niri_ifaces[@]}"; do
 | 
				
			||||||
 | 
					        if __network_interfaces_remove_iface "$iface" <"$workfile" >"$tmpfile"; then
 | 
				
			||||||
 | 
					            cat "$tmpfile" >"$workfile"
 | 
				
			||||||
 | 
					            modified=1
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					    done
 | 
				
			||||||
 | 
					    [ -n "$modified" ] && cat "$workfile" >"$nifile"
 | 
				
			||||||
 | 
					    ac_clean "$workfile" "$tmpfile"
 | 
				
			||||||
 | 
					    [ -n "$modified" ]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function network_interfaces_add_confbr() {
 | 
					function network_interfaces_add_confbr() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user