1 | #!/bin/sh -e |
---|
2 | |
---|
3 | I2PHOME=/var/lib/i2p |
---|
4 | I2P=/usr/share/i2p |
---|
5 | I2PUSER=i2psvc |
---|
6 | |
---|
7 | conffile="/etc/default/i2p" |
---|
8 | |
---|
9 | update_config_file() |
---|
10 | { |
---|
11 | db_field=$1 |
---|
12 | config_field=$2 |
---|
13 | |
---|
14 | RET=false |
---|
15 | db_get $db_field |
---|
16 | if [ -n "$RET" ] ; then |
---|
17 | if grep -q "^$config_field" $conffile ; then |
---|
18 | # keep any admin changes, while replacing the variable content |
---|
19 | sed "s/^[ ]*$config_field=\".*\"/$config_field=\"$RET\"/" < $conffile > $conffile.new && |
---|
20 | mv $conffile.new $conffile |
---|
21 | else |
---|
22 | echo "$config_field=\"$RET\"" >> $conffile |
---|
23 | fi |
---|
24 | fi |
---|
25 | } |
---|
26 | |
---|
27 | # Source debconf library -- we have a Depends line |
---|
28 | # to make sure it is there... |
---|
29 | . /usr/share/debconf/confmodule |
---|
30 | db_version 2.0 |
---|
31 | |
---|
32 | |
---|
33 | case "$1" in |
---|
34 | configure|reconfigure) |
---|
35 | if [ -f $conffile ] ; then |
---|
36 | sed -i -e 's/^[ ]*STARTI2P/RUN_DAEMON/g' $conffile |
---|
37 | if ! grep -q RUN_DAEMON $conffile ; then |
---|
38 | cat << EOF >> $conffile |
---|
39 | # I2P daemon. If set to true, I2P will start automatically |
---|
40 | # when your computer boots. |
---|
41 | RUN_DAEMON="false" |
---|
42 | EOF |
---|
43 | fi |
---|
44 | if ! grep -q I2PUSER $conffile ; then |
---|
45 | cat << EOF >> $conffile |
---|
46 | # The user that runs the I2P daemon. By default this is set to i2psvc. |
---|
47 | # You may want to change this to use a manually installed I2P profile. |
---|
48 | I2PUSER="i2psvc" |
---|
49 | EOF |
---|
50 | fi |
---|
51 | else |
---|
52 | cat << EOF >> $conffile |
---|
53 | # Defaults for i2p initscript (/etc/init.d/i2p) |
---|
54 | # This is a posix shell fragment |
---|
55 | |
---|
56 | # [automatically edited by postinst, do not change line format ] |
---|
57 | # Run 'dpkg-reconfigure -plow i2p' to change these values. |
---|
58 | |
---|
59 | # I2P daemon. If set to true, i2p will start automatically when |
---|
60 | # the computer boots |
---|
61 | RUN_DAEMON="false" |
---|
62 | |
---|
63 | # The user that runs the I2P daemon. By default this is set to i2psvc. |
---|
64 | # You may want to change this to use a manually installed I2P profile. |
---|
65 | I2PUSER="i2psvc" |
---|
66 | EOF |
---|
67 | fi |
---|
68 | update_config_file i2p/daemon RUN_DAEMON |
---|
69 | update_config_file i2p/user I2PUSER |
---|
70 | |
---|
71 | migrate_existing_user(){ |
---|
72 | # Adjust the user/group in /etc/passwd, mainly for upgrades from old packages that didn't |
---|
73 | # create $I2PUSER as a system group/user |
---|
74 | usermod -c "I2P Router Daemon" -m -d $I2PHOME -g $I2PUSER -s "/bin/false" \ |
---|
75 | -l $I2PUSER -e 1 > /dev/null 2>&1 |
---|
76 | echo "Existing user migrated, home directory moved to $I2PHOME" |
---|
77 | } |
---|
78 | |
---|
79 | # Create user and group as a system user. |
---|
80 | adduser --system --quiet --group --home $I2PHOME $I2PUSER || migrate_existing_user |
---|
81 | |
---|
82 | [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p |
---|
83 | chown -f -R $I2PUSER:adm /var/log/i2p |
---|
84 | |
---|
85 | # Has someone set the permissions with dpkg-statoverride? If so, obey them. |
---|
86 | if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1 |
---|
87 | then |
---|
88 | chown -f -R $I2PUSER:$I2PUSER $I2PHOME |
---|
89 | chmod -f u=rwx,g=rxs,o= $I2PHOME |
---|
90 | fi |
---|
91 | |
---|
92 | ##if ! dpkg-statoverride --list $I2P > /dev/null |
---|
93 | ##then |
---|
94 | ## chown -f -R $I2PUSER:$I2PUSER $I2P |
---|
95 | ##fi |
---|
96 | |
---|
97 | db_stop |
---|
98 | ;; |
---|
99 | abort-upgrade|abort-remove|abort-deconfigure) |
---|
100 | echo "Aborting upgrade" |
---|
101 | exit 0 |
---|
102 | ;; |
---|
103 | *) |
---|
104 | echo "postinst called with unknown argument \`$1'" >&2 |
---|
105 | exit 0 |
---|
106 | ;; |
---|
107 | esac |
---|
108 | |
---|
109 | #DEBHELPER# |
---|
110 | |
---|
111 | exit 0 |
---|