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

Re: How to move a conffile ?



On Sat, Oct 07, 2000 at 02:00:24PM +0200, Gregor Hoffleit wrote:
> With the next revision of masqmail, I'd like to move the conffile
> /etc/masqmail.conf to /etc/masqmail/masqmail.conf. What's the best way to do
> this ?

I'm sure my way is not the best way, but it is more careful than yours.

> Is it okay if I just change the position in conffiles and then include this
> in the preinst script, or do I have to make more efforts (e.g. announce this
> to the user via debconf) ?

No.  You have to make more efforts.  Here's what I do in X, and so far I
have yet to receive a bug report that claims I got someone's conffile lost
(this, of course, is now the cue for 500 reports against my packages
claiming exactly that :-P).

>     # move config file to new location
>     if [ -e /etc/masqmail.conf ]; then
>         if [ ! -d /etc/masqmail ]; then
>             mkdir /etc/masqmail
>         fi
>         mv -f /etc/masqmail.conf /etc/masqmail/
>     fi

(Simplifed a bit for pedagogical purposes:)

preinst:

if dpkg --compare-versions "$2" lt "4.0"; then
  # /etc/X11/xfs dir renamed to /etc/X11/fs in 4.x
  if [ -d /etc/X11/xfs -a ! -e /etc/X11/fs ]; then
    echo "Note: Moving X font server configuration directory /etc/X11/xfs to /etc/X11/fs."
    mv /etc/X11/xfs /etc/X11/fs
    touch /etc/X11/xfs.moved-by-preinst
  fi
fi

(Yes, I know I should use debconf instead.)

postinst:

# now safe to finish migration started in preinst
if [ -e /etc/X11/xfs.moved-by-preinst ]; then
  rm /etc/X11/xfs.moved-by-preinst
fi

(Yes, I know I can use rm -f; I guess I just like my if statements.)

postrm:

(This is the part most people overlook, because they forget that, yes,
maintainer scripts or package unpacking can fail:)

cleanup () {
  if [ -e /etc/X11/xfs.moved-by-preinst -a -d /etc/X11/fs -a ! -e /etc/X11/xfs ]; then
    mv /etc/X11/fs /etc/X11/xfs
    rm /etc/X11/xfs.moved-by-preinst
  fi;
}

case "$1" in
  remove) ;;
  purge)
    update-rc.d xfs remove > /dev/null 2>&1
    if [ -d /etc/X11/xfs ]; then
      rm -r /etc/X11/xfs
    fi
    ;;
  abort-install|abort-upgrade)
    cleanup
    exit 0
    ;;
  upgrade|failed-upgrade|disappear) exit 0 ;;
esac

-- 
G. Branden Robinson             |    I am sorry, but what you have mistaken
Debian GNU/Linux                |    for malicious intent is nothing more
branden@debian.org              |    than sheer incompetence!
http://www.debian.org/~branden/ |    -- J. L. Rizzo II

Attachment: pgp1X8h1LjPBq.pgp
Description: PGP signature


Reply to: