source: debian/i2p.postinst @ 7b49493

Last change on this file since 7b49493 was 7b49493, checked in by kytv <kytv@…>, 9 years ago

Redo existing account handling

  • Property mode set to 100755
File size: 3.0 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    # Create user and group as a system user.
65    if getent passwd i2psvc > /dev/null 2>&1 ; then
66        usermod -c "I2P Router Daemon" -d $I2PHOME -g $I2PSYSUSER -s "/bin/false" \
67            $I2PSYSUSER -e 1 > /dev/null 2>&1
68    else
69        adduser --system --quiet --group --home $I2PHOME $I2PSYSUSER
70    fi
71
72    [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p
73    chown -f -R $I2PSYSUSER:adm /var/log/i2p
74
75    # Has someone set the permissions with dpkg-statoverride? If so, obey them.
76    if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1
77    then
78        chown -f -R $I2PSYSUSER:$I2PSYSUSER $I2PHOME
79        chmod -f u=rwx,g=rxs,o= $I2PHOME
80    fi
81
82    db_stop
83;;
84abort-upgrade|abort-remove|abort-deconfigure)
85    echo "Aborting upgrade"
86    exit 0
87    ;;
88*)
89        echo "postinst called with unknown argument \`$1'" >&2
90                exit 0
91                ;;
92esac
93
94#DEBHELPER#
95
96exit 0
Note: See TracBrowser for help on using the repository browser.