| 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 /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 |
# PATTERN may contain variables, which will be interpolated every time the pattern search |
| 65 |
# is evaluated, except for when the delimiter is a single quote. |
| 66 |
# (perldoc perlop) |
| 67 |
perl -p -e "s'^ *START_IODINED=.*'START_IODINED=\"$START_IODINED\"'; \ |
| 68 |
s'^ *IODINED_ARGS=.*'IODINED_ARGS=\"$IODINED_ARGS\"'; \ |
| 69 |
s'^ *IODINED_PASSWORD=.*'IODINED_PASSWORD=\"$IODINED_PASSWORD\"';" \ |
| 70 |
< $CONFIGFILE > $CONFIGFILE.tmp |
| 71 |
|
| 72 |
mv -f $CONFIGFILE.tmp $CONFIGFILE |
| 73 |
[ ! -e $CONFIGFILE ] || chmod 600 $CONFIGFILE |
| 74 |
;; |
| 75 |
|
| 76 |
abort-upgrade|abort-remove|abort-deconfigure) |
| 77 |
;; |
| 78 |
|
| 79 |
*) |
| 80 |
echo "postinst called with unknown argument \`$1'" >&2 |
| 81 |
exit 1 |
| 82 |
;; |
| 83 |
esac |
| 84 |
|
| 85 |
# tell debconf we are done. otherwise, it hangs waiting for the daemon. |
| 86 |
db_stop; |
| 87 |
|
| 88 |
# dh_installdeb will replace this with shell code automatically |
| 89 |
# generated by other debhelper scripts. |
| 90 |
|
| 91 |
#DEBHELPER# |
| 92 |
|
| 93 |
# mask iodined.service if START_IODINED is not set to true |
| 94 |
# this mimicks the behaviour of sysvinit. cf. #832599 |
| 95 |
if [ "$1" = "configure" ] ; then |
| 96 |
if [ "$START_IODINED" != "true" ] ; then |
| 97 |
deb-systemd-helper mask iodined.service >/dev/null || true |
| 98 |
fi |
| 99 |
fi |
| 100 |
|
| 101 |
exit 0 |