source: debian/i2p.postinst @ f674b78

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

Fix ticket #514 (debconf values are overwritten upon installation)

  • Property mode set to 100755
File size: 2.4 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                fi
26
27                db_get i2p/daemon
28                RUN_DAEMON="$RET"
29                db_get i2p/user
30                I2PUSER="$RET"
31
32                cp -a -f $conffile $conffile.tmp
33
34                # If the admin deleted or commented some variables but then set them via debconf,
35                # (re-)add them to the conffile.
36                test -z "$RUN_DAEMON" || grep -Eq '^ *RUN_DAEMON=' $conffile || \
37                        echo "RUN_DAEMON=" >> $conffile
38                test -z "$I2PUSER" || grep -Eq '^ *I2PUSER=' $conffile || \
39                        echo "I2PUSER=" >> $conffile
40
41                if [ -z $RUN_DAEMON ]; then
42                        RUN_DAEMON="false"
43                        I2PUSER="i2psvc"
44                fi
45
46                sed -e "s/^ *RUN_DAEMON=.*/RUN_DAEMON=\"$RUN_DAEMON\"/" \
47                        -e "s/^ *I2PUSER=.*/I2PUSER=\"$I2PUSER\"/" \
48                        < $conffile > $conffile.tmp
49                mv -f $conffile.tmp $conffile
50
51        migrate_existing_user(){
52                # Adjust the user/group in /etc/passwd, mainly for upgrades from old packages that didn't
53                # create $I2PSYSUSER as a system group/user
54                usermod -c "I2P Router Daemon" -m -d $I2PHOME -g $I2PSYSUSER -s "/bin/false" \
55                        -l $I2PSYSUSER -e 1 > /dev/null 2>&1
56                echo "Existing user migrated, home directory moved to $I2PHOME"
57        }
58
59        # Create user and group as a system user.
60        adduser --system --quiet --group --home $I2PHOME $I2PSYSUSER || migrate_existing_user
61
62        [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p
63        chown -f -R $I2PSYSUSER:adm /var/log/i2p
64
65        # Has someone set the permissions with dpkg-statoverride? If so, obey them.
66        if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1
67        then
68                chown -f -R $I2PSYSUSER:$I2PSYSUSER $I2PHOME
69                chmod -f u=rwx,g=rxs,o= $I2PHOME
70        fi
71
72        db_stop
73;;
74abort-upgrade|abort-remove|abort-deconfigure)
75        echo "Aborting upgrade"
76        exit 0
77        ;;
78*)
79        echo "postinst called with unknown argument \`$1'" >&2
80                exit 0
81                ;;
82esac
83       
84#DEBHELPER#
85
86exit 0
Note: See TracBrowser for help on using the repository browser.