Add oping as an alternative to fping in Suggests.
[debian/iodine.git] / debian / postinst
1 #!/bin/sh
2 # postinst script for iodine
3 #
4 # see: dh_installdeb(1)
5
6 CONFIGFILE=/etc/default/iodine
7 set -e
8 . /usr/share/debconf/confmodule
9
10 # summary of how this script can be called:
11 #        * <postinst> `configure' <most-recently-configured-version>
12 #        * <old-postinst> `abort-upgrade' <new version>
13 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
14 #          <new-version>
15 #        * <postinst> `abort-remove'
16 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
17 #          <failed-install-package> <version> `removing'
18 #          <conflicting-package> <version>
19 # for details, see http://www.debian.org/doc/debian-policy/ or
20 # the debian-policy package
21
22
23 case "$1" in
24     configure)
25         # we need a tun device
26         if [ ! -c /dev/net/tun ] && [ -x /dev/MAKEDEV ] ; then
27             echo "Creating device /dev/net/tun ..."
28             cd /dev
29             ./MAKEDEV tun || true
30         fi 
31
32         # and we want a special user
33         adduser --quiet --system --home /var/run/iodine iodine
34
35         # generate/update /etc/default/iodine
36         if [ ! -e $CONFIGFILE ]; then
37             cat <<EOF >$CONFIGFILE
38 # Default settings for iodine. This file is sourced from
39 # /etc/init.d/iodined
40 START_IODINED=
41 IODINED_ARGS=
42 IODINED_PASSWORD=
43 EOF
44         fi
45
46         db_get iodine/start_daemon
47         START_IODINED=$RET
48         db_get iodine/daemon_options
49         IODINED_ARGS=$RET
50         db_get iodine/daemon_password
51         IODINED_PASSWORD=$RET
52
53         cp -a -f $CONFIGFILE $CONFIGFILE.tmp
54
55         # If the admin deleted or commented some variables but then set
56         # them via debconf, (re-)add them to the conffile.
57         test -z "$START_IODINED" || grep -Eq '^ *START_IODINED=' $CONFIGFILE || \
58             echo "START_IODINED=" >> $CONFIGFILE
59         test -z "$IODINED_ARGS" || grep -Eq '^ *IODINED_ARGS=' $CONFIGFILE || \
60             echo "IODINED_ARGS=" >> $CONFIGFILE
61         test -z "$IODINED_PASSWORD" || grep -Eq '^ *IODINED_PASSWORD=' $CONFIGFILE || \
62             echo "IODINED_PASSWORD=" >> $CONFIGFILE
63
64         sed -e "s/^ *START_IODINED=.*/START_IODINED=\"$START_IODINED\"/" \
65             -e "s/^ *IODINED_ARGS=.*/IODINED_ARGS=\"$IODINED_ARGS\"/" \
66             -e "s/^ *IODINED_PASSWORD=.*/IODINED_PASSWORD=\"$IODINED_PASSWORD\"/" \
67             < $CONFIGFILE > $CONFIGFILE.tmp
68
69         mv -f $CONFIGFILE.tmp $CONFIGFILE
70         [ ! -e $CONFIGFILE ] || chmod 600 $CONFIGFILE
71     ;;
72
73     abort-upgrade|abort-remove|abort-deconfigure)
74     ;;
75
76     *)
77         echo "postinst called with unknown argument \`$1'" >&2
78         exit 1
79     ;;
80 esac
81
82 # tell debconf we are done. otherwise, it hangs waiting for the daemon.
83 db_stop;
84
85 # dh_installdeb will replace this with shell code automatically
86 # generated by other debhelper scripts.
87
88 #DEBHELPER#
89
90 exit 0