blob: 48afa7b27df47069226baed097d9d59d23431572 (
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
|
#!/bin/bash
output_dirname=$1
input_dirname=$2
# make sure "sort" works the way we expect it to
export LC_ALL=C
rpm_dir=/var/lib/rpm
dpkg_dir=/var/lib/dpkg
bin_dir=`readlink -f $0 | xargs dirname`
dpkg=0
rpm=0
if [ "X${output_dirname}" == "X" ] ; then
echo "Need to specify output directory. "
echo " update_distro <output_dir> [<input_dir>]"
exit 1
fi
function process_rpm
{
rpm -q --queryformat="%{NAME} %{VERSION} %{RELEASE} %{ARCH}\n" \
-a --dbpath ${input_dirname} \
> ${output_dirname}/packages
# Use rpm to generate a list like:
# firstpkg # firstpkg.list
# firstpkg /path/to/Afile1
# firstpkg /path/to/Afile2
# secondpkg # secondpkg.list
# secondpkg /path/to/Bfile1
# secondpkg /path/to/Bfile2
# That list can be ran through "sort -u" to elminate
# duplicates within each package, and then the leading
# package names can be stripped off using "sed". That
# gives a list that can be piped into swab_testf, which
# will test each for the existance of each file and
# generate the pkg.list files.
rpm -qa --qf "%{NAME} # ${output_dirname}/%{NAME}.list\n[%{NAME} %{FILENAMES}\n]" \
--dbpath ${input_dirname} | sort -u |
sed -e 's/[^ ]* //' | ${bin_dir}/swab_testf
}
function process_dpkg
{
dpkg-query -W \
--showformat="\${Package} \${Version} 0 \${Architecture}\n" \
--admindir=${input_dirname} > ${output_dirname}/packages
ls -d1 ${input_dirname}/info/*.list |
while read pkg_path ; do
echo "# ${output_dirname}/"`basename ${pkg_path}`
cat ${pkg_path}
done | ${bin_dir}/swab_testf
}
function detect_distro
{
HOST=`grep 'openSUSE\|Fedora\| SUSE\|Red Hat\|Ubuntu' /etc/issue| sed 's/.*\(openSUSE\|Fedora\| SUSE\|Red Hat\|Ubuntu\).*/\1/'`
if [ -z "$HOST" ];then
echo unable to determine host type
exit 1
fi
TEMP=`mktemp`
if [ "$HOST" = "Ubuntu" ]; then
NEWEST=10.04
VER=`cat /etc/issue|head -n1 | awk '{print $2}'`
dpkg-query -l > $TEMP
if [ $? != 0 ];then
echo package listing failed
exit 1
fi
elif [ "$HOST" = "Fedora" ]; then
NEWEST=11
VER=`cat /etc/issue|head -n1 | awk '{print $3}'`
HOST="fedora"
rpm -qa > $TEMP
if [ $? != 0 ];then
echo package listing failed
exit 1
fi
elif [ "$HOST" = "Red Hat" ]; then
HOST="redhat"
release_ver=`rpm -q --queryformat "%{VERSION}" redhat-release`
MAJOR="?"
if [ `echo ${release_ver} | grep 4` ] ; then
MAJOR="4"
MINOR=`cat /etc/issue|head -n1 | sed 's/.*\([0-9]\))/\1/'`
elif [ `echo ${release_ver} | grep 5` ] ; then
MAJOR="5"
MINOR=`cat /etc/redhat-release | sed -e "s/^.*\.//" -e "s/ .*$//"`
fi
VER="${MAJOR}.${MINOR}"
elif [ "$HOST" = " SUSE" ]; then
NEWEST=11.0
HOST="SLED"
VER=`grep SUSE /etc/issue|head -n1 | awk '{print $7}'`
if [ "$VER" = "10" ];then
VER=10.2
fi
rpm -qa > $TEMP
if [ $? != 0 ];then
echo package listing failed
exit 1
fi
elif [ "$HOST" = "openSUSE" ]; then
NEWEST=11.2
VER=`grep SUSE /etc/issue|head -n1 | awk '{print $4}'`
if [ "$VER" = "10" ];then
VER=10.2
fi
rpm -qa > $TEMP
if [ $? != 0 ];then
echo package listing failed
exit 1
fi
else
echo unknown host type -- $HOST
exit 1
fi
W=`tail -n1 /proc/kallsyms |awk '{print $1}'|wc -c`
WIDTH=`echo "($W-1)*4"|bc`
echo $HOST-$VER-${WIDTH}
}
function regenerate_blob
{
echo Reading package directory from ${input_dirname}, writing out to ${output_dirname}
mkdir -p ${output_dirname} || \
( echo "Could not create output directory ${output_dirname}" ; exit )
if [ ${rpm} -eq 1 ] ; then
echo Looks like an RPM distribution to me...
process_rpm
fi
if [ ${dpkg} -eq 1 ] ; then
echo Looks like a dpkg distribution to me...
process_dpkg
fi
echo ${distro_name} > ${output_dirname}/distro
blob_file=${distro_dir}/distro.blob
${bin_dir}/load_distro -d ${output_dirname}
echo ${md5} > ${md5_file}
}
distro_name=`detect_distro`
echo "Distribution is ${distro_name}"
if [ "X${input_dirname}" != "X" ] ; then
rpm_dir=${input_dirname}
dpkg_dir=${input_dirname}
fi
if [ -f ${rpm_dir}/Packages ] ; then
input_dirname=${rpm_dir}
rpm=1
else if [ -f ${dpkg_dir}/status ] ; then
input_dirname=${dpkg_dir}
dpkg=1
else
echo Could not identify distribution.
exit 1
fi
fi
md5_file=${output_dirname}/md5
md5=`ls -lR ${input_dirname} | md5sum | cut -f 1 -d " " `
existing_md5=`cat ${md5_file} 2> /dev/null`
if [ ! "X${md5}" == "X${existing_md5}" ] ; then
echo Regenerating
regenerate_blob
else
echo Existing cache can be used
fi
rm -f ${output_dirname}/*list
|