also sprach Jelle de Jong <jelledej...@powercraft.nl> [2011.07.08.2100 +0200]:
> @@ -236,9 +237,10 @@
>      thingstoremove+=("$tempfile")
>      trap 'rm -f "${thingstoremove[@]}"' 0 1 2 3 15;
>      [ -z "$tempfile" ] && exit 1
> -    files="$SYSCONF"
> +    [ -r "$USERCONF" ] && files+="$USERCONF"
>      files+=$'\n'
>      files+=$(run-parts --list "$SYSDIR" )
> +    [ -r "$SYSCONF" ] && files+=$'\n'"$SYSCONF"
>      if [ -n "$files" ]; then
>          while read file; do
>              set +e

Please consider the following patch to simplify things, but read on
below!

--- /tmp/pct-scanner-script     2011-07-08 21:19:55.731037910 +0200
+++ /usr/bin/pct-scanner-script 2011-07-08 21:22:07.174316546 +0200
@@ -229,20 +229,15 @@
     tempfile=$(mktemp -p "/tmp/" tempfile.XXXXXXXXXX)
     trap "rm -f $tempfile" 0 1 2 3 15
     [ -z "$tempfile" ] && exit 1
-    [ -r "$USERCONF" ] && files+="$USERCONF"
-    files+=$'\n'
-    files+=$(run-parts --list "$SYSDIR" )
-    [ -r "$SYSCONF" ] && files+=$'\n'"$SYSCONF"
-    if [ -n "$files" ]; then
-        while read file; do
-            set +e
-            [ ! -r "$file" ] && continue
-            sed -n '/^\['"$section"'\]$/,/^\[.*\]$/{//!p}' "$file" > 
"$tempfile"
-            scan_configuration "$tempfile"
-            . "$tempfile"
-            set -e
-        done < <(echo "$files")
-    fi
+    files=("$USERCONF" $(run-parts --list "$SYSDIR" ) "$SYSCONF")
+    for file in $files; do
+        set +e
+        [ ! -r "$file" ] && continue
+        sed -n '/^\['"$section"'\]$/,/^\[.*\]$/{//!p}' "$file" > "$tempfile"
+        scan_configuration "$tempfile"
+        . "$tempfile"
+        set -e
+    done
 }
 
 function check_dependencies()



I still do not think this is right. You are suggesting that your
configuration system works on a first-come-first-serve basis, i.e.
earlier configuration files overrride later configuration files
(else you would source the userconf last!). However, run-parts will
return a list increasing in "priority".

I suggest that you rework this to read SYSCONF before run-parts
before USERCONF. You do not need any
"unless-variable-is-already-set" logic because of the use of shell
variables. For instance:

  SYSCONF:
    [lineart]
    RESOLUTION=300

  SYSCONF.D/50-CONFIG:
    [lineart]
    RESOLUTION=900

  USERCONF;
    [lineart]
    RESOLUTION=1200

    [lineart-madduck]
    RESOLUTION=2400


If I invoke --lineart, RESOLUTION should be 900.

If I invoke --lineart --config madduck, RESOLUTION should be 1200.

Right?

In this case use sed (as you currently do) to select the applicable
config stanza, and then just source (with the '.' command) the
snippets.

Ideally, just iterate the configuration files in the suggested order
and use sed to cut out the configuration under the [stanzas]. Just
write it all to a tempfile, which will then contain:

  RESOLUTION=300
  RESOLUTION=900
  RESOLUTION=1200
  RESOLUTION=2400

and source it.

By the magic of shell, when invoked with --lineart, RESOLUTION will
be 2400 if [lineart-madduck] was included (i.e. if --config madduck
was passed), or 1200 if it was not.

And this should work exactly the same for all variables.

If you want to go one step further:

Since SYSCONF includes a call to $(scanadf …) (which is slow), you
could merge new configuration items into the tempfile, overwriting
existing ones. Finally, source the file ('.'). If the user overwrote
DEVICE, then his/her value will be used, and the call to $(scanadf …)
will not happen.

-- 
 .''`.   martin f. krafft <madduck@d.o>      Related projects:
: :'  :  proud Debian developer               http://debiansystem.info
`. `'`   http://people.debian.org/~madduck    http://vcs-pkg.org
  `-  Debian - when you have better things to do than fixing systems
 
the english take english for granted.
but if we explore its paradoxes,
we find that quicksand can work slowly.

Attachment: digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)

Reply via email to