1 | #!/bin/sh -e |
---|
2 | |
---|
3 | I2PHOME=/var/lib/i2p |
---|
4 | I2PSYSUSER=i2psvc |
---|
5 | |
---|
6 | conffile="/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 |
---|
11 | db_version 2.0 |
---|
12 | |
---|
13 | |
---|
14 | case "$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 | migrate_existing_user(){ |
---|
65 | # Adjust the user/group in /etc/passwd, mainly for upgrades from old packages that didn't |
---|
66 | # create $I2PSYSUSER as a system group/user |
---|
67 | usermod -c "I2P Router Daemon" -m -d $I2PHOME -g $I2PSYSUSER -s "/bin/false" \ |
---|
68 | -l $I2PSYSUSER -e 1 > /dev/null 2>&1 |
---|
69 | echo "Existing user migrated, home directory moved to $I2PHOME" |
---|
70 | } |
---|
71 | |
---|
72 | # Create user and group as a system user. |
---|
73 | adduser --system --quiet --group --home $I2PHOME $I2PSYSUSER || migrate_existing_user |
---|
74 | |
---|
75 | [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p |
---|
76 | chown -f -R $I2PSYSUSER:adm /var/log/i2p |
---|
77 | |
---|
78 | # Has someone set the permissions with dpkg-statoverride? If so, obey them. |
---|
79 | if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1 |
---|
80 | then |
---|
81 | chown -f -R $I2PSYSUSER:$I2PSYSUSER $I2PHOME |
---|
82 | chmod -f u=rwx,g=rxs,o= $I2PHOME |
---|
83 | fi |
---|
84 | |
---|
85 | db_stop |
---|
86 | ;; |
---|
87 | abort-upgrade|abort-remove|abort-deconfigure) |
---|
88 | echo "Aborting upgrade" |
---|
89 | exit 0 |
---|
90 | ;; |
---|
91 | *) |
---|
92 | echo "postinst called with unknown argument \`$1'" >&2 |
---|
93 | exit 0 |
---|
94 | ;; |
---|
95 | esac |
---|
96 | |
---|
97 | #DEBHELPER# |
---|
98 | |
---|
99 | exit 0 |
---|