Frank Küster <[EMAIL PROTECTED]> wrote: > Subject: Re: wwwoffle: Overwrites local configuration upon upgrade > Package: wwwoffle > Version: 2.8e-1 > Severity: serious
I have prepared a patch for an NMU, or for adoption by Paul. This patch is not yet finished and does not yet address all issues (see the changelog). I have attached it, and include it here and discuss some parts. Many thanks to David! diff -Nur wwwoffle-2.8e.orig/debian/wwwoffle.config wwwoffle-2.8e/debian/wwwoffle.config --- wwwoffle-2.8e.orig/debian/wwwoffle.config 2005-04-05 15:13:02.000000000 +0200 +++ wwwoffle-2.8e/debian/wwwoffle.config 2005-04-05 20:00:27.000000000 +0200 @@ -12,23 +12,26 @@ # set defaults in debconf from the config files PARENT_PROXY=$( perl -e '$proxy="";while(<>){if (m,^(\s*<http://[^>a-z0-9]+>)?\s*proxy\s*=\s*(\S+),) {$proxy=$2;}}print $proxy;' /etc/wwwoffle/wwwoffle.conf 2>/dev/null ) +PORT_NUMBER=$( perl -e '$port="";while(<>){if (m/^\s*http-port\s*=\s*(\S+)/){$port=$1}}print $port' /etc/wwwoffle/wwwoffle.conf 2>/dev/null) if [ -z "$PARENT_PROXY" ]; then PARENT_PROXY=none; fi db_set wwwoffle/string_parent_proxy "$PARENT_PROXY" # put config file data into debconf +db_set wwwoffle/string_port_number "$PORT_NUMBER" + This fixes the http-port problem Paolo reported. if [ -s /etc/wwwoffle/wwwoffle.options ]; then if grep -qsx ppp /etc/wwwoffle/wwwoffle.options; then - db_set wwwoffle/use-ppp-interface yes + db_set wwwoffle/use-ppp-interface true else - db_set wwwoffle/use-ppp-interface no + db_set wwwoffle/use-ppp-interface false fi if grep -qsx fetch /etc/wwwoffle/wwwoffle.options; then - db_set wwwoffle/ppp-fetch yes + db_set wwwoffle/ppp-fetch true else - db_set wwwoffle/ppp-fetch no + db_set wwwoffle/ppp-fetch false fi if grep -qsx htdig /etc/wwwoffle/wwwoffle.options; then - db_set wwwoffle/use-htdig yes + db_set wwwoffle/use-htdig true else - db_set wwwoffle/use-htdig no + db_set wwwoffle/use-htdig false fi fi @@ -49,7 +52,7 @@ db_input medium wwwoffle/use-ppp-interface db_go db_get wwwoffle/use-ppp-interface -if [ x"$RET" = xyes ]; then +if [ x"$RET" = xtrue ]; then db_input medium wwwoffle/ppp-fetch fi x=1 This is David's patch. Then comes a patch to init.d which actually addresses #224937, I'm going to send a patch about this to that bug once I actually do the upload, to allow the maintainer to easily back out this one. diff -Nur wwwoffle-2.8e.orig/debian/wwwoffle.init.d wwwoffle-2.8e/debian/wwwoffle.init.d --- wwwoffle-2.8e.orig/debian/wwwoffle.init.d 2005-04-05 15:13:02.000000000 +0200 +++ wwwoffle-2.8e/debian/wwwoffle.init.d 2005-04-05 20:12:45.000000000 +0200 @@ -190,7 +190,7 @@ echo " stopping failed!" exit 1 ;; - force-restart|restart|force-reload) + restart-keepmode) newmode="$mode" # The wwwoffled maybe was already online. if pgrep '^wwwoffled$' >/dev/null; then @@ -210,6 +210,11 @@ $PROGRAM -c $CONFIG -$newmode fi ;; + force-restart|restart|force-reload) + $0 stop + sleep 2 + $0 start + ;; reload) echo -n "Reloading $NAME configuration files..." if start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON; then Now comes the postinst diff -Nur wwwoffle-2.8e.orig/debian/wwwoffle.postinst wwwoffle-2.8e/debian/wwwoffle.postinst --- wwwoffle-2.8e.orig/debian/wwwoffle.postinst 2005-04-05 15:13:02.000000000 +0200 +++ wwwoffle-2.8e/debian/wwwoffle.postinst 2005-04-05 19:44:48.000000000 +0200 @@ -12,7 +12,58 @@ MSGPATH=/etc/wwwoffle/html CONFIG=/etc/wwwoffle/wwwoffle.conf OPTIONS=/etc/wwwoffle/wwwoffle.options +CRONTAB=/etc/cron.d/wwwoffle just moved up LOG=/var/log/wwwoffle-upgrade.log +CONFIG_NEEDS_BACKUP=true +OPTIONS_NEEDS_BACKUP=true Uups, no longer needed - will not be in the attached file. +# make backups of the files we (possibly) change +for file in $CONFIG $OPTIONS $CRONTAB; do + # is there already a backup file from last time? + if [ -f $file.postinst-bak ]; then rm $file.postinst-bak; fi + if [ -f $file ]; then cp $file $file.postinst-bak; fi +done This is for backing up, at one central place. Now come some functions that save error-prone Copy&Paste at many places: +safe_edit_file(){ + # this function allows perl or sed commands to change a file, even if it + # is a symlink + filename="$1" + replacecommand="$2" + tempfile=`mktemp` + eval $replacecommand $filename > $tempfile + if cmp -s $filename $tempfile; then + # if the files are unchanged, remove tempfile; + rm $tempfile + else + #otherwise, cat it into $filename. (We don't move to preserve a possible symlink) + cat $tempfile > $filename + fi +} + +setoption_from_debconf(){ + option="$1" + variable="$2" + template="$3" + + db_get $template + if [ $? -eq 0 -o $? -ge 30 ]; then + eval $variable=$RET + else + eval $variable=unknown + fi + if [ "${!variable}" = "true" ]; then + if grep "^$option" $OPTIONS >/dev/null 2>&1; then + : # already there + else + safe_edit_file $OPTIONS "perl -e 's/^(\s*$option)/# \$1/'" + echo $option >> $OPTIONS + fi + elif [ "${!variable}" = "false" ]; then + safe_edit_file $OPTIONS "perl -e 's/^(\s*$option)/# \$1/'" + else + : # don't touch the existing settings + fi +} if [ "$POSTINST_ARG2" = 2.6d-2 ]; then # fix screwup in version 2.6d-2, where age = line disappeared... @@ -35,11 +86,11 @@ db_fset wwwoffle/ageline_lost seen false db_input critical wwwoffle/ageline_lost else - perl -i.noage -e "while (<>) { print; last if /^Purge\b/; }" \ - -e "while (<>) {" \ - -e "if (/^}/) { print \" # re-inserted by wwwoffle.postinst\n$ageline\n\$_\"; last; }" \ - -e "print; }" \ - -e "while (<>) { print; }" $CONFIG + safe_edit_file $CONFIG "perl -e 'while (<>) { print; last if /^Purge\b/; }' \ + -e 'while (<>) {' \ + -e 'if (/^}/) { print \" # re-inserted by wwwoffle.postinst\n$ageline\n\$_\"; last; }' \ + -e 'print; }' \ + -e 'while (<>) { print; }'" First use of the function, the second argument starts with `"perl' and ends with the `"' at the last line I added. @@ -53,6 +104,8 @@ if [ -z "$oldspooldir" ]; then oldspooldir=/var/cache/wwwoffle elif [ "$oldspooldir" != /var/cache/wwwoffle ]; then + # TODO: needs a test whether the directory exists. Otherwise, a configuration error can lead + # to a dangling symlink In fact the default wwwoffle.conf contains such a configuration error: spool-dir = SPOOLDIR which f*cked up my system several times during the dpkg-reconfigure tests, until I found out that it wasn't an error I introduced... @@ -178,7 +231,8 @@ fi NEW_CONFIG_MADE=true fi -chown proxy:proxy $CONFIG +# moved chown line to the end, to gather them all at one place for easier fixing +#chown proxy:proxy $CONFIG Nothing to add. @@ -254,8 +307,7 @@ if grep -qsw 'cache-control-max-age-0' $CONFIG; then config_version=2.8e fi - perl -i.bak -pe 's/^(\# WWWOFFLE - World Wide Web Offline Explorer - Version).*/$1'" $config_version/" $CONFIG - if cmp -s $CONFIG $CONFIG.bak; then mv -f $CONFIG.bak $CONFIG; fi + safe_edit_file $CONFIG "perl -pe 's/^(# WWWOFFLE - World Wide Web Offline Explorer - Version).*/\$1 $config_version/'" fi again safe_edit_file. Note that bash substitutes $config_version because of the outer surrounding pair of ", it doesn't care about the inner ' pair. echo "config_vers=$config_version; installed_deb_vers=$POSTINST_ARG2; current_vers_file=$current_version_file; current_vers=$current_version" >>$LOG @@ -340,68 +392,34 @@ PASSWD_MATCH='^NO PASSWD CONFIGURED IN DEBCONF$' PASSWD=secret fi -set -e -perl -pi -e "s,$PORTNUMBER_MATCH, http-port = $PORTNUMBER,; \ +set -ex +safe_edit_file $CONFIG "perl -p -e 's,$PORTNUMBER_MATCH, http-port = $PORTNUMBER,; \ s,^\s*spool-dir\s*=.*, spool-dir = /var/cache/wwwoffle,; \ s,^(#|\s*)run-uid\s*=.*, run-uid = proxy,; \ s,^(#|\s*)run-gid\s*=.*, run-gid = proxy,; \ s,$PROXY_MATCH, <\$1://*> proxy = $PROXY,; \ - s,$PASSWD_MATCH, password = $PASSWD,;" \ - $CONFIG - + s,$PASSWD_MATCH, password = $PASSWD,;'" set +e + +# TODO: should not recreate if local admin has removed if [ ! -f $OPTIONS ]; then cp -p /usr/share/wwwoffle/default/wwwoffle.options $OPTIONS fi -cp -p $OPTIONS $OPTIONS.bak one more function use, one as yet unfixed item, and the backup has been done earlier. The following lines have been replaced by a function definition above and by its invocation: -db_get wwwoffle/use-htdig ########################################### -if [ $? -eq 0 -o $? -ge 30 ]; then [...] -fi -db_get wwwoffle/use-ppp-interface ########################################### -if [ $? -eq 0 -o $? -ge 30 ]; then [...] -fi +setoption_from_debconf htdig USE_HTDIG wwwoffle/use-htdig +setoption_from_debconf ppp USE_PPP wwwoffle/use-ppp-interface -if cmp -s $OPTIONS $OPTIONS.bak; then mv -f $OPTIONS.bak $OPTIONS; fi backups all done later -CRONTAB=/etc/cron.d/wwwoffle moved up db_get wwwoffle/fetchfrequency ########################################### rc=$? if [ $rc -eq 0 -o $rc -ge 30 ]; then FREQ="$RET" if [ "$FREQ" != off ]; then - # convert to digits only - FREQ=$( expr "$FREQ" : '\([0-9]*\)' ) removed, done in config as David found @@ -411,13 +429,13 @@ if [ "$FREQ" = off ]; then if [ -s $CRONTAB ]; then # replace only first occurrence of wwwoffle.cron-fetch line - perl -i.bak -pe 'unless($done==1){if(s,^(\s*#\s*)*([^#]*wwwoffle.cron-fetch),# $2,){$done=1;}}' $CRONTAB + safe_edit_file $CRONTAB "perl -pe 'unless($done==1){if(s,^(\s*#\s*)*([^#]*wwwoffle.cron-fetch),# $2,){$done=1;}}'" else ( echo "# min hr dom mon dow" echo "# If you want to disable this, comment out the line" echo "# below (don't simply remove this file)." echo "# */30 * * * * proxy [ -x /etc/wwwoffle/wwwoffle.cron-fetch ] && /etc/wwwoffle/wwwoffle.cron-fetch" - ) > /etc/cron.d/wwwoffle + ) > $CRONTAB fi else if [ -s $CRONTAB ]; then @@ -437,7 +455,7 @@ echo "# If you want to disable this, comment out the line" echo "# below (don't simply remove this file)." echo "*/$FREQ * * * * proxy [ -x /etc/wwwoffle/wwwoffle.cron-fetch ] && /etc/wwwoffle/wwwoffle.cron-fetch" - ) > /etc/cron.d/wwwoffle + ) > $CRONTAB fi fi fi replaced crontab name by variable just for readability @@ -500,6 +520,13 @@ ) ###################################### +# remove backups if unchanged +for file in $CONFIG $OPTIONS $CRONTAB; do + if cmp -s $file $file.postinst-bak; then + rm $file.postinst-bak + fi +done now here they are gathered. # Apparently someone may leave some filehandles open. Without the stop command # postinst may hang. db_stop @@ -513,15 +540,14 @@ echo "Fixing ownership of spooldirs in the background." mkdir -p /var/cache/wwwoffle/temp >/dev/null 2>&1 cd /var/cache/wwwoffle/temp - rm -f nohup.out nohup chown -R proxy:proxy /var/cache/wwwoffle/. /var/lib/wwwoffle/. >/dev/null 2>&1 & sleep 1 - rm -f nohup.out We don't write this file, so we don't remove them. Regards, Frank -- Frank Küster Inst. f. Biochemie der Univ. Zürich Debian Developer
diff -Nur wwwoffle-2.8e.orig/debian/changelog wwwoffle-2.8e/debian/changelog --- wwwoffle-2.8e.orig/debian/changelog 2005-04-05 15:13:02.000000000 +0200 +++ wwwoffle-2.8e/debian/changelog 2005-04-05 20:17:19.000000000 +0200 @@ -1,3 +1,30 @@ +wwwoffle (2.8e-1.1) unstable; urgency=high + + * NMU to fix a release critical bug and get wwwoffle back into sarge. + Many thanks go to David Schmitt <[EMAIL PROTECTED]>. + * wwwoffle.config: + - use true/false instead of yes/no for debconf preseeding. + - get the port number from wwwoffle.conf and put it into the debconf + database before asking + wwwoffle.postinst: + - do not replace symlinks by real files, instead change the symlink + target. + - many other small fixes + - the postinst still creates files if they have been deleted. + This addresses #295060, but does not yet close it because of the last + issue. + * init script: With argument "restart", it now does what is expected, + namely execute itself with stop and then start, and not more. This + (closes: #224937). In the discussion in the bug log it turned out + that in the init script the removed feature of returning to the + previous mode was not used at all. + + Anybody who relied on this feature should fix their scripts to use the + argument "restart-keepmode" instead, and/or ask the maintainer to back + out that fix. + + -- Frank Küster <[EMAIL PROTECTED]> Tue, 5 Apr 2005 20:17:08 +0200 + wwwoffle (2.8e-1) unstable; urgency=low * New upstream version. diff -Nur wwwoffle-2.8e.orig/debian/wwwoffle.config wwwoffle-2.8e/debian/wwwoffle.config --- wwwoffle-2.8e.orig/debian/wwwoffle.config 2005-04-05 15:13:02.000000000 +0200 +++ wwwoffle-2.8e/debian/wwwoffle.config 2005-04-05 20:00:27.000000000 +0200 @@ -12,23 +12,26 @@ # set defaults in debconf from the config files PARENT_PROXY=$( perl -e '$proxy="";while(<>){if (m,^(\s*<http://[^>a-z0-9]+>)?\s*proxy\s*=\s*(\S+),) {$proxy=$2;}}print $proxy;' /etc/wwwoffle/wwwoffle.conf 2>/dev/null ) +PORT_NUMBER=$( perl -e '$port="";while(<>){if (m/^\s*http-port\s*=\s*(\S+)/){$port=$1}}print $port' /etc/wwwoffle/wwwoffle.conf 2>/dev/null) if [ -z "$PARENT_PROXY" ]; then PARENT_PROXY=none; fi db_set wwwoffle/string_parent_proxy "$PARENT_PROXY" # put config file data into debconf +db_set wwwoffle/string_port_number "$PORT_NUMBER" + if [ -s /etc/wwwoffle/wwwoffle.options ]; then if grep -qsx ppp /etc/wwwoffle/wwwoffle.options; then - db_set wwwoffle/use-ppp-interface yes + db_set wwwoffle/use-ppp-interface true else - db_set wwwoffle/use-ppp-interface no + db_set wwwoffle/use-ppp-interface false fi if grep -qsx fetch /etc/wwwoffle/wwwoffle.options; then - db_set wwwoffle/ppp-fetch yes + db_set wwwoffle/ppp-fetch true else - db_set wwwoffle/ppp-fetch no + db_set wwwoffle/ppp-fetch false fi if grep -qsx htdig /etc/wwwoffle/wwwoffle.options; then - db_set wwwoffle/use-htdig yes + db_set wwwoffle/use-htdig true else - db_set wwwoffle/use-htdig no + db_set wwwoffle/use-htdig false fi fi @@ -49,7 +52,7 @@ db_input medium wwwoffle/use-ppp-interface db_go db_get wwwoffle/use-ppp-interface -if [ x"$RET" = xyes ]; then +if [ x"$RET" = xtrue ]; then db_input medium wwwoffle/ppp-fetch fi x=1 diff -Nur wwwoffle-2.8e.orig/debian/wwwoffle.init.d wwwoffle-2.8e/debian/wwwoffle.init.d --- wwwoffle-2.8e.orig/debian/wwwoffle.init.d 2005-04-05 15:13:02.000000000 +0200 +++ wwwoffle-2.8e/debian/wwwoffle.init.d 2005-04-05 20:12:45.000000000 +0200 @@ -190,7 +190,7 @@ echo " stopping failed!" exit 1 ;; - force-restart|restart|force-reload) + restart-keepmode) newmode="$mode" # The wwwoffled maybe was already online. if pgrep '^wwwoffled$' >/dev/null; then @@ -210,6 +210,11 @@ $PROGRAM -c $CONFIG -$newmode fi ;; + force-restart|restart|force-reload) + $0 stop + sleep 2 + $0 start + ;; reload) echo -n "Reloading $NAME configuration files..." if start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON; then diff -Nur wwwoffle-2.8e.orig/debian/wwwoffle.postinst wwwoffle-2.8e/debian/wwwoffle.postinst --- wwwoffle-2.8e.orig/debian/wwwoffle.postinst 2005-04-05 15:13:02.000000000 +0200 +++ wwwoffle-2.8e/debian/wwwoffle.postinst 2005-04-05 20:38:22.000000000 +0200 @@ -12,8 +12,57 @@ MSGPATH=/etc/wwwoffle/html CONFIG=/etc/wwwoffle/wwwoffle.conf OPTIONS=/etc/wwwoffle/wwwoffle.options +CRONTAB=/etc/cron.d/wwwoffle LOG=/var/log/wwwoffle-upgrade.log +# make backups of the files we (possibly) change +for file in $CONFIG $OPTIONS $CRONTAB; do + # is there already a backup file from last time? + if [ -f $file.postinst-bak ]; then rm $file.postinst-bak; fi + if [ -f $file ]; then cp $file $file.postinst-bak; fi +done + +safe_edit_file(){ + # this function allows perl or sed commands to change a file, even if it + # is a symlink + filename="$1" + replacecommand="$2" + tempfile=`mktemp` + eval $replacecommand $filename > $tempfile + if cmp -s $filename $tempfile; then + # if the files are unchanged, remove tempfile; + rm $tempfile + else + #otherwise, cat it into $filename. (We don't move to preserve a possible symlink) + cat $tempfile > $filename + fi +} + +setoption_from_debconf(){ + option="$1" + variable="$2" + template="$3" + + db_get $template + if [ $? -eq 0 -o $? -ge 30 ]; then + eval $variable=$RET + else + eval $variable=unknown + fi + if [ "${!variable}" = "true" ]; then + if grep "^$option" $OPTIONS >/dev/null 2>&1; then + : # already there + else + safe_edit_file $OPTIONS "perl -e 's/^(\s*$option)/# \$1/'" + echo $option >> $OPTIONS + fi + elif [ "${!variable}" = "false" ]; then + safe_edit_file $OPTIONS "perl -e 's/^(\s*$option)/# \$1/'" + else + : # don't touch the existing settings + fi +} + if [ "$POSTINST_ARG2" = 2.6d-2 ]; then # fix screwup in version 2.6d-2, where age = line disappeared... set +e @@ -35,11 +84,11 @@ db_fset wwwoffle/ageline_lost seen false db_input critical wwwoffle/ageline_lost else - perl -i.noage -e "while (<>) { print; last if /^Purge\b/; }" \ - -e "while (<>) {" \ - -e "if (/^}/) { print \" # re-inserted by wwwoffle.postinst\n$ageline\n\$_\"; last; }" \ - -e "print; }" \ - -e "while (<>) { print; }" $CONFIG + safe_edit_file $CONFIG "perl -e 'while (<>) { print; last if /^Purge\b/; }' \ + -e 'while (<>) {' \ + -e 'if (/^}/) { print \" # re-inserted by wwwoffle.postinst\n$ageline\n\$_\"; last; }' \ + -e 'print; }' \ + -e 'while (<>) { print; }'" db_subst wwwoffle/ageline_added AGELINE "$ageline" db_fset wwwoffle/ageline_added seen false db_input critical wwwoffle/ageline_added @@ -53,6 +102,8 @@ if [ -z "$oldspooldir" ]; then oldspooldir=/var/cache/wwwoffle elif [ "$oldspooldir" != /var/cache/wwwoffle ]; then + # TODO: needs a test whether the directory exists. Otherwise, a configuration error can lead + # to a dangling symlink echo "Fixing up user's preference of spool-dir" echo -n "(adding symlink to it as /var/cache/wwwoffle)... " # try to remove in case of symlink @@ -178,7 +229,8 @@ fi NEW_CONFIG_MADE=true fi -chown proxy:proxy $CONFIG +# moved chown line to the end, to gather them all at one place for easier fixing +#chown proxy:proxy $CONFIG # Old wwwoffle versions (2.3) had a directory here. We have to remove it # before we place our symlink to this location. @@ -203,8 +255,7 @@ # non-existent file. for i in gif png js; do - if [ ! -f /etc/wwwoffle/debian-replacement.$i ]; then - rm -f /etc/wwwoffle/debian-replacement.$i + if [ ! -e /etc/wwwoffle/debian-replacement.$i ]; then ln -s /usr/share/wwwoffle/html/en/local/dontget/standard.replacement.$i /etc/wwwoffle/debian-replacement.$i fi done @@ -254,8 +305,7 @@ if grep -qsw 'cache-control-max-age-0' $CONFIG; then config_version=2.8e fi - perl -i.bak -pe 's/^(\# WWWOFFLE - World Wide Web Offline Explorer - Version).*/$1'" $config_version/" $CONFIG - if cmp -s $CONFIG $CONFIG.bak; then mv -f $CONFIG.bak $CONFIG; fi + safe_edit_file $CONFIG "perl -pe 's/^(# WWWOFFLE - World Wide Web Offline Explorer - Version).*/\$1 $config_version/'" fi echo "config_vers=$config_version; installed_deb_vers=$POSTINST_ARG2; current_vers_file=$current_version_file; current_vers=$current_version" >>$LOG @@ -340,68 +390,28 @@ PASSWD_MATCH='^NO PASSWD CONFIGURED IN DEBCONF$' PASSWD=secret fi -set -e -perl -pi -e "s,$PORTNUMBER_MATCH, http-port = $PORTNUMBER,; \ +set -ex +safe_edit_file $CONFIG "perl -p -e 's,$PORTNUMBER_MATCH, http-port = $PORTNUMBER,; \ s,^\s*spool-dir\s*=.*, spool-dir = /var/cache/wwwoffle,; \ s,^(#|\s*)run-uid\s*=.*, run-uid = proxy,; \ s,^(#|\s*)run-gid\s*=.*, run-gid = proxy,; \ s,$PROXY_MATCH, <\$1://*> proxy = $PROXY,; \ - s,$PASSWD_MATCH, password = $PASSWD,;" \ - $CONFIG - + s,$PASSWD_MATCH, password = $PASSWD,;'" set +e + +# TODO: should not recreate if local admin has removed if [ ! -f $OPTIONS ]; then cp -p /usr/share/wwwoffle/default/wwwoffle.options $OPTIONS fi -cp -p $OPTIONS $OPTIONS.bak -db_get wwwoffle/use-htdig ########################################### -if [ $? -eq 0 -o $? -ge 30 ]; then - USE_HTDIG=$RET -else - USE_HTDIG=unknown -fi -if [ "$USE_HTDIG" = "true" ]; then - if grep '^htdig' $OPTIONS >/dev/null 2>&1 ; then - : # already there - else - perl -i -e 'while (<>) { next if /htdig/; print; }' $OPTIONS - echo htdig >> $OPTIONS - fi -elif [ "$USE_HTDIG" = "false" ]; then - perl -i -e 'while (<>) { next if /htdig/; print; }' $OPTIONS -else - : # don't touch the existing settings -fi -db_get wwwoffle/use-ppp-interface ########################################### -if [ $? -eq 0 -o $? -ge 30 ]; then - USE_PPP=$RET -else - USE_PPP=unknown -fi -if [ "$USE_PPP" = "true" ]; then - if grep '^PPP' $OPTIONS >/dev/null 2>&1 ; then - : # already there - else - perl -i -e 'while (<>) { next if /ppp/; print; }' $OPTIONS - echo ppp >> $OPTIONS - fi -elif [ "$USE_HTDIG" = "false" ]; then - perl -i -e 'while (<>) { next if /ppp/; print; }' $OPTIONS -else - : # don't touch the existing settings -fi +setoption_from_debconf htdig USE_HTDIG wwwoffle/use-htdig +setoption_from_debconf ppp USE_PPP wwwoffle/use-ppp-interface -if cmp -s $OPTIONS $OPTIONS.bak; then mv -f $OPTIONS.bak $OPTIONS; fi - -CRONTAB=/etc/cron.d/wwwoffle db_get wwwoffle/fetchfrequency ########################################### rc=$? if [ $rc -eq 0 -o $rc -ge 30 ]; then FREQ="$RET" if [ "$FREQ" != off ]; then - # convert to digits only - FREQ=$( expr "$FREQ" : '\([0-9]*\)' ) if [ -z "$FREQ" ] then FREQ=off elif [ "$FREQ" = 0 ] @@ -411,13 +421,13 @@ if [ "$FREQ" = off ]; then if [ -s $CRONTAB ]; then # replace only first occurrence of wwwoffle.cron-fetch line - perl -i.bak -pe 'unless($done==1){if(s,^(\s*#\s*)*([^#]*wwwoffle.cron-fetch),# $2,){$done=1;}}' $CRONTAB + safe_edit_file $CRONTAB "perl -pe 'unless($done==1){if(s,^(\s*#\s*)*([^#]*wwwoffle.cron-fetch),# $2,){$done=1;}}'" else ( echo "# min hr dom mon dow" echo "# If you want to disable this, comment out the line" echo "# below (don't simply remove this file)." echo "# */30 * * * * proxy [ -x /etc/wwwoffle/wwwoffle.cron-fetch ] && /etc/wwwoffle/wwwoffle.cron-fetch" - ) > /etc/cron.d/wwwoffle + ) > $CRONTAB fi else if [ -s $CRONTAB ]; then @@ -437,7 +447,7 @@ echo "# If you want to disable this, comment out the line" echo "# below (don't simply remove this file)." echo "*/$FREQ * * * * proxy [ -x /etc/wwwoffle/wwwoffle.cron-fetch ] && /etc/wwwoffle/wwwoffle.cron-fetch" - ) > /etc/cron.d/wwwoffle + ) > $CRONTAB fi fi fi @@ -500,6 +510,13 @@ ) ###################################### +# remove backups if unchanged +for file in $CONFIG $OPTIONS $CRONTAB; do + if cmp -s $file $file.postinst-bak; then + rm $file.postinst-bak + fi +done + # Apparently someone may leave some filehandles open. Without the stop command # postinst may hang. db_stop @@ -513,15 +530,14 @@ echo "Fixing ownership of spooldirs in the background." mkdir -p /var/cache/wwwoffle/temp >/dev/null 2>&1 cd /var/cache/wwwoffle/temp - rm -f nohup.out nohup chown -R proxy:proxy /var/cache/wwwoffle/. /var/lib/wwwoffle/. >/dev/null 2>&1 & sleep 1 - rm -f nohup.out ##fi # hide password in all cases chmod 0640 ${CONFIG}*; chown proxy:proxy ${CONFIG}* +chown proxy:proxy $CONFIG # directory needs to be writable by owner proxy chown proxy /etc/wwwoffle chmod u+w /etc/wwwoffle