debian/postinst: only try to create /dev/net/tun if it doesn't exist and
[debian/iodine.git] / debian / postinst
1 #!/bin/sh
2 # postinst script for iodine
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
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         # and we want a special user
32         adduser --quiet --system --home /var/run/iodine iodine
33         # generate /etc/default/iodine
34         db_get iodine/start_daemon
35         START_IODINED=$RET
36         db_get iodine/daemon_options
37         IODINED_ARGS=$RET
38         db_get iodine/daemon_password
39         IODINED_PASSWORD=$RET
40         cat <<EOF > /etc/default/iodine
41 # Default settings for iodine. This file is sourced from
42 # /etc/init.d/iodined
43 START_IODINED="$START_IODINED"
44 IODINED_ARGS="$IODINED_ARGS"
45 IODINED_PASSWORD="$IODINED_PASSWORD"
46 EOF
47         [ -e /etc/default/iodine ] && chmod 600 /etc/default/iodine
48     ;;
49
50     abort-upgrade|abort-remove|abort-deconfigure)
51     ;;
52
53     *)
54         echo "postinst called with unknown argument \`$1'" >&2
55         exit 1
56     ;;
57 esac
58
59 # tell debconf we are done. otherwise, it hangs waiting for the daemon.
60 db_stop;
61
62 # dh_installdeb will replace this with shell code automatically
63 # generated by other debhelper scripts.
64
65 #DEBHELPER#
66
67 exit 0