openvpn-nomades : postinst
[auf-serveur.git] / auf-serveur-openvpn-nomades / debian / postinst
1 #!/bin/sh
2 # postinst script for auf-serveur-openvpn-nomades
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 # summary of how this script can be called:
9 #        * <postinst> `configure' <most-recently-configured-version>
10 #        * <old-postinst> `abort-upgrade' <new version>
11 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12 #          <new-version>
13 #        * <postinst> `abort-remove'
14 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15 #          <failed-install-package> <version> `removing'
16 #          <conflicting-package> <version>
17 # for details, see http://www.debian.org/doc/debian-policy/ or
18 # the debian-policy package
19
20 LOCALCONF=/etc/openvpn/auf-nomades.conf.local
21
22 conf_openvpn_local() {
23         # create /etc/openvpn/auf-nomades.conf.local
24         VPNIP=`LANG=C /sbin/ifconfig | sed -n 's/^[[:space:]]*inet addr:\(10\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/p' | head -1`
25         test -z "$VPNIP" && VPNIP="10.255.0.0"
26         VPN16=`echo $VPNIP | cut -d. -f1-2`
27         VPN20=$(($((`echo $VPNIP | cut -d. -f3` / 16))*16))
28         VPNNOMADE=$(($VPN20 + 8))
29         CONF_IFCONFIG="ifconfig $VPN16.$VPNNOMADE.1 $VPN16.$VPNNOMADE.2"
30         CONF_ROUTE="route $VPN16.$VPNNOMADE.0 255.255.248.0"
31         CONF_POOL="ifconfig-pool $VPN16.$(($VPNNOMADE + 4)).1 $VPN16.$(($VPNNOMADE + 7)).255"
32         sed -e 's/^ifconfig[[:space:]].*$/'"$CONF_IFCONFIG"'/' \
33                 -e 's/^route[[:space:]].*$/'"$CONF_ROUTE"'/' \
34                 -e 's/^ifconfig-pool[[:space:]].*$/'"$CONF_POOL"'/' < /usr/share/doc/auf-serveur-openvpn-nomades/auf-nomades.conf.local.ex > $LOCALCONF
35 }
36
37 case "$1" in
38     configure)
39         if ! test -f $LOCALCONF
40         then
41                 conf_openvpn_local
42                 if test -x /etc/init.d/openvpn
43                 then
44                         invoke-rc.d openvpn start auf-nomades
45                 fi
46         fi
47     ;;
48
49     abort-upgrade|abort-remove|abort-deconfigure)
50     ;;
51
52     *)
53         echo "postinst called with unknown argument \`$1'" >&2
54         exit 1
55     ;;
56 esac
57
58 # dh_installdeb will replace this with shell code automatically
59 # generated by other debhelper scripts.
60
61 #DEBHELPER#
62
63 exit 0
64
65