net (883B)
1 #!/bin/sh 2 3 [ $(whoami) != "root" ] && echo "run this shit as root" && exit 4 5 dev_scan() { 6 [ -n "$2" ] && cd $1 7 DEV=$1 8 IP=$(cat ip 2>/dev/null) 9 MAC=$(cat mac 2>/dev/null) 10 GW=$(cat gw 2>/dev/null) 11 MASTER=$(cat master 2>/dev/null) 12 13 ip l s $1 up 14 ip a f dev $1 15 [ -n "$MAC" ] && ip l s $1 a $MAC 16 if [ -n "$MASTER" ] 17 then 18 if [ -z "$(ip l show "$MASTER" 2>/dev/null)" ] 19 then 20 ip l a $MASTER type bridge 21 ip l s $MASTER up 22 fi 23 ip l s $DEV master $MASTER 24 DEV=$MASTER 25 fi 26 if [ -z "$IP" ] 27 then 28 ! [ -d "$1" ] && dhcpcd -4n $DEV && return 29 IP=$(cat "$1"/ip) 30 GW=$(cat "$1"/gw) 31 fi 32 ip a a $IP/24 dev $DEV 2>/dev/null 33 ip r a default via $GW 2>/dev/null 34 } 35 36 cd /etc/net 37 38 if [ $# -eq 0 ] 39 then 40 dev_scan $(ip -o l|awk '$2~/^[ew][^u]+$/{print $2}'|sed 's/://;q') 41 killall dhcpcd 2>/dev/null 42 for dev in $(ls) 43 do 44 ! [ -d "$dev" ] && continue 45 dev_scan $dev 1 & 46 done 47 fi