[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

preseed/include* substitution



Hi,

Laying awake last night, it occurs to me that I could make my preseed setup
much simpler if we added a small feature to the processing of
preseed/include* settings.

The idea is that we indicate in some way that the file retrieved should be
executed, and it's output used as the preseed file, rather than the file
itself.

For example, we could treat filenames containing a pipe (|) as the last
character as something to execute.

So, taking an example from my preseed stuff, we might have:

  d-i preseed/include string chain_to_preseed2.sh|

with chain_to_preseed2.sh containing:

=-=-=-=-
#/bin/sh

# check to see if the top directory of the preseed setup was set
url="$(debconf-get local/cfg|cut -sd';' -f3)"

# this is the default, if none is specified on the command line
[ -z "$url" ] && url="http://hands.com/d-i";

# if we're already doing a preseed/url, just daisy-chain onto
# preseed2.cfg with an include, otherwise set preseed/url
if [ -n "$(debconf-get preseed/url)" ] ; then
  echo "d-i preseed/include string preseed2.cfg"
else
  echo "d-i preseed/url string $url/preseed2.cfg"
fi
=-=-=-=-

which would achieve the same result as the existing:

d-i     preseed/include_command string ( set -x; url="$(debconf-get
local/cfg|cut -sd';' -f3)" ; [ -z "$url" ] && url="http://hands.com/d-i"; ;
 if [ -n "$(debconf-get preseed/url)" ] ; then echo preseed2.cfg ; else
echo "x preseed/url x $url/preseed2.cfg" > /tmp/preseed-url.set;
debconf-set-selections /tmp/preseed-url.set; fi )

but is a lot more readable.

This should be implementable with the following (totally untested, off the
top of my head) patch:

=-=-=-
--- lib/preseed/preseed.sh      Thu Jan  1 01:00:00 1970
+++ lib/preseed/preseed.sh-with-subst     Sat Jul  2 10:41:13 2005
@@ -20,9 +20,21 @@

        local tmp=/tmp/debconf-seed
        local logfile=/var/log/debconf-seed
+       local subst=0
+
+       if x=$expr "$location" : "\(.*\)|$"); then
+         subst=1
+         location="$x"
+       fi

        if ! preseed_fetch $location $tmp; then
                error retrieve_error "$location"
+       fi
+
+       if [ 1 = "$subst" ]; then
+         mv $tmp $tmp.subst
+         chmod +x $tmp.subst
+         $tmp.subst > $tmp || error substitution_error "$location"
        fi

        db_set preseed/include ""
=-=-=-

I've not got time to try this out now, but might have next week, in which
case I'll patch my initrds and try reimplementing my setup to see if it's a
big win.

Cheers, Phil.

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: