1 | #!/bin/sh |
---|
2 | |
---|
3 | set -e |
---|
4 | |
---|
5 | I2PHOME=/var/lib/i2p |
---|
6 | I2PSYSUSER=i2psvc |
---|
7 | |
---|
8 | conffile="/etc/default/i2p" |
---|
9 | systemdservice="/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 |
---|
14 | db_version 2.0 |
---|
15 | |
---|
16 | |
---|
17 | case "$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 "ULIMIT=" >> $conffile |
---|
29 | echo "CONFINE_WITH_APPARMOR=" >> $conffile |
---|
30 | echo "# The next value is also wrapper.java.maxmemory in /etc/i2p/wrapper.config" >> $conffile |
---|
31 | echo "MEMORYLIMIT=" >> $conffile |
---|
32 | fi |
---|
33 | |
---|
34 | db_get i2p/daemon |
---|
35 | RUN_DAEMON="$RET" |
---|
36 | db_get i2p/user |
---|
37 | I2PUSER="$RET" |
---|
38 | db_get i2p/memory |
---|
39 | MEMORYLIMIT="$RET" |
---|
40 | db_get i2p/aa |
---|
41 | CONFINE_WITH_APPARMOR="$RET" |
---|
42 | |
---|
43 | cp -a -f $conffile $conffile.tmp |
---|
44 | |
---|
45 | # If the admin deleted or commented some variables but then set them via debconf, |
---|
46 | # (re-)add them to the conffile. |
---|
47 | test -z "$RUN_DAEMON" || grep -Eq '^ *RUN_DAEMON=' $conffile || \ |
---|
48 | echo "RUN_DAEMON=" >> $conffile |
---|
49 | test -z "$I2PUSER" || grep -Eq '^ *I2PUSER=' $conffile || \ |
---|
50 | echo "I2PUSER=" >> $conffile |
---|
51 | test -z "$MEMORYLIMIT" || grep -Eq '^ *MEMORYLIMIT=' $conffile || \ |
---|
52 | echo "MEMORYLIMIT=" >> $conffile |
---|
53 | test -z "$ULIMIT" || grep -Eq '^ *ULIMIT=' $conffile || \ |
---|
54 | echo "ULIMIT=" >> $conffile |
---|
55 | test -z "$CONFINE_WITH_APPARMOR" || grep -Eq '^ *CONFINE_WITH_APPARMOR=' $conffile || \ |
---|
56 | echo "CONFINE_WITH_APPARMOR=" >> $conffile |
---|
57 | |
---|
58 | if [ -z $RUN_DAEMON ]; then |
---|
59 | RUN_DAEMON="false" |
---|
60 | I2PUSER="i2psvc" |
---|
61 | fi |
---|
62 | |
---|
63 | sed -e "s/^ *RUN_DAEMON=.*/RUN_DAEMON=\"$RUN_DAEMON\"/" \ |
---|
64 | -e "s/^ *I2PUSER=.*/I2PUSER=\"$I2PUSER\"/" \ |
---|
65 | -e "s/^ *MEMORYLIMIT=.*/MEMORYLIMIT=\"$MEMORYLIMIT\"/" \ |
---|
66 | -e "s/^ *CONFINE_WITH_APPARMOR=.*/CONFINE_WITH_APPARMOR=\"$CONFINE_WITH_APPARMOR\"/" \ |
---|
67 | < $conffile > $conffile.tmp |
---|
68 | mv -f $conffile.tmp $conffile |
---|
69 | |
---|
70 | if [ -e "$systemdservice" ]; then |
---|
71 | sed -e "s/User=.*/User=$I2PUSER/" < "$systemdservice" > "$systemdservice.tmp" |
---|
72 | mv -f "$systemdservice.tmp" "$systemdservice" |
---|
73 | chmod 0644 -f "$systemdservice" |
---|
74 | if [ -d /run/systemd/system ]; then |
---|
75 | systemctl --system daemon-reload || true |
---|
76 | if [ $RUN_DAEMON = 'true' ]; then |
---|
77 | deb-systemd-helper enable i2p.service |
---|
78 | else |
---|
79 | deb-systemd-helper disable i2p.service |
---|
80 | fi |
---|
81 | fi |
---|
82 | fi |
---|
83 | |
---|
84 | sed -e "s/^ *wrapper\.java\.maxmemory=.*/wrapper\.java\.maxmemory=$MEMORYLIMIT/" \ |
---|
85 | < /etc/i2p/wrapper.config > /etc/i2p/wrapper.config.tmp |
---|
86 | mv -f /etc/i2p/wrapper.config.tmp /etc/i2p/wrapper.config |
---|
87 | chmod 0644 -f /etc/i2p/wrapper.config |
---|
88 | |
---|
89 | # Older versions of adduser created the home directory. |
---|
90 | # The version of adduser in Debian unstable does not. |
---|
91 | [ -d $I2PHOME ] || mkdir -m0750 $I2PHOME |
---|
92 | |
---|
93 | # Create user and group as a system user. |
---|
94 | if getent passwd i2psvc > /dev/null 2>&1 ; then |
---|
95 | groupadd -f $I2PSYSUSER || true |
---|
96 | usermod -c "I2P Router Daemon" -d $I2PHOME -g $I2PSYSUSER -s "/bin/false" \ |
---|
97 | $I2PSYSUSER -e 1 > /dev/null 2>&1 || true |
---|
98 | else |
---|
99 | adduser --system --quiet --group --home $I2PHOME $I2PSYSUSER > /dev/null 2>&1 |
---|
100 | fi |
---|
101 | |
---|
102 | [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p |
---|
103 | chown -f -R $I2PSYSUSER:i2psvc /var/log/i2p |
---|
104 | |
---|
105 | # Has someone set the permissions with dpkg-statoverride? If so, obey them. |
---|
106 | if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1 |
---|
107 | then |
---|
108 | chown -f -R $I2PSYSUSER:$I2PSYSUSER $I2PHOME |
---|
109 | chmod -f u=rwx,g=rxs,o= $I2PHOME |
---|
110 | fi |
---|
111 | |
---|
112 | db_stop |
---|
113 | ;; |
---|
114 | abort-upgrade|abort-remove|abort-deconfigure) |
---|
115 | echo "Aborting upgrade" |
---|
116 | exit 0 |
---|
117 | ;; |
---|
118 | *) |
---|
119 | echo "postinst called with unknown argument \`$1'" >&2 |
---|
120 | exit 0 |
---|
121 | ;; |
---|
122 | esac |
---|
123 | |
---|
124 | #DEBHELPER# |
---|
125 | |
---|
126 | exit 0 |
---|
127 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |
---|