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

Re: how to move a config file during package upgrade



On Wed, Jan 02, 2002 at 03:17:09PM +0100, Wichert Akkerman wrote:
> Previously Thomas Lange wrote:
> > my package fai will have a new location for its configuration file
> > /etc/fai.conf. The next version will use /etc/fai/fai.conf. How can I
> > handle this in a preinst script during an upgrade ? Any examples would
> > be fine.
> 
> Move it in the preinst.
> 

This'll surely give you problems if the installation is aborted for
any reason, you have no way to unwind.

So copy your file to the new location in preinst and delete the file in the old location in the postinst.

This is what I did for crafty:

- from preinst:

#! /bin/sh
# preinst script for crafty
#

case "$1" in
    install|upgrade)
# In the beginning Crafty did not allow for a global resource file.  So,
# a "/etc/craftyrc" file was hacked.  Later, Crafty added support
# for a file called "/etc/crafty.rc".  This move is simply to bring
# users of earlier packages up to speed with the new packages.
#
    if [ -e /etc/craftyrc -a ! -e /etc/crafty.rc ]
    then
    echo "Moving /etc/craftyrc to /etc/crafty.rc"
#We first copy the file, it'll be removed in postinst. This allows us to
#unwind if install/upgrade fails or is aborted.
    cp /etc/craftyrc /etc/crafty.rc
    fi

    abort-upgrade)

    if [ -e /etc/craftyrc -a -e /etc/crafty.rc ]
    then
    rm /etc/crafty.rc
    fi

        ;;

    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac


- the postinst:

case "$1" in
    configure)

#In previous versions, crafty used /etc/craftyrc as a global config file. It's
#now been moved to /etc/crafty.rc
#We remove the file we copied in preinst
        if [ -e /etc/crafty.rc -a -e /etc/craftyrc ]
        then
        rm /etc/craftyrc
        fi
    ;;

    abort-upgrade)
#If upgrade fails, then let the files where they were before install/upgrade
#(cancel the 'move' stuff initiated in preinst).
        if [ -e /etc/craftyrc -a -e /etc/crafty.rc ]
        then
        rm /etc/crafty.rc
        fi
        ;;
   *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

-- 
Eric VAN BUGGENHAUT     "Hay tampones y tampones..." (Eva Serrano)
			Andago
        \_|_/           Av. Santa Engracia, 54
       \/   \/          E-28010 Madrid - tfno:+34(91)2041100
a n d a g o  |--        http://www.andago.com
       /\___/\ 		"Innovando en Internet"
        / | \           eric@andago.com



Reply to: