summaryrefslogtreecommitdiff
path: root/debian/dpkg.preinst
blob: 66805b9ec3fda927258e22ab9aaa6a4121b708e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh -e
# This script can be called in the following ways:
#
# Before the package is installed:
#	<new-preinst> install
#
# Before removed package is upgraded:
#	<new-preinst> install <old-version>
#
# Before the package is upgraded:
#	<new-preinst> upgrade <old-version>
#
#
# If postrm fails during upgrade or fails on failed upgrade:
#	<old-preinst> abort-upgrade <new-version>


# 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 <package>

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