#!/bin/sh -e # This script can be called in the following ways: # # Before the package is installed: # install # # Before removed package is upgraded: # install # # Before the package is upgraded: # upgrade # # # If postrm fails during upgrade or fails on failed upgrade: # abort-upgrade # Confirm that users are aware that conffile changes will be lost confirm_conffile_stomp() { tempfile=/var/lib/dpkg/bp.$$ trap 'status=$?; rm -f $tempfile; exit $status' 0 perl -000 -ne 'print $x if m/^Package:\s+(\S+\n)/im && ($x=$1) ne "dpkg\n" && m/^Status:.*(unpacked|postinst)/im' \ /var/lib/dpkg/status >$tempfile if [ -s $tempfile ]; then echo " WARNING - have you read the release notes for this upgrade ? The following packages have been unpacked but not yet configured:" echo " "`cat $tempfile` echo -n " If you proceed with the dpkg upgrade with these packages in this state you will LOSE ANY CONFIGURATION CHANGES that have been made to their configuration files. I recommend that you back out of the upgrade now (see below) and then configure each of these packages using: dpkg --configure --force-hold If you do this and it fails for some packages they are broken anyway, in which case you probably don't have that much to lose by going ahead with the upgrade. Type \"yes\" to confirm that you really want to do the upgrade in spite of my warning above; if you give any other response we'll back off the upgrade to give you a chance to fix things. Continue with upgrade despite probable loss of config data ? " read response case "$response" in [Yy][Ee][Ss]) echo "OK, going ahead." ;; *) echo "Aborting dpkg upgrade." exit 1 ;; esac fi rm -f $tempfile } # Confirm that the user isn't upgrading anything else at the same time confirm_singleton() { echo -n " IMPORTANT - you must install this upgrade on its own, not together in the same dpkg run as any other packages. Otherwise you risk losing configuration information. If you say \"no\" to the question below we'll back off the upgrade now, and you can then do it later using: dpkg --install dpkg-0.93.51.deb If you're not sure what to do, say \"no\", and then run that command (with the appropriate dpkg-*.deb filename) from a root shell prompt. Are you installing only the dpkg upgrade in this dpkg run ? [y/n] " read response case "$response" in [yY]*|"") echo "OK, going ahead." ;; *) echo "Aborting dpkg upgrade." exit 1 ;; esac } # Confirm that dselect got split into it's own package confirm_dselect_split() { if [ -x /bin/ps ]; then if ! ps -C dselect >/dev/null; then return fi fi if ! grep "^Package: *dselect$" /var/lib/dpkg/status >/dev/null; then echo -n " IMPORTANT - if you are upgrading this package from within dselect you _MUST_ install the dselect package first. The dselect frontend has been split into a separate \`dselect' package, which has not yet been unpacked onto your system. Continuing the upgrade will mean that dselect will temporarily be removed from your system, if this happens within dselect the upgrade will fail. Type \"yes\" to confirm that you really want to do the upgrade in spite of my warning above (because you're not running dselect, for example); if you give any other response we'll back off the upgrade to give you a change to install the dselect package first. Continue with upgrade despite separation of dselect ? " read response case "$response" in [Yy][Ee][Ss]) echo "OK, going ahead." ;; *) echo "Aborting dpkg upgrade." exit 1 ;; esac fi } # Remove obsolete hd method scripts remove_hd_method() { methoddir=/usr/lib/dpkg/methods/hd if [ -d $methoddir ]; then echo "Removing obsolete $methoddir ..." rm -r $methoddir fi } # Handle upgrades from pre-conffile dpkg.cfg upgrade_dpkg_non_conffile() { if [ -r /etc/dpkg/dpkg.cfg ]; then dpkg_cfg_md5="535552ad5ee9145dbc7a34c264df4e59 /etc/dpkg/dpkg.cfg" if echo "$dpkg_cfg_md5" | md5sum -c >/dev/null 2>&1; then echo "Removing non-modified dpkg.cfg to be replaced by a conffile ..." rm -f /etc/dpkg/dpkg.cfg fi fi } case "$1" in install) ;; upgrade) case "$2" in # Upgrade from non-C dpkg (pre-0.93.50) 0.93.[01234]* | -) echo "" echo "Contemplating upgrade of dpkg from pre-0.93.50 version ..." confirm_conffile_stomp confirm_singleton confirm_dselect_split remove_hd_method ;; # Upgrade from pre-dselect split 0.93.[5678][0-9]* | 1.[023456789]* | 1.1.* | 1.10 | 1.10.[12] ) confirm_dselect_split ;; esac case "$2" in # Upgrade from pre-conffile dpkg.cfg 1.9.21 | 1.10.* ) upgrade_dpkg_non_conffile ;; esac ;; abort-upgrade) ;; *) echo "$0 called with unknown argument \`$1'" 1>&2 exit 1 ;; esac #DEBHELPER# exit 0