File: dhcp-probe.postinst

package info (click to toggle)
dhcp-probe 1.3.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,316 kB
  • sloc: sh: 4,783; ansic: 2,400; perl: 381; xml: 51; makefile: 50
file content (96 lines) | stat: -rw-r--r-- 2,263 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
# piston's script for dhcp-probe
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


PACKAGE="dhcp-probe"
CONF_DIR="/etc/$PACKAGE"
CONF_FILE="/etc/dhcp_probe.cf"

MSG="dhcp-probe: IP not configured on host, please see template file"
MSG="$MSG /usr/share/doc/dhcp-probe/dhcp_probe.tpl.eth0 to configure !"

#
# Dynamic configuration procedure
#
if test -f /lib/lsb/init-functions
then
	. /lib/lsb/init-functions
fi

#
# postinst script main
#
case "$1" in
    configure)
			DEST="/etc/$PACKAGE/$PACKAGE"
			if [ -z "$(ls "$CONF_DIR")" ]
			then # Configuration doesn't exist
				ip address | awk '
					/^[0-9]*:/ {
						iface=$2
						sub(/:/, "", iface)
						ether=""
						inet=0
					}
					/link\/ether/ {
						ether=$2
					}
					/inet / && !inet {
						inet=$2
						sub(/\/.*/, "", inet)
						if(iface && ether && inet) {
							print iface
							print ether
							print inet
						}
					}
				' | while read -r i && read -r ether && read -r inet; do
					TMPDEST=$(mktemp -t "$PACKAGE.$i.XXXXXXXX")
					{
						echo "#"
						echo "# Automaticaly generated file during dhcp-probe package install procedure"
						echo "#"
						echo "INTERFACE=\"$i\""
						echo "MAC=\"$ether\""
						echo "IPV4=\"$inet\""
					} > "$TMPDEST"
					ucf "$TMPDEST" "$DEST.$i"
					logger -i -p daemon.crit "$TMPDEST installed."
					rm -f "$TMPDEST"
				done
			fi
			if test ! -f "$CONF_FILE"; then
				DHCP_PROBE_CF=$(mktemp -t $PACKAGE.XXXXXXXX)
				ucf "$DHCP_PROBE_CF" "$CONF_FILE"
				rm -f "$DHCP_PROBE_CF"
			fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

#DEBHELPER#

exit 0