rc.local 2.02 KB
Newer Older
Maria Matejka's avatar
Maria Matejka committed
1 2
#!/bin/bash

3
export PATH=$PATH:/usr/local/bin:/usr/pkg/bin
Maria Matejka's avatar
Maria Matejka committed
4

5
. /mnt/nfs/rclib
Maria Matejka's avatar
Maria Matejka committed
6 7

case $UNAME in
8 9
	linux)
		AUTOCONF=autoreconf
Maria Matejka's avatar
Maria Matejka committed
10
		MAKE=make
11 12

    iptables -F # Flush predefined firewall
Maria Matejka's avatar
Maria Matejka committed
13
		;;
14

15
	freebsd|netbsd)
16
		AUTOCONF=autoreconf
Maria Matejka's avatar
Maria Matejka committed
17
		MAKE=gmake
18 19 20

		sysctl -w net.inet6.ip6.forwarding=1
		sysctl -w net.inet.ip.forwarding=1
Maria Matejka's avatar
Maria Matejka committed
21
		;;
22

Maria Matejka's avatar
Maria Matejka committed
23
	openbsd)
24
		AUTOCONF=autoreconf-2.69
Maria Matejka's avatar
Maria Matejka committed
25
		MAKE=gmake
26 27 28

		sysctl -w net.inet6.ip6.forwarding=1
		sysctl -w net.inet.ip.forwarding=1
29 30
		sysctl -w net.inet.esp.enable=1
		sysctl -w net.inet.gre.allow=1
Maria Matejka's avatar
Maria Matejka committed
31 32 33 34 35 36
		;;
	*)
		echo "Unknown system $UNAME"
		;;
esac

37
echo "Ifaces list: $(ifaces)"
38

39 40 41 42
for I in $(ifaces); do
	NAME=${I%%,*}
	MAC=${I##*,}
	MAC=${MAC,,}
43

44
  echo "Iface $NAME ($MAC)"
45 46 47

  case $UNAME in
    linux)
48 49 50 51 52 53 54
      CIP4=$(ip addr show dev $NAME | sed -nr 's/\s+inet ([^ ]*) brd 192.168.255.255 .*/\1/p' )
      if [ -n "$CIP4" ]; then
        CIP6DEC=$(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)/[0-9]+#2001:1488:a001::\1:\2/64#')
        CIP6HEX=$(printf "2001:1488:a001::ffff:%02x%02x/64" $(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)/[0-9]+#\1 \2#'))
        ip6 $NAME $CIP6HEX
        ip6 $NAME $CIP6DEC
        ip -6 route add default via 2001:1488:a001::1
55
        continue
56
      fi
57 58
      ;;
    netbsd|openbsd|freebsd)
59 60 61 62 63 64 65 66 67 68
      CIP4=$(ifconfig $NAME | sed -nr 's/[[:space:]]+inet (192.168.[^ ]*) netmask 0x[0-9a-f]+ broadcast 192.168.255.255/\1/p' )
      echo "CIP4=$CIP4"
      if [ -n "$CIP4" ]; then
        CIP6DEC=$(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)#2001:1488:a001::\1:\2/64#')
        CIP6HEX=$(printf "2001:1488:a001::ffff:%02x%02x/64" $(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)#\1 \2#'))
        echo "CIP6DEC=$CIP6DEC"
        echo "CIP6HEX=$CIP6HEX"
        ip6 $NAME $CIP6HEX
        ip6 $NAME $CIP6DEC
        route add -inet6 default 2001:1488:a001::1
69
        continue
70
      fi
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
      ;;
  esac

  IFBYMAC[$MAC]=$NAME
  INTERFACES+=( $I )
done

RCGFILE=/mnt/nfs/rc/rc-gen-$HOSTNAME
if [ -f $RCGFILE ]; then
  . $RCGFILE
fi

RCFILE=/mnt/nfs/rc/rc-loc-$HOSTNAME
if [ -f $RCFILE ]; then
  . $RCFILE
86
fi