Ignore:
Timestamp:
Aug 25, 2011 9:33:06 PM (9 years ago)
Author:
kytv <kytv@…>
Branches:
master
Children:
5f6efbf, ab58875, c243f21b
Parents:
bb5f3a9
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • debian/i2p.postinst

    rbb5f3a9 rf674b78  
    22
    33I2PHOME=/var/lib/i2p
    4 I2P=/usr/share/i2p
    5 I2PUSER=i2psvc
     4I2PSYSUSER=i2psvc
    65
    76conffile="/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 }
    267
    278# Source debconf library -- we have a Depends line
     
    3314case "$1" in
    3415        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
     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
    5526
    56 # [automatically edited by postinst, do not change line format ]
    57 # Run 'dpkg-reconfigure -plow i2p' to change these values.
     27                db_get i2p/daemon
     28                RUN_DAEMON="$RET"
     29                db_get i2p/user
     30                I2PUSER="$RET"
    5831
    59 # I2P daemon. If set to true, i2p will start automatically when
    60 # the computer boots
    61 RUN_DAEMON="false"
     32                cp -a -f $conffile $conffile.tmp
    6233
    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
     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"
    6744                fi
    68         update_config_file i2p/daemon   RUN_DAEMON
    69         update_config_file i2p/user     I2PUSER
     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
    7050
    7151        migrate_existing_user(){
    7252                # 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
     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
    7656                echo "Existing user migrated, home directory moved to $I2PHOME"
    7757        }
    7858
    7959        # Create user and group as a system user.
    80         adduser --system --quiet --group --home $I2PHOME $I2PUSER || migrate_existing_user
     60        adduser --system --quiet --group --home $I2PHOME $I2PSYSUSER || migrate_existing_user
    8161
    8262        [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p
    83         chown -f -R $I2PUSER:adm /var/log/i2p
     63        chown -f -R $I2PSYSUSER:adm /var/log/i2p
    8464
    8565        # Has someone set the permissions with dpkg-statoverride? If so, obey them.
    8666        if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1
    8767        then
    88                 chown -f -R $I2PUSER:$I2PUSER $I2PHOME
     68                chown -f -R $I2PSYSUSER:$I2PSYSUSER $I2PHOME
    8969                chmod -f u=rwx,g=rxs,o= $I2PHOME
    9070        fi
    91 
    92         ##if ! dpkg-statoverride --list $I2P > /dev/null
    93         ##then
    94         ##      chown -f -R $I2PUSER:$I2PUSER $I2P
    95         ##fi 
    9671
    9772        db_stop
Note: See TracChangeset for help on using the changeset viewer.