confz

git mirror of https://ccx.te2000.cz/bzr/confz
git clone https://ccx.te2000.cz/git/confz
Log | Files | Refs

confz_ip_init (717B)


      1 # vim: ft=zsh noet ts=4 sts=4 sw=4
      2 
      3 #
      4 # confz functions for dealing with iproute2
      5 #
      6 
      7 
      8 confz_rename_interface_check() {
      9 	checkvars name mac
     10 
     11 	# local -A ifaces
     12 	local ignored iface mac rest out old_name
     13 
     14 	out=$( confz_do ip link show ) || die "ip failed"
     15 
     16 	while read ignored iface rest; do
     17 		read ignored mac rest
     18 		if [[ ${iface%:} == $vars[name] ]]; then
     19 			[[ $mac == $vars[mac] ]] || \
     20 				die "${(qqq)iface%:} already exists with different MAC address"
     21 			return 0
     22 		fi
     23 		if [[ -z $old_name && $mac == $vars[mac] ]]; then
     24 			old_name=${iface%:}
     25 		fi
     26 	done <<<$out
     27 
     28 	[[ -n $old_name ]] || die "could not find interface with MAC: $vars[mac]"
     29 
     30 	do_command=( ip link set dev $old_name name $vars[name] )
     31 	return 1
     32 }