#!/bin/sh1# checksize.sh: scan the ports collection for "size mismatch" and2# "size unknown" errors by attempting to fetch onto a full filesystem3#4# When called with a parameter that is the name of a category of5# ports, the script checks that category, then checks the whole6# ports collection, redoing the named category. When called with7# no parameter, it checks the whole collection.8#9# First do something like:10#11# dd if=/dev/zero of=/usr/ports/mfs.img bs=1k count=51212# mdconfig -a -t vnode -f /usr/ports/mfs.img -u 113# newfs /dev/md114# mount /dev/md1 /mnt15#16# (for RELENG_4 use vnconfig instead of mdconfig). Then run this17# while logging with, for example, the "script" utility and look18# for "size mismatch" (indicating the server has a distfile with a19# different size than what is listed in the distinfo file) and "size20# unknown" (indicating that the server does not report file sizes)21# errors in the output. Pipe the output through:22#23# grep -w size | grep -1 -E "unknown|mismatch"24#25# By keeping the filesystem full, we avoid fetching entire distfiles.26# The script attempts to partially download each distfile from all27# master sites. Contacting all sites is desirable because sometimes28# a site which ostensibly mirrors another may contain corrupt files29# which are intact on the main site (or vice versa).30#31# bugs:32# - assumes ports tree is in /usr/ports/33# - doesn't provide for checking only particular categories or ports34# - support for multiple architectures is inefficient35# - output is messy36# - on my system, the first 20 kB of each distfile are fetched37# (this can be suppressed by adding FETCH_BEFORE_ARGS=-s to the make options,38# in which case the word "Unknown" appears by itself on a line39# where otherwise there would be a "size unknown" error, and "size40# mismatch" errors are not detected)41# - needs manual setup of /mnt/42#43# placed in the public domain by Trevor Johnson4445for category in $1 `grep ^SUBDIR /usr/ports/Makefile | cut -f3 -d\ `; do46cd /usr/ports/$category47for port in \48`grep -wc SIZE */distinfo* | grep -v :0 | cut -f1 -d\/`; do49cd /usr/ports/$category/$port50for arc in i386; do51dd if=/dev/zero of=/mnt/zero52echo checking $arc size data for $category/$port53make DISTDIR=/mnt \54ARCH=$arc \55BATCH=yes \56MACHINE_ARCH=$arc \57PACKAGE_BUILDING=yes \58TRYBROKEN=yes checksum59rm -rf /mnt/*60done61done62done636465