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

RE: debconf question



Hello

thanks for your answer

> If there's only host and port in your config file, don't try
> to re-read it in your postinst. What you have done in your
> config script should be enough to read the value that was
> previously in the config file, or the one that was set using
> debconf (with priority to what has been change in debconf,
> which is what you've done already).

Yes there is only one variable in the config file (for now).
I instrumented the code and I found that the config script was run
two times before the postinst when installing my package with dbconfig-common.
so it seems that my config script was not ...potent.
I decided to use the fget with the seen attribute to not override the
first user choice. I put the new script at the end of this mail.
If the question was not already seen, set the default value using the hostname
if not do nothing.

It seems to me that it is quite similar to your proposition.
Nevertheless some feed back comparing both solution would be interesting.
I do not now if a reconfiguration is ok with my solution.

thanks frederic


> So instead of the above postinst, just overwrite the config
> file this way:
>
> debian/config:
> =========
> #!/bin/sh
>
> set -e
>
> CONFIGFILE=/etc/tangorc
>
> . /usr/share/debconf/confmodule
>
> # Use what may have been set durring a pre-seed
> # operation, so we don't overwrite something that
> # may have been previously set.
> RET=""
> db_get tango-common/tango-host || true
> if [ -n "${RET}" ] ; then
>	TANGO_HOST=$RET
> fi
>
> # Load config file, if it exists.
> # This should populate $TANGO_HOST
> # if the variable is set in the
> # configuration file
> if [ -f $CONFIGFILE ]; then
>	. $CONFIGFILE || true
> fi
>
>
> # Set $TANGO_HOST with a value if
> # we don't find any so far
> if [ -z "$TANGO_HOST" ] ; then
>	TANGO_HOST=$(hostname -f)":10000"
> fi
>
> # Set the value with something, always,
> # because at this point, we really should
> # have a value in $TANGO_HOST
> db_set tango-common/tango-host $TANGO_HOST
>
> # Now that we have either the default value
> # or what was set in the config file, let's
> # tell Debconf that we want it to prompt the
> # user for a change.
> db_input high tango-common/tango-host || true
> db_go || true
>
>
> debian/postinst:
> ================
> #!/bin/sh
> CONFIGFILE=/etc/tangorc
> set -e
> . /usr/share/debconf/confmodule
>
> # As we have always set a value in debconf,
> # even in non-interactive mode we will have
> # somethinga to use there
> db_get tango-common/tango-host
> TANGO_HOST=$RET
> 
> # And as a consequence, we can create a brand
> # new config file (provided that there's no
> # other things in this config file because in
> # that case, we want to make some code to not
> # overwrite them...).
> echo "# Config file for my package" > $CONFIGFILE
> echo "TANGO_HOST=" >> $CONFIGFILE
>
>
> I hope the above helps. As you see, it's a way
> more simple than what you tried to do. I have
> to highlight that this is not always the solution,
> there might be some other ways, but the above
> does worked for me in some of my packages, and
> it respects the policy (which is: always read
> what is in the config file and keep what the
> admin may have change, works also in non-interactive,
> provide working defaults).
>
> I'd appreciate another DD comment on this.
>
> Thomas Goirand



   1 #!/bin/sh
   2 CONFIGFILE=/etc/tangorc
   3 set -e
   4 . /usr/share/debconf/confmodule
   5 
   6 # Load config file, if it exists.
   7 if [ -e $CONFIGFILE ]; then
   8     . $CONFIGFILE || true
   9 
  10     # Store values from config file into
  11     # debconf db.
  12     db_set tango-common/tango-host "$TANGO_HOST"
  13 else
  14     if db_fget tango-common/tango-host seen; then
  15         if [ "$RET" = "false" ]; then
  16             db_set tango-common/tango-host $(hostname -f)":10000"
  17         fi
  18     fi
  19 fi
  20 
  21 
  22 # what is the name of the tango host
  23 db_input high tango-common/tango-host || true
  24 db_go || true


Reply to: