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
|
#!/bin/sh -e
# A string that denotes the current version of the package:
version=5.0.0-3
# The name of the file that comes from Compaq's web site:
filename=cxml_ev5-5.0.0-3.alpha.rpm
##############################################################################
# This package doesn't pre-depend on cpio, so if it is being preconfigured
# and cpio is not present, exit. This script will be re-ran when the postinst
# runs.
if [ ! -x /bin/cpio ]; then
exit 0
fi
# This script will check to see if a new file needs to be downloaded, and if
# so will prompt the user to do so.
# Use debconf.
. /usr/share/debconf/confmodule || exit
# Establish the preliminaries.
db_version 2.0
#db_capb 'backup'
# Minimalist rpm2cpio in perl.
# Code taken from http://www.eleves.ens.fr:8080/home/espel/rpm2cpio
rpm2cpio() {
perl -e '
undef $/;
$|=1;
$rpm = <>;
($magic, $major, $minor, undef) = unpack("NCC C90", $rpm);
exit "Not an RPM\n" if $magic != 0xedabeedb;
exit "Not a version 3 RPM\n" if $major != 3;
$rpm = substr($rpm, 96);
while ($rpm ne "") {
$rpm =~ s/^\c@*//s;
($magic, undef, $sections, $bytes) = unpack("N4", $rpm);
$smagic = unpack("n", $rpm);
last if $smagic eq 0x1f8b;
die "Error: header not recognized\n" if $magic != 0x8eade801;
$rpm = substr($rpm, 16*(1+$sections) + $bytes);
}
exit "bogus RPM\n" if $rpm eq "";
open(ZCAT, "|gzip -cd") || die "cannot pipe to gzip\n";
print ZCAT $rpm;
close ZCAT;
' $1
}
# Called if we cannot communicate with the user.
abort() {
# They can't see it..
# Try to leave them a message anyway.
db_fset cxml-ev5/needfile seen false
db_input critical cxml-ev5/needfile || true
db_go
exit 1
}
# Go ahead and check if we're a new upstream or not
if [ ! -e "/usr/lib/compaq/cxml-ev5-version" -o \
"`cat /usr/lib/compaq/cxml-ev5-version 2>/dev/null`" != "$version" ]
then
# It seems these need to be reset on upgrade
db_fset cxml-ev5/intro rpmok false
db_fset cxml-ev5/intro seen false
db_fset cxml-ev5/download_dir seen false
# Loopdee loop
db_fget cxml-ev5/intro rpmok
while [ "$RET" != "true" ]
do
# Check for valid CPU type using Thomas Weyergraf's trick
cputype=`grep "cpu model" /proc/cpuinfo | cut -b 14-`
if [[ ! "$cputype" < "EV6" ]]
then
db_input critical cxml-ev5/wrongcpu || abort
db_go
db_get cxml-ev5/wrongcpu
if [ "$RET" != "true" ]
then
# Tell them to remove this and quit
db_input low cxml-ev5/remove || true
db_go
exit 0
fi
fi
# reset all these.. lala
db_fset cxml-ev5/intro seen false
db_fset cxml-ev5/download_dir seen false
db_input critical cxml-ev5/intro || abort
db_go
# Get response (continue y/n)
db_get cxml-ev5/intro
if [ "$RET" != "true" ]
then
# If No, tell them how to do it later and quit.
db_input low cxml-ev5/later || true
db_go
exit 0
fi
# Otherwise continue
db_subst cxml-ev5/download_dir filename "$filename"
db_beginblock
# ask them where to find the rpm, important
db_input critical cxml-ev5/download_dir || abort
# ask them if we can delete the rpm, lower priority
db_fset cxml-ev5/deletefile seen false
db_input medium cxml-ev5/deletefile || false
db_endblock
db_go || exit 1
# Actually check if rpm is ok, and .. deal with it
db_get cxml-ev5/download_dir
if [ -e "$RET/$filename" ] && (rpm2cpio $RET/$filename | cpio --list >/dev/null 2>&1)
then
# happy days.
db_fset cxml-ev5/intro rpmok true
else
# shit happens
# Display a message and then loop.
db_subst cxml-ev5/badfile filename "$RET/$filename"
db_fset cxml-ev5/badfile seen false
db_input critical cxml-ev5/badfile || exit 1
db_fset cxml-ev5/intro rpmok false
fi
done
else
echo "Not reinstalling cxml-ev5 since our upstream version matches"
echo "the one currently installed."
echo "My upstream version is ${version}, I'm looking at "
echo "/usr/lib/compaq/cxml-ev5-version"
exit 0
fi
|