-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckPackageConsistency
executable file
·455 lines (391 loc) · 18 KB
/
checkPackageConsistency
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/bin/bash
#
# Script to check the consistency of a single package
#
package="$1"
if [ -z "$package" ]; then
echo "Usage: ./checkPackageConsistency <nameOfPackage>"
echo "nameOfPackage must be one of the package names defined in the DebianBuildVersions repository and must have been built already prior to running this script."
exit 1
fi
package_lc=`echo "$package" | tr '[:upper:]' '[:lower:]'`
WD=`realpath $(dirname "$0")`
cd "$WD"
source functions.sh
declare -A config
# function to extract a variable from a CONFIG file
function getFromConfig() { # arguments: package name, config variable; sets variable in environment ("-" repaces with "_")
value=`getConfigValue "${WD}/DebianBuildVersions/${1}" "${distribution}" ${2}`
name=`echo ${2} | sed -e "s|-|_|g"`
config[$name]=$value
}
# load configuration
source config.sh
# load master-control file
if [ ! -f master-control ]; then
echo "No master_control file found. Run the master script first."
exit 1
fi
source master-control
# preperations for running pbuilder later
LOCAL_REPOS="${WD}/pbuilder-result"
PBUILDER_IMAGE="${WD}/pbuilder-base/base-${distribution}.tgz"
# Check that there are debian packages and return an error if not
if [ ! -d pbuilder-result ]; then
echo "No pbuilder-result directory found. Run the master script first."
exit 1
fi
cd pbuilder-result/dists/${distribution}/main/binary-${arch}
echo "Checking package ${package}..."
# obtain list of sub-packages from the CONFIG file
getFromConfig $package "Has-packages"
# obtain list of dependencies from the CONFIG file
getFromConfig $package "Dependencies"
# obtain flag whether to include the build version in the package name from the CONFIG file
getFromConfig $package "package-name-contains-buildversion"
if [ -z "${config[package_name_contains_buildversion]}" ]; then
config[package_name_contains_buildversion]=1
fi
# obtain epoch version as part of the Debian package name
epoch_version=`echo ${package_buildcmd[$package]} | sed -e "s|^.*${package}/||" -e 's|-[^/].*/||' -e 's|/|-|' -e 's|\.|-|'`
epoch_version_no_buildversion=`echo ${package_buildcmd[$package]} | sed -e "s|^.*${package}/||" -e 's|/.*$||' -e 's|\.|-|'`
# obtain so file version in two different ways and compare
so_version_nopatch=`echo ${package_buildcmd[$package]} | sed -e "s|^.*${package}/||" -e 's|-[^/].*/||' -e 's|/||'`
# This cuts of the potential --preseed argument for the build
mdpconfig="${WD}/`echo ${package_buildcmd[$package]} | sed -e 's|^./makeDebianPackage.*Debian|Debian|'`/makeDebianPackage.config"
so_version="`( source $mdpconfig ; echo $SOVERSION )`"
if [ -z "`echo $so_version | grep ^$so_version_nopatch`" ]; then
echo "The .so file version obtained from the makeDebianPackage.config file and from the master-control file do not match."
echo "The so version (incl. patch level) from the makeDebianPackage.config is: $so_version"
echo "The so version (excl. patch level) from the master-control file is: $so_version_nopatch"
ERROR=1
fi
# check if there is a lib sub-pacakge, in which case we assume a library package
is_library=0
package_prefix=""
if [ -n "`echo \" ${config[Has_packages]} \" | grep \" lib \"`" ]; then
is_library=1
package_prefix="lib"
fi
if [ -n "`echo \" ${config[Has_packages]} \" | grep \" dev-headeronly \"`" ]; then
is_library=1
package_prefix="lib"
fi
if [ -n "`echo \" ${config[Has_packages]} \" | grep \" dev-alien-headeronly \"`" ]; then
is_library=1
package_prefix="lib"
fi
# count number of files checked across calles to this script (needed for the vaildation script)
if [ ! -f "${LOCAL_REPOS}/nDebianFilesChecked.txt" ]; then
echo 0 > "${LOCAL_REPOS}/nDebianFilesChecked.txt"
fi
nDebianFilesChecked=`cat "${LOCAL_REPOS}/nDebianFilesChecked.txt"`
# check if we have the dev-alien sub-package, in which case we need to be less strict
IS_ALIEN=0
for subpackage in ${config[Has_packages]} ; do
if [ $subpackage == "dev-alien" -o $subpackage == "dev-alien-headeronly" ]; then
IS_ALIEN=1
fi
done
# check if we have the dev-noheader-dynload sub-package, in which case we need add a dynload package as well
for subpackage in ${config[Has_packages]} ; do
if [ $subpackage == "dev-noheader-dynload" ]; then
config[Has_packages]+=" dynload"
break
fi
done
# loop over the sub-packages
for subpackage in ${config[Has_packages]} ; do
echo " -> subpackage: $subpackage"
# get name from config, if specified
getFromConfig $package "Package-name-$subpackage"
name=${config[Package_name_${subpackage}]}
# no name specified in the config: build it
if [ -z "${name}" ]; then
package_suffix=""
if [ $subpackage == "dev" -o $subpackage == "doc" -o $subpackage == "extra" -o $subpackage == "extra2" ]; then
package_suffix="-$subpackage"
elif [ $subpackage == "dev-noheader" -o $subpackage == "dev-headeronly" -o $subpackage == "dev-alien" -o $subpackage == "dev-alien-headeronly" -o $subpackage == "dev-noheader-dynload" ]; then
package_suffix="-dev"
elif [ $subpackage == "dkms" ]; then
package_suffix="-dkms"
elif [ $subpackage == "python" -o $subpackage == "dynload" ]; then
package_suffix=""
else
if [ "${config[package_name_contains_buildversion]}" == "1" ]; then
package_suffix="${epoch_version}"
else
package_suffix="${epoch_version_no_buildversion}"
fi
fi
name=${package_prefix}${package_lc}${package_suffix}
# if name was specified, replace #debversion# with the epoch version
else
if [ "${config[package_name_contains_buildversion]}" == "1" ]; then
name=`echo $name | sed -e "s|#debversion#|${epoch_version}|"`
else
name=`echo $name | sed -e "s|#debversion#|${epoch_version_no_buildversion}|"`
fi
fi
# check if there is exacty one .deb file per subpackage
nfiles=`ls ${name}_*.deb 2>/dev/null | wc -l`
if [ $nfiles -gt 1 ]; then
echo "Too many .deb files for package: $name"
ERROR=1
elif [ $nfiles -lt 1 ]; then
echo "Missing .deb file for package: $name"
ERROR=1
fi
# sub-package specific tests:
debname=`echo ${name}_*.deb`
debug_name=`echo ${name}-dbgsym*_*.deb`
if [ ! -f "${debug_name}" ]; then
# on bionic automatic dbgsym packages are called *.ddeb
debug_name=`echo ${name}-dbgsym*_*.ddeb`
fi
package_increment=1
if [ $subpackage == "lib" -a $IS_ALIEN != 1 ]; then
# check for presence of .so file with the right name and version number in the pacakge
so_file=`dpkg -c $debname | grep -i "\./usr/lib.*/lib${package}.so.${so_version}$"`
if [ -z "$so_file" ]; then
echo "Cannot find the .so file in the library pacakge by the name: ./usr/lib.*/lib${package}.so.${so_version}"
ERROR=1
fi
so_link=`dpkg -c $debname | grep -i "\./usr/lib.*/lib${package}.so.${so_version_nopatch} -> lib${package}.so.${so_version}$"`
if [ -z "$so_link" ]; then
echo "Cannot find the link to the .so file in the library pacakge by the name: ./usr/lib.*/lib${package}.so.${so_version_nopatch}"
ERROR=1
fi
# There should be a debug package as well
debug_files=`dpkg -c $debug_name| grep "\./usr/lib.*/debug/.*\.debug" | wc -l`
package_increment=2
echo " -> debug package for subpackage: lib"
if [ "$debug_files" -lt 1 ]; then
echo "Debug package for lib package is empty!"
ERROR=1
fi
elif [ $subpackage == "lib" -a $IS_ALIEN == 1 ]; then
# check for presence of .so file without checking for the exact version
so_file=`dpkg -c $debname | grep -i "\./usr/lib.*/lib${package}.so\..*$"`
if [ -z "$so_file" ]; then
echo "Cannot find the .so file in the library pacakge by the name: ./usr/lib.*/lib*.so.*"
ERROR=1
fi
# There should be a debug package as well
debug_files=`dpkg -c $debug_name| grep "\./usr/lib.*/debug/.*\.debug" | wc -l`
package_increment=2
echo " -> debug package for subpackage: lib"
if [ "$debug_files" -lt 1 ]; then
echo "Debug package for lib package is empty!"
ERROR=1
fi
elif [ $subpackage == "dev" -o $subpackage == "dev-noheader" -o $subpackage == "dev-headeronly" -o $subpackage == "dev-alien" -o $subpackage == "dev-alien-headeronly" -o $subpackage == "dev-noheader-dynload" -o $subpackage == "dynload" ]; then
# check for presence of include files
if [ $subpackage == "dev" -o $subpackage == "dev-headeronly" -o $subpackage == "dev-alien" -o $subpackage == "dev-alien-headeronly" ]; then
n_include_files=`dpkg -c $debname | grep "\./usr/include/" | wc -l`
if [ "$n_include_files" -lt 2 ]; then # 2 is correct since directories (like /usr/include itself) are counted as well
echo "No include files found in the dev package!"
ERROR=1
fi
fi
if [ $subpackage != "dynload" ]; then
# check for presence pkgconfig
n_config_files=`dpkg -c $debname | grep "\./usr/share/pkgconfig/.*\.pc" | wc -l`
if [ "$n_config_files" -ne 1 -a $subpackage != "dev-alien" -a $subpackage != "dev-alien-headeronly" ]; then
echo "Did not find the pkgconfig required for a dev package!"
ERROR=1
fi
# check for presence of cmake package config
n_config_files=`dpkg -c $debname | grep -i "\./usr/lib.*/cmake/${package}/.*\.cmake" | wc -l`
if [ "$n_config_files" -lt 1 -a $subpackage != "dev-alien" -a $subpackage != "dev-alien-headeronly" ]; then
echo "Did not find the cmake find_package config!"
ERROR=1
fi
fi
# check for presence of so link
if [ $subpackage == "dev" -o $subpackage == "dev-noheader" -o $subpackage == "dynload" ]; then
so_link=`dpkg -c $debname | grep -i "\./usr/lib.*/lib${package}\.so -> lib${package}\.so\.${so_version_nopatch}$"`
if [ -z "$so_link" ]; then
echo "Cannot find the link to the .so file in the dev pacakge by the name: ./usr/lib.*/lib${package}.so"
ERROR=1
fi
fi
# check for presence of so link in alien package - do not check for exact target
if [ $subpackage == "dev-alien" ]; then
so_link=`dpkg -c $debname | grep -i "\./usr/lib.*/lib${package}\.so -> lib${package}\.so\..*$"`
if [ -z "$so_link" ]; then
echo "Cannot find the link to the .so file in the dev pacakge by the name: ./usr/lib.*/lib${package}.so"
ERROR=1
fi
fi
# read "Depends:" line from dpkg -I output and parse it into an array (split by commas)
temp=`dpkg -I $debname | grep '^ Depends: ' | sed -e 's|^ Depends: ||'`
IFS=',' read -r -a dpkg_depends <<< "$temp"
# loop over dependencies
haveFoundOurLib=0 # will be set if the dev package depends on our lib package
isInVersionRange=0 # will be set if the found dependency is a package maintained by these scripts and a second
# entry for the same dependency is expected next (to describe an allowed version range)
for dep in "${dpkg_depends[@]}"; do
IFS=' ' read -r -a dep_split <<< "$dep"
if [[ "${dep_split[0]}" == *-dev ]]; then
# dependency on a "-dev" package: check if this is a package maintaned by these scripts
dep_packname=`echo "${dep_split[0]}" | sed -e 's|^lib||' -e 's|-dev$||'`
if [ -d "${WD}/DebianBuildVersions/${dep_packname}" ]; then
# check if the version range is properly specified
if [ $isInVersionRange == 0 ]; then # first of the two entries for this dependency
isInVersionRange=1
if [ ${dep_split[1]} != "(>=" ]; then
echo "The dependency of lib${package}-dev on ${dep_packname} must be limited to a version range but there seems to be no minimum version."
ERROR=1
fi
# extract the specified min version
versionRange_minVersion=`echo ${dep_split[2]} | sed -e 's|)$||'`
else # second of the two entries for this dependency
isInVersionRange=0
if [ ${dep_split[1]} != "(<<" ]; then
echo "The dependency of lib${package}-dev on ${dep_packname} must be limited to a version range but there seems to be no maximum version."
ERROR=1
fi
# extract the specified max version
versionRange_maxVersion=`echo ${dep_split[2]} | sed -e 's|)$||'`
# check if the version range is matching one single epoch version
versionRange_minVersion_epoch=`echo $versionRange_minVersion | sed -e "s|${distribution}.*$||"`
versionRange_minVersion_build=`echo $versionRange_minVersion | sed -e "s|^.*${distribution}||"`
versionRange_maxVersion_expected=${versionRange_minVersion_epoch}${distribution}$(( versionRange_minVersion_build + 1 ))
if [ "$versionRange_maxVersion" != "$versionRange_maxVersion_expected" ]; then
echo "The dependency of lib${package}-dev on ${dep_packname} must be limited to a version range only allowing different patch levels."
fi
fi
fi
fi
done
# There should NOT be a debug package for this
if [ -e $debug_name ] ; then
echo "Unexpected debug file $debug_name found for development package"
ERROR=1
fi
elif [ $subpackage == "doc" ]; then
# check for presence of html files
n_html_files=`dpkg -c $debname | grep -i "\./usr/share/doc/lib${package}${epoch_version}/html/.*\.html" | wc -l`
if [ "$n_html_files" -lt 10 ]; then # note, this is a quite arbitrary number!
echo "Only $n_html_files html files found in the doc package! The validation expects at least 10 (which is arbitrary)."
ERROR=1
fi
# There should NOT be a debug package for this
if [ -e $debug_name ] ; then
echo "Unexpected debug file $debug_name found for doc package"
ERROR=1
fi
elif [ $subpackage == "bin" ]; then
# check for presence of binary files
bin_files=`dpkg -c $debname | grep "\./usr/bin/.*" | wc -l`
if [ "$bin_files" -lt 1 ]; then
echo "No executable files found in the bin package!"
ERROR=1
fi
# check that no -config script has leaked into the bin package
n_config_files=`dpkg -c $debname | grep "\./usr/bin/.*-config" | wc -l`
if [ "$n_config_files" -gt 0 ]; then
echo "The config script from the dev package was found in the bin package!"
ERROR=1
fi
# Bin packages may or may not have a debug package (could contain only scripts). If it has one, check for consistency
if [ -e "$debug_name" ] ; then
debug_files=`dpkg -c $debug_name| grep "\./usr/lib.*/debug/.*\.debug" | wc -l`
package_increment=2
echo " -> debug package for subpackage: bin"
if [ "$debug_files" -lt 1 ]; then
echo "Debug package for bin package is empty!"
ERROR=1
fi
fi
elif [ $subpackage == "extra" -o $subpackage == "extra2" ]; then
# check for presence of files
extra_files=`dpkg -c $debname | wc -l`
if [ "$extra_files" -lt 1 ]; then
echo "No files found in the $subpackage package!"
ERROR=1
fi
# check that no -config script has leaked into the extra package
n_config_files=`dpkg -c $debname | grep "\./usr/bin/.*-config" | wc -l`
if [ "$n_config_files" -gt 0 ]; then
echo "The config script from the dev package was found in the $subpackage package!"
ERROR=1
fi
# May or may not have a debug package. If it has one, check for consistency
if [ -e "$debug_name" ] ; then
debug_files=`dpkg -c $debug_name| grep "\./usr/lib.*/debug/.*\.debug" | wc -l`
package_increment=2
echo " -> debug package for subpackage: $subpackage"
if [ "$debug_files" -lt 1 ]; then
echo "Debug package for $subpackage package is empty!"
ERROR=1
fi
fi
elif [ $subpackage == "python" ]; then
# check for presence of python files
python_files=`dpkg -c $debname | grep "\./usr/lib/python" | wc -l`
if [ "$python_files" -lt 1 ]; then
echo "No files found in the python package!"
ERROR=1
fi
# check that no -config script has leaked into the python package
n_config_files=`dpkg -c $debname | grep "\./usr/bin/.*-config" | wc -l`
if [ "$n_config_files" -gt 0 ]; then
echo "The config script from the dev package was found in the python package!"
ERROR=1
fi
# May or may not have a debug package. If it has one, check for consistency
if [ -e "$debug_name" ] ; then
package_increment=2
echo " -> debug package for subpackage: python"
# There should be a debug package as well
debug_files=`dpkg -c $debug_name| grep "\./usr/lib.*/debug/.*\.debug" | wc -l`
if [ "$debug_files" -lt 1 ]; then
echo "Debug package for python package is empty!"
ERROR=1
fi
fi
elif [ $subpackage == "doocs-bin" ]; then
# check for presence of files in /export/doocs/server/...
bin_files=`dpkg -c $debname | grep "\./export/doocs/server/.*" | wc -l`
if [ "$bin_files" -lt 1 ]; then
echo "No files in the /export/doocs/server directory were found in the bin package!"
ERROR=1
fi
# There should be a debug package as well
debug_files=`dpkg -c $debug_name| grep "\./usr/lib.*/debug/.*\.debug" | wc -l`
package_increment=2
echo " -> debug package for subpackage: doocs-bin"
if [ "$debug_files" -lt 1 ]; then
echo "Debug package for doocs server is empty!"
ERROR=1
fi
elif [ $subpackage == "dkms" ]; then
dkms_conf=`dpkg -c $debname | grep dkms.conf | wc -l`
if [ "$dkms_conf" -lt 1 ]; then
echo "No dkms config in dkms package"
ERROR=1
fi
else
echo "Unknown sub-package type: $subpackage"
ERROR=1
fi
# Check if description field exists in package
if [ -z "`dpkg -I ${debname} | grep '^ Description: '`" ]; then
echo "Description field missing!"
ERROR=1
fi
# Additional saftey check that the expected and counted packages are really there
if [ ! -f "${debname}" ]; then
echo " *** MISSING PACKAGE: ${debname}"
fi
if [ ! -f "${debug_name}" -a ${package_increment} -gt 1 ]; then
echo " *** MISSING PACKAGE: ${debug_name}"
fi
# increment checked number of files
nDebianFilesChecked=$(( nDebianFilesChecked + package_increment ))
done
# update number of files checked
echo ${nDebianFilesChecked} > "${LOCAL_REPOS}/nDebianFilesChecked.txt"
exit $ERROR