Debian Codegraph @

debian/dhcp-probe.postinst

raw
1 #!/bin/sh
2 # piston's script for dhcp-probe
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
21 PACKAGE="dhcp-probe"
22 CONF_DIR="/etc/$PACKAGE"
23 CONF_FILE="/etc/dhcp_probe.cf"
24
25 MSG="dhcp-probe: IP not configured on host, please see template file"
26 MSG="$MSG /usr/share/doc/dhcp-probe/dhcp_probe.tpl.eth0 to configure !"
27
28 #
29 # Dynamic configuration procedure
30 #
31 if test -f /lib/lsb/init-functions
32 then
33 . /lib/lsb/init-functions
34 fi
35
36 #
37 # postinst script main
38 #
39 case "$1" in
40 configure)
41 DEST="/etc/$PACKAGE/$PACKAGE"
42 if [ -z "$(ls "$CONF_DIR")" ]
43 then # Configuration doesn't exist
44 ip address | awk '
45 /^[0-9]*:/ {
46 iface=$2
47 sub(/:/, "", iface)
48 ether=""
49 inet=0
50 }
51 /link\/ether/ {
52 ether=$2
53 }
54 /inet / && !inet {
55 inet=$2
56 sub(/\/.*/, "", inet)
57 if(iface && ether && inet) {
58 print iface
59 print ether
60 print inet
61 }
62 }
63 ' | while read -r i && read -r ether && read -r inet; do
64 TMPDEST=$(mktemp -t "$PACKAGE.$i.XXXXXXXX")
65 {
66 echo "#"
67 echo "# Automaticaly generated file during dhcp-probe package install procedure"
68 echo "#"
69 echo "INTERFACE=\"$i\""
70 echo "MAC=\"$ether\""
71 echo "IPV4=\"$inet\""
72 } > "$TMPDEST"
73 ucf "$TMPDEST" "$DEST.$i"
74 logger -i -p daemon.crit "$TMPDEST installed."
75 rm -f "$TMPDEST"
76 done
77 fi
78 if test ! -f "$CONF_FILE"; then
79 DHCP_PROBE_CF=$(mktemp -t $PACKAGE.XXXXXXXX)
80 ucf "$DHCP_PROBE_CF" "$CONF_FILE"
81 rm -f "$DHCP_PROBE_CF"
82 fi
83 ;;
84
85 abort-upgrade|abort-remove|abort-deconfigure)
86 ;;
87
88 *)
89 echo "postinst called with unknown argument \`$1'" >&2
90 exit 1
91 ;;
92 esac
93
94 #DEBHELPER#
95
96 exit 0