diff --git a/debian/i2p.config b/debian/i2p.config index 340266dbf..522857c5d 100755 --- a/debian/i2p.config +++ b/debian/i2p.config @@ -3,37 +3,20 @@ conffile="/etc/default/i2p" -get_config_file() -{ - config_field=$1 - db_field=$2 - - if [ -f "$conffile" ] ; then - VALUE="$(grep "^[ ]*$config_field" $conffile | sed -e "s/^$config_field *= *\"\(.*\)\"/\1/g")" - if [ -n "$VALUE" ] ; then - db_set $db_field "$VALUE" - fi - fi -} - . /usr/share/debconf/confmodule -db_version 2.0 -if [ "$1" = configure -o "$1" = reconfigure ] ; then - get_config_file STARTI2P i2p/daemon - get_config_file RUN_DAEMON i2p/daemon - db_input medium i2p/daemon || true - - get_config_file I2PUSER i2p/user - db_input medium i2p/user || true - #db_input high i2p/stop_running_router || true - - db_go - if dpkg --compare-versions "$2" lt 0.8.4-2 ; then - rm -f $conffile - fi +# Load config file if it exists +if [ -e $conffile ]; then + . $conffile + db_set i2p/daemon "$RUN_DAEMON" + db_set i2p/user "$I2PUSER" fi -exit 0 - +db_input medium i2p/daemon || true +db_go +db_get i2p/daemon || true +if [ "$RET" = "true" ]; then + db_input medium i2p/user || true + db_go +fi diff --git a/debian/i2p.default b/debian/i2p.default deleted file mode 100644 index 0bf8a47f0..000000000 --- a/debian/i2p.default +++ /dev/null @@ -1,13 +0,0 @@ -# Defaults for i2p initscript (/etc/init.d/i2p) -# This is a posix shell fragment - -# [automatically edited by postinst, do not change line format ] -# Run 'dpkg-reconfigure -plow i2p' to change these values. - -# I2P daemon. If set to true, i2p will start automatically when -# the computer boots -RUN_DAEMON="false" - -# The user that runs the I2P daemon. By default this is set to i2psvc. -# You may want to change this to use a manually installed I2P profile. -I2PUSER="i2psvc" diff --git a/debian/i2p.init b/debian/i2p.init index 64a302bc5..ef902fb98 100755 --- a/debian/i2p.init +++ b/debian/i2p.init @@ -52,6 +52,11 @@ I2P_ARGS="/etc/i2p/wrapper.config \ # read config file [ -r /etc/default/$NAME ] && . /etc/default/$NAME +if [ -z "$RUN_DAEMON" ]; then + echo "/etc/default/$NAME is not set. Aborting." + exit 1 +fi + case "$RUN_DAEMON" in [NnFf]*) log_action_msg "$DESC daemon disabled in /etc/default/$NAME". diff --git a/debian/i2p.postinst b/debian/i2p.postinst index 690cb4cef..85fac5532 100755 --- a/debian/i2p.postinst +++ b/debian/i2p.postinst @@ -1,29 +1,10 @@ #!/bin/sh -e I2PHOME=/var/lib/i2p -I2P=/usr/share/i2p -I2PUSER=i2psvc +I2PSYSUSER=i2psvc conffile="/etc/default/i2p" -update_config_file() -{ - db_field=$1 - config_field=$2 - - RET=false - db_get $db_field - if [ -n "$RET" ] ; then - if grep -q "^$config_field" $conffile ; then - # keep any admin changes, while replacing the variable content - sed "s/^[ ]*$config_field=\".*\"/$config_field=\"$RET\"/" < $conffile > $conffile.new && - mv $conffile.new $conffile - else - echo "$config_field=\"$RET\"" >> $conffile - fi - fi -} - # Source debconf library -- we have a Depends line # to make sure it is there... . /usr/share/debconf/confmodule @@ -32,68 +13,62 @@ db_version 2.0 case "$1" in configure|reconfigure) - if [ -f $conffile ] ; then - sed -i -e 's/^[ ]*STARTI2P/RUN_DAEMON/g' $conffile - if ! grep -q RUN_DAEMON $conffile ; then - cat << EOF >> $conffile -# I2P daemon. If set to true, I2P will start automatically -# when your computer boots. -RUN_DAEMON="false" -EOF - fi - if ! grep -q I2PUSER $conffile ; then - cat << EOF >> $conffile -# The user that runs the I2P daemon. By default this is set to i2psvc. -# You may want to change this to use a manually installed I2P profile. -I2PUSER="i2psvc" -EOF - fi - else - cat << EOF >> $conffile -# Defaults for i2p initscript (/etc/init.d/i2p) -# This is a posix shell fragment - -# [automatically edited by postinst, do not change line format ] -# Run 'dpkg-reconfigure -plow i2p' to change these values. - -# I2P daemon. If set to true, i2p will start automatically when -# the computer boots -RUN_DAEMON="false" - -# The user that runs the I2P daemon. By default this is set to i2psvc. -# You may want to change this to use a manually installed I2P profile. -I2PUSER="i2psvc" -EOF + if [ ! -e $conffile ]; then + echo "# Defaults for i2p initscript (/etc/init.d/i2p" >> $conffile + echo "# This is a posix shell fragment" >> $conffile + echo >> $conffile + echo "# [automatically edited by postinst, do not change line format ]" >> $conffile + echo "# Run 'dpkg-reconfigure -plow i2p' to change these values." >> $conffile + echo >> $conffile + echo "RUN_DAEMON=" >> $conffile + echo "I2PUSER=" >> $conffile fi - update_config_file i2p/daemon RUN_DAEMON - update_config_file i2p/user I2PUSER + + db_get i2p/daemon + RUN_DAEMON="$RET" + db_get i2p/user + I2PUSER="$RET" + + cp -a -f $conffile $conffile.tmp + + # If the admin deleted or commented some variables but then set them via debconf, + # (re-)add them to the conffile. + test -z "$RUN_DAEMON" || grep -Eq '^ *RUN_DAEMON=' $conffile || \ + echo "RUN_DAEMON=" >> $conffile + test -z "$I2PUSER" || grep -Eq '^ *I2PUSER=' $conffile || \ + echo "I2PUSER=" >> $conffile + + if [ -z $RUN_DAEMON ]; then + RUN_DAEMON="false" + I2PUSER="i2psvc" + fi + + sed -e "s/^ *RUN_DAEMON=.*/RUN_DAEMON=\"$RUN_DAEMON\"/" \ + -e "s/^ *I2PUSER=.*/I2PUSER=\"$I2PUSER\"/" \ + < $conffile > $conffile.tmp + mv -f $conffile.tmp $conffile migrate_existing_user(){ # Adjust the user/group in /etc/passwd, mainly for upgrades from old packages that didn't - # create $I2PUSER as a system group/user - usermod -c "I2P Router Daemon" -m -d $I2PHOME -g $I2PUSER -s "/bin/false" \ - -l $I2PUSER -e 1 > /dev/null 2>&1 + # create $I2PSYSUSER as a system group/user + usermod -c "I2P Router Daemon" -m -d $I2PHOME -g $I2PSYSUSER -s "/bin/false" \ + -l $I2PSYSUSER -e 1 > /dev/null 2>&1 echo "Existing user migrated, home directory moved to $I2PHOME" } # Create user and group as a system user. - adduser --system --quiet --group --home $I2PHOME $I2PUSER || migrate_existing_user + adduser --system --quiet --group --home $I2PHOME $I2PSYSUSER || migrate_existing_user [ -d /var/log/i2p ] || mkdir -m0750 /var/log/i2p - chown -f -R $I2PUSER:adm /var/log/i2p + chown -f -R $I2PSYSUSER:adm /var/log/i2p # Has someone set the permissions with dpkg-statoverride? If so, obey them. if ! dpkg-statoverride --list $I2PHOME > /dev/null 2>&1 then - chown -f -R $I2PUSER:$I2PUSER $I2PHOME + chown -f -R $I2PSYSUSER:$I2PSYSUSER $I2PHOME chmod -f u=rwx,g=rxs,o= $I2PHOME fi - ##if ! dpkg-statoverride --list $I2P > /dev/null - ##then - ## chown -f -R $I2PUSER:$I2PUSER $I2P - ##fi - db_stop ;; abort-upgrade|abort-remove|abort-deconfigure)