source: debian/i2p.postinst @ 2b79da5c

Last change on this file since 2b79da5c was dd65f17, checked in by kytv <kytv@…>, 8 years ago

Debian: Explicitly create the home directory in the postinst

Older versions of adduser create it automatically. The version in Debian unstable apparently does not…

  • Property mode set to 100755
File size: 3.3 KB
Line 
1#!/bin/sh  -e
2
3I2PHOME=/var/lib/i2p
4I2PSYSUSER=i2psvc
5
6conffile="/etc/default/i2p"
7
8# Source debconf library -- we have a Depends line
9# to make sure it is there...
10. /usr/share/debconf/confmodule
11db_version 2.0
12
13
14case "$1" in
15    configure|reconfigure)
16        if [ ! -e $conffile ]; then
17            echo "# Defaults for i2p initscript (/etc/init.d/i2p" >> $conffile
18            echo "# This is a posix shell fragment" >> $conffile
19            echo >> $conffile
20            echo "# [automatically edited by postinst, do not change line format ]" >> $conffile
21            echo "# Run 'dpkg-reconfigure -plow i2p' to change these values." >> $conffile
22            echo >> $conffile
23            echo "RUN_DAEMON=" >> $conffile
24            echo "I2PUSER=" >> $conffile
25            echo "# The next value is also wrapper.java.maxmemory in /etc/i2p/wrapper.config" >> $conffile
26            echo "MEMORYLIMIT=" >> $conffile
27        fi
28
29        db_get i2p/daemon
30        RUN_DAEMON="$RET"
31        db_get i2p/user
32        I2PUSER="$RET"
33        db_get i2p/memory
34        MEMORYLIMIT="$RET"
35
36        cp -a -f $conffile $conffile.tmp
37
38        # If the admin deleted or commented some variables but then set them via debconf,
39        # (re-)add them to the conffile.
40        test -z "$RUN_DAEMON" || grep -Eq '^ *RUN_DAEMON=' $conffile || \
41            echo "RUN_DAEMON=" >> $conffile
42        test -z "$I2PUSER" || grep -Eq '^ *I2PUSER=' $conffile || \
43            echo "I2PUSER=" >> $conffile
44        test -z "$MEMORYLIMIT" || grep -Eq '^ *MEMORYLIMIT=' $conffile || \
45            echo "MEMORYLIMIT=" >> $conffile
46
47        if [ -z $RUN_DAEMON ]; then
48            RUN_DAEMON="false"
49            I2PUSER="i2psvc"
50        fi
51
52
53
54        sed -e "s/^ *RUN_DAEMON=.*/RUN_DAEMON=\"$RUN_DAEMON\"/" \
55            -e "s/^ *I2PUSER=.*/I2PUSER=\"$I2PUSER\"/" \
56            -e "s/^ *MEMORYLIMIT=.*/MEMORYLIMIT=\"$MEMORYLIMIT\"/" \
57            < $conffile > $conffile.tmp
58        mv -f $conffile.tmp $conffile
59
60        sed -e "s/^ *wrapper\.java\.maxmemory=.*/wrapper\.java\.maxmemory=$MEMORYLIMIT/" \
61            < /etc/i2p/wrapper.config > /etc/i2p/wrapper.config.tmp
62        mv -f /etc/i2p/wrapper.config.tmp /etc/i2p/wrapper.config
63
64    # Older versions of adduser created the home directory.
65    # The version of adduser in Debian unstable does not.
66    [ -d $I2PHOME ] || mkdir -m0750 $I2PHOME
67
68    # Create user and group as a system user.
69    if getent passwd i2psvc > /dev/null 2>&1 ; then
70        groupadd -f $I2PSYSUSER || true
71        usermod -c "I2P Router Daemon" -d $I2PHOME -g $I2PSYSUSER -s "/bin/false" \
72            $I2PSYSUSER -e 1 > /dev/null 2>&1 || true
73    else
74        adduser --system --quiet --group --home $I2PHOME $I2PSYSUSER
75    fi
76
77    [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p
78    chown -f -R $I2PSYSUSER:i2psvc /var/log/i2p
79
80    # Has someone set the permissions with dpkg-statoverride? If so, obey them.
81    if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1
82    then
83        chown -f -R $I2PSYSUSER:$I2PSYSUSER $I2PHOME
84        chmod -f u=rwx,g=rxs,o= $I2PHOME
85    fi
86
87    db_stop
88;;
89abort-upgrade|abort-remove|abort-deconfigure)
90    echo "Aborting upgrade"
91    exit 0
92    ;;
93*)
94        echo "postinst called with unknown argument \`$1'" >&2
95                exit 0
96                ;;
97esac
98
99#DEBHELPER#
100
101exit 0
Note: See TracBrowser for help on using the repository browser.