]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | set -e | |
3 | ||
4 | MYNAME="${0##*/}" | |
5 | ||
6 | report() { echo "${MYNAME}: $*" ; } | |
7 | report_warn() { report "Warning: $*" >&2 ; } | |
8 | report_err() { report "Error: $*" >&2 ; } | |
9 | ||
10 | fix_dhclient_file_with_space() | |
11 | { | |
12 | # because of a typo an older ifupdown2 version was creating lease file | |
13 | # with trailing space. In case we still have users with such files we | |
14 | # need to strip that trailing whitespace. | |
15 | for filename in `find /var/lib/dhcp/ -name "dhclient.*.leases "` | |
16 | do | |
17 | if [ -f "$filename " ]; | |
18 | then | |
19 | interface_name=`echo $filename | cut -d'.' -f2,3,4,5` | |
20 | mv "$filename " /var/lib/dhcp/dhclient6.$interface_name | |
21 | fi | |
22 | done | |
23 | } | |
24 | ||
25 | process_etc_network_interfaces() | |
26 | { | |
27 | # Generic stuff done on all configurations | |
28 | if [ -f /etc/network/interfaces ] ; then | |
29 | if ! grep -q -E "^[[:space:]]*iface[[:space:]]+l[o0]([[:space:]]+inet([[:space:]]+loopback)?)?[[:space:]]*$" /etc/network/interfaces ; then | |
30 | report_warn "No 'iface lo' definition found in /etc/network/interfaces" | |
31 | fi | |
32 | ||
33 | if ! grep -q "^[[:space:]]*\(allow-\|\)auto[[:space:]]\+\(.*[[:space:]]\+\|\)lo0\?\([[:space:]]\+\|$\)" /etc/network/interfaces ; then | |
34 | report_warn "No 'auto lo' statement found in /etc/network/interfaces" | |
35 | fi | |
36 | else # ! -f /etc/network/interfaces | |
37 | if [ -z "$2" ]; then | |
38 | echo "Creating /etc/network/interfaces." | |
39 | echo "# interfaces(5) file used by ifup(8) and ifdown(8)" > /etc/network/interfaces | |
40 | echo "auto lo" >> /etc/network/interfaces | |
41 | echo "iface lo inet loopback" >> /etc/network/interfaces | |
42 | else | |
43 | report_warn "/etc/network/interfaces does not exist" | |
44 | fi | |
45 | fi | |
46 | } | |
47 | ||
48 | process_udev() | |
49 | { | |
50 | # override default udev bridge and hotplug rules because they interfere with | |
51 | # networking init script | |
52 | udev_user_rulesdir=/etc/udev/rules.d/ | |
53 | udev_sys_rulesdir=/lib/udev/rules.d/ | |
54 | if [ -e $udev_user_rulesdir ]; then | |
55 | udev_ifupdown2_overrides="80-networking.rules | |
56 | 60-bridge-network-interface.rules" | |
57 | for u in ${udev_ifupdown2_overrides} | |
58 | do | |
59 | if [ -e ${udev_sys_rulesdir}/$u -a ! -e ${udev_user_rulesdir}/$u ]; then | |
60 | (cd ${udev_user_rulesdir} && ln -sf /dev/null $u) | |
61 | fi | |
62 | done | |
63 | fi | |
64 | } | |
65 | ||
66 | # restore file if we diverted it on install/upgrade | |
67 | _postinst_remove_diverts() | |
68 | { | |
69 | diversions=$(LC_ALL=C.UTF-8 dpkg-divert --list | grep "^diversion of $1 .* by ifupdown2$" | wc -l 2> /dev/null) | |
70 | if [ $diversions -gt 0 ]; | |
71 | then | |
72 | dpkg-divert --remove --package ifupdown2 --rename $1 | |
73 | fi | |
74 | } | |
75 | ||
76 | postinst_remove_diverts() | |
77 | { | |
78 | for filename in ifup ifdown ifquery ifreload | |
79 | do | |
80 | _postinst_remove_diverts "/sbin/$filename" | |
81 | _postinst_remove_diverts "/usr/share/bash-completion/completions/$filename" | |
82 | _postinst_remove_diverts "/etc/bash_completion.d/$filename" | |
83 | _postinst_remove_diverts "/usr/share/man/man8/$filename.8.gz" | |
84 | done | |
85 | _postinst_remove_diverts "/usr/share/man/man5/interfaces.5.gz" | |
86 | } | |
87 | ||
88 | case "$1" in | |
89 | configure) | |
90 | fix_dhclient_file_with_space | |
91 | process_etc_network_interfaces | |
92 | process_udev | |
93 | chmod +x /usr/share/ifupdown2/__main__.py | |
94 | postinst_remove_diverts | |
95 | ;; | |
96 | ||
97 | abort-upgrade|abort-remove|abort-deconfigure) | |
98 | ;; | |
99 | ||
100 | *) | |
101 | echo "postinst called with unknown argument \`$1'" >&2 | |
102 | exit 1 | |
103 | ;; | |
104 | esac | |
105 | ||
106 | ||
107 | #DEBHELPER# | |
108 | ||
109 | exit 0 |