moth/packages/00admin/bin/fire-ip

33 lines
516 B
Plaintext
Raw Normal View History

2012-04-19 17:40:30 -06:00
#! /bin/sh -e
action=$1; shift
read n < ip.txt
if grep -q ipv4 /proc/cmdline; then
# IPv4
2012-04-24 10:03:14 -06:00
IP="10.0.0.$n/16"
2012-04-19 17:40:30 -06:00
else
# IPv6
l=$(busybox dc 16 o $n p)
IP="fd84:b410:3441::$l/64"
fi
[ "$action" ] && ip addr $action $IP dev eth0
if [ "$action" = "add" ]; then
fail=fail
for i in $(seq 5); do
2012-04-24 10:03:14 -06:00
if ip addr | grep -v tentative | grep -Fq $IP; then
2012-04-19 17:40:30 -06:00
fail=
break
fi
sleep 1
done
[ "$fail" ] && return 1
fi
[ "$action" = del ] || echo $IP