source: debian/i2p.postinst @ 5d1796b

Last change on this file since 5d1796b was bfba732, checked in by kytv <kytv@…>, 6 years ago

Debian: Add systemd support (ticket #1208)

Currently just for Debian unstable and Ubuntu Saucy and newer.

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