~serge-hallyn/ubuntu/saucy/lxc/lxc-doc1

« back to all changes in this revision

Viewing changes to debian/lxc.preinst

  • Committer: Stéphane Graber
  • Author(s): Serge Hallyn
  • Date: 2013-05-14 19:34:51 UTC
  • Revision ID: stgraber@ubuntu.com-20130514193451-e23wdfwpfdg2rnsd
Tags: 0.9.0-0ubuntu6
debian/lxc.default, debian/lxc.preinst: calculate an open 10.0.x.0 network
for lxcbr0 to use at package install time.  This allows easier package
installion when nested.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
set -e
 
4
 
 
5
write_lxc_net()
 
6
{
 
7
    local i=$1
 
8
    cat >> /etc/default/lxc-net << EOF
 
9
# Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your
 
10
# containers.  Set to "false" if you'll use virbr0 or another existing
 
11
# bridge, or mavlan to your host's NIC.
 
12
USE_LXC_BRIDGE="true"
 
13
 
 
14
# If you change the LXC_BRIDGE to something other than lxcbr0, then
 
15
# you will also need to update your /etc/lxc/default.conf as well as the
 
16
# configuration (/var/lib/lxc/<container>/config) for any containers
 
17
# already created using the default config to reflect the new bridge
 
18
# name.
 
19
# If you have the dnsmasq daemon installed, you'll also have to update
 
20
# /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon.
 
21
LXC_BRIDGE="lxcbr0"
 
22
LXC_ADDR="10.0.$i.1"
 
23
LXC_NETMASK="255.255.255.0"
 
24
LXC_NETWORK="10.0.$i.0/24"
 
25
LXC_DHCP_RANGE="10.0.$i.2,10.0.$i.254"
 
26
LXC_DHCP_MAX="253"
 
27
EOF
 
28
}
 
29
 
 
30
configure_lxcbr0()
 
31
{
 
32
    local i=3
 
33
    cat > /etc/default/lxc-net << EOF
 
34
# This file is auto-generated by lxc.postinst if it does not
 
35
# exist.  Customizations will not be overridden.
 
36
EOF
 
37
    # if lxcbr0 exists, keep using the same network
 
38
    if  ip addr show lxcbr0 > /dev/null 2>&1 ; then
 
39
        i=`ip addr show lxcbr0 | grep "inet\>" | awk '{ print $2 }' | awk -F. '{ print $3 }'`
 
40
        write_lxc_net $i
 
41
        return
 
42
    fi
 
43
    # if no lxcbr0, find an open 10.0.a.0 network
 
44
    for l in `ip addr show | grep "inet\>" |awk '{ print $2 }' | grep '^10\.0\.' | sort -n`; do
 
45
            j=`echo $l | awk -F. '{ print $3 }'`
 
46
            if [ $j -gt $i ]; then
 
47
                write_lxc_net $i
 
48
                return
 
49
            fi
 
50
            i=$((j+1))
 
51
    done
 
52
    if [ $i -ne 254 ]; then
 
53
        write_lxc_net $i
 
54
    fi
 
55
}
 
56
 
 
57
case "${1}" in
 
58
    install|upgrade)
 
59
        if [ ! -f /etc/default/lxc-net ]; then
 
60
            configure_lxcbr0
 
61
        fi
 
62
        ;;
 
63
    abort-upgrade)
 
64
        ;;
 
65
    *)
 
66
        echo "preinst called with unknown argument (${1})"
 
67
        exit 1
 
68
        ;;
 
69
esac
 
70
 
 
71
#DEBHELPER#
 
72
 
 
73
exit 0