On Wed, Aug 01, 2007 at 09:11:18AM +0200, Ola Lundqvist wrote:
> On Tue, Jul 31, 2007 at 11:14:37PM +0200, Marc Haber wrote:
> > A different way to implement would mean having suffixes for the
> > variable name in config.d, either FOO_FROMHERE to replace FOO's value
> > for the rest of the cron-apt run, or FOO_HERE to only replace FOO's
> > value for thi action.d item.
> 
> That would be one way, but it seems rather complicated.
> I think we should do something that is backwards compatible as well. :)
> 
> > Please indicate which way you'd prefer, and I'll send a modified
> > patch. I do think that the patch listed above is the easiest one.
> 
> I'm not sure what I prefer. :)
> 
> Maybe I prefer the _HERE approach, but keep the old way that is if
> you change SYSLOGON that is actually changed. So when restoring you
> actually need to check if that the corresponding _HERE value actually
> contain something.

I am afraid that your way of parsing the environment won't work. One
of the difficulties is that one cannot easily distinguish between
"unset variable" and "variable set with a null value", which would be
needed to find out whether a variable is not meant to be overridden
(unset), or meant to be overridden with a null value (empty).

I am therefore afraid that we won't get along without an explicit list
of Variables needed for the override mechanism (since we need to know
which variables to copy into the _THIS variables). In a first step,
$ACTIONF is sourced to initiate the global overrides of the plain
variables. We then copy the contents of FOO to FOO_THIS (which is the
variable that will actually be used by this iteration's code) and
source $ACTIONF again. This time, the FOO_THIS definitions inside
$ACTIONF get in effect.

It was a long day for me, so I might be wrong, but you'll point me
into the right direction.

Suggested (untested) Patch:
--- cron-apt.orig       2007-08-01 23:11:40.000000000 +0200
+++ cron-apt    2007-08-01 23:46:49.000000000 +0200
@@ -482,6 +488,27 @@

 for ACTION in $(run_parts "$ACTIONDIR") ; do
        ACTIONF=$(echo $ACTION | sed "s|$ACTIONDIR/||")
+       # we need this list to start things
+       VARLIST="SYSLOGON MAILON DEBUG EXITON DIFFIGNORE_THIS DIFFONCHANGES"
+
+       # $ACTIONF can override the _THIS variables directly, which will
+       # only hold for this loop, and it can directly override the
+       # unsuffixed variables, which will hold for the rest of this
+       # cron-apt run.
+       # The first source of $ACTIONF will initiate the global override
+       # _before_ we initialize the _THIS variables for this iteration.
+       if [ -f "$ACTIONCONFDIR/$ACTIONF" ] ; then
+           . "$ACTIONCONFDIR/$ACTIONF"
+       fi
+
+       # initialize _THIS variables to original variable value
+       for VAR in $VARLIST; do
+         eval "${VAR}_THIS=$VAR"
+       done
+
+       # the second source of $ACTIONF will not do any harm to global
+       # overrides (they're already in effect), but initiate the _THIS
+       # overrides.
        if [ -f "$ACTIONCONFDIR/$ACTIONF" ] ; then
            . "$ACTIONCONFDIR/$ACTIONF"
        fi
@@ -505,22 +532,22 @@
                        createerrorinfo $ACTIONF

                        # SYSLOG
-                       if [ "$SYSLOGON" = "error" ] || [ "$SYSLOGON" = 
"upgrade" ] ; then
+                       if [ "$SYSLOGON_THIS" = "error" ] || [ "$SYSLOGON_THIS" 
= "upgrade" ] ; then
                            createsysloginfo $ACTIONF
                        fi

                        # MAIL
-                       if [ "$MAILON" = "error" ] || [ "$MAILON" = "upgrade" ] 
; then
+                       if [ "$MAILON_THIS" = "error" ] || [ "$MAILON_THIS" = 
"upgrade" ] ; then
                            createmailinfo $ACTIONF
                        fi

                        # DEBUG
-                       if [ "$DEBUG" = "error" ] ; then
+                       if [ "$DEBUG_THIS" = "error" ] ; then
                            createloginfo $ACTIONF
                        fi

                        # EXIT
-                       if [ "$EXITON" = "error" ] ; then
+                       if [ "$EXITON_THIS" = "error" ] ; then
                            echo exit > "$STATUS"
                            #exit
                        fi
@@ -533,15 +560,15 @@
                            # Upgrade has happend

                            # SYSLOG
-                           if [ "$SYSLOGON" = "upgrade" ] ; then
+                           if [ "$SYSLOGON_THIS" = "upgrade" ] ; then
                                createsysloginfo $ACTIONF
                            fi
                            # MAIL
-                           if [ "$MAILON" = "upgrade" ] ; then
+                           if [ "$MAILON_THIS" = "upgrade" ] ; then
                                createmailinfo $ACTIONF
                            fi
                            # DEBUG
-                           if [ "$DEBUG" = "upgrade" ] ; then
+                           if [ "$DEBUG_THIS" = "upgrade" ] ; then
                                createloginfo $ACTIONF
                            fi
                        fi
@@ -550,46 +577,46 @@
                     # Independent of error or not

                    # SYSLOG
-                   if [ "$SYSLOGON" = "always" ] ; then
+                   if [ "$SYSLOGON_THIS" = "always" ] ; then
                        createsysloginfo $ACTIONF
                    fi
                    # MAIL
-                   if [ "$MAILON" = "always" ] ; then
+                   if [ "$MAILON_THIS" = "always" ] ; then
                        createmailinfo $ACTIONF
                    fi
                    # DEBUG
-                    if [ "$DEBUG" = "verbose" ] || [ "$DEBUG" = "always" ] ; 
then
+                    if [ "$DEBUG_THIS" = "verbose" ] || [ "$DEBUG_THIS" = 
"always" ] ; then
                        createloginfo $ACTIONF
                    fi

                    if grep -qvE '^[[:space:]]*$|CRON-APT' "$TEMP"; then
                        # ---
                        # Now we have output
-                       if [ "$SYSLOGON" = "output" ]; then
+                       if [ "$SYSLOGON_THIS" = "output" ]; then
                            createsysloginfo $ACTIONF
                        fi
-                       if [ "$MAILON" = "output" ]; then
+                       if [ "$MAILON_THIS" = "output" ]; then
                            createmailinfo $ACTIONF
                        fi
-                       if [ "$DEBUG" = "upgrade" ] ; then
+                       if [ "$DEBUG_THIS" = "upgrade" ] ; then
                            createloginfo $ACTIONF
                        fi
                    fi
                    TLINE=$(echo "$LINE" | sed -e "s/[[:space:]]/_/g;" | \
                        tr "/" "-")
-                   if [ -n "$DIFFIGNORE" ]; then
-                       DIFFIGNORELINE="--ignore-matching-lines=$DIFFIGNORE"
+                   if [ -n "$DIFFIGNORE_THIS" ]; then
+                       
DIFFIGNORELINE="--ignore-matching-lines=$DIFFIGNORE_THIS"
                    fi
                    if [ ! -r "$MAILCHDIR/$ACTIONF-$TLINE" ] || ! diff 
$DIFFIGNORELINE -u "$MAILCHDIR/$ACTIONF-$TLINE" "$TEMP" > "$DIFF" ; then
                        cp "$TEMP" "$MAILCHDIR/$ACTIONF-$TLINE"
                        # What to do with diff
                        # OBS! FROM NOW ON "$TEMP" CAN HAVE DIFF INFORMATION IN 
IT!
                        if [ -n "$DIFF" ] && [ -r "$DIFF" ] ; then
-                           if [ "$DIFFONCHANGES" = "only" ] ; then
+                           if [ "$DIFFONCHANGES_THIS" = "only" ] ; then
                                cp "$DIFF" "$TEMP"
-                           elif [ "$DIFFONCHANGES" = "append" ] ; then
+                           elif [ "$DIFFONCHANGES_THIS" = "append" ] ; then
                                cat "$DIFF" >> "$TEMP"
-                           elif [ "$DIFFONCHANGES" = "prepend" ] ; then
+                           elif [ "$DIFFONCHANGES_THIS" = "prepend" ] ; then
                                echo "----- DIFF END HERE -----" >> "$DIFF"
                                cat "$TEMP" >> "$DIFF"
                                mv "$DIFF" "$TEMP"
@@ -600,15 +627,15 @@
                        # We have changes

                        # MAIL
-                       if [ "$MAILON" = "changes" ] ; then
+                       if [ "$MAILON_THIS" = "changes" ] ; then
                            createmailinfo $ACTIONF
                        fi
                        # SYSLOG
-                       if [ "$SYSLOGON" = "changes" ] ; then
+                       if [ "$SYSLOGON_THIS" = "changes" ] ; then
                            createmailinfo $ACTIONF
                        fi
                        # DEBUG
-                       if [ "$DEBUG" = "changes" ] ; then
+                       if [ "$DEBUG_THIS" = "changes" ] ; then
                            createloginfo $ACTIONF
                        fi
                    fi


Greetings
Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Mannheim, Germany  |  lose things."    Winona Ryder | Fon: *49 621 72739834
Nordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to