findunusedbd/findunusedbd.sh

109 lines
4 KiB
Bash
Raw Normal View History

2014-06-05 12:14:03 +00:00
#!/bin/sh -ex
# start this script without arguments and then start sbuild as:
#
2014-06-18 05:03:42 +00:00
# sbuild --chroot-setup-commands='/home/prebuildcmd.sh chroot-setup' --pre-realbuild-commands='/home/prebuildcmd.sh pre-realbuild' --post-realbuild-commands='/home/prebuildcmd.sh post-realbuild'
2014-06-05 12:14:03 +00:00
if [ "$#" -eq 1 ]; then
tmpdir="$1"
# once something is written to the fifo, it indicates that fatrace should start
SCHROOT_SESSION_ID=`cat "${tmpdir}/myfifo"`;
# change to the schroot mount
cd /var/lib/schroot/mount/$SCHROOT_SESSION_ID
2014-06-05 12:14:03 +00:00
# start fatrace in the mounted directory
fatrace --current-mount > "${tmpdir}/fatrace.log" &
FATRACE_PID=$!
# give fatrace some time to set up (value is arbitrary)
sleep 5
# signal that fatrace was started
echo > "${tmpdir}/myfifo"
# wait for build to finish
cat "${tmpdir}/myfifo" > /dev/null
kill $FATRACE_PID
2014-06-05 12:14:03 +00:00
# clean up the fatrace log to only include unique paths
sed 's/\/var\/lib\/schroot\/mount\/[^\/]\+//' "${tmpdir}/fatrace.log" \
2014-06-05 12:14:03 +00:00
| awk '{ print $3; }' \
| grep -v ^/build \
| sort \
| uniq \
> "${tmpdir}/accessed.log"
2014-06-05 12:14:03 +00:00
# now get all packages in /tmp/pkglists that have files that never appear in the collected trace
while read namever; do
name=`echo $namever | cut -d '=' -f 1 | cut -d ':' -f 1`
2014-06-05 12:14:03 +00:00
# FIXME: the following cannot handle dependencies on virtual packages
if [ -z `comm -12 "${tmpdir}/accessed.log" "${tmpdir}/$namever"` ] \
&& grep --line-regexp "$name" "${tmpdir}/sbuild-dummy-depends" > /dev/null; then
echo $namever
fi
done > "${tmpdir}/unneededdepends.list" < "${tmpdir}/bdselection.list"
elif [ "$#" -eq 2 ]; then
2014-06-05 12:14:03 +00:00
case "$1" in
chroot-setup)
tmpdir="$2"
dpkg --list | awk '$1 == "ii" { print $2"="$3 }' | sort > "${tmpdir}/initialselection.list"
2014-06-05 12:14:03 +00:00
;;
pre-realbuild)
tmpdir="$2"
2014-06-05 12:14:03 +00:00
# get the current selection so that the parent script can find the additional packages that were installed
dpkg --list | awk '$1 == "ii" { print $2"="$3 }' | sort > "${tmpdir}/fullselection.list"
# get all packages that were installed on top of the base packages
comm -13 "${tmpdir}/initialselection.list" "${tmpdir}/fullselection.list" > "${tmpdir}/bdselection.list"
2014-06-05 12:14:03 +00:00
# output the files belonging to all packages
dpkg --list | awk '$1 == "ii" { print $2, $3 }' | while read namever; do
set -- $namever
name=$1
ver=$2
if grep --line-regexp $pkgnamever "${tmpdir}/bdselection.list"; then
dpkg -L $name > "${tmpdir}/${name}=${ver}"
fi
2014-06-05 12:14:03 +00:00
done
# output the dependencies of the sbuild dummy package
dpkg --get-selections | awk '{ print $1; }' \
| grep sbuild-build-depends \
| grep -v sbuild-build-depends-core-dummy \
| grep -v sbuild-build-depends-essential-dummy \
| grep -v sbuild-build-depends-lintian-dummy \
| xargs -I {} dpkg-query --showformat='${Depends}\n' --show {} \
| sed 's/, \+/\n/'g \
| sed 's/\([a-zA-Z0-9][a-zA-Z0-9+.-]*\).*/\1/' \
> "${tmpdir}/sbuild-dummy-depends"
2014-06-05 12:14:03 +00:00
# output the schroot id to start tracing
echo $SCHROOT_SESSION_ID > "${tmpdir}/myfifo"
# wait for fatrace to be forked
cat "${tmpdir}/myfifo" > /dev/null
2014-06-05 12:14:03 +00:00
;;
post-realbuild)
tmpdir="$2"
# signal that the build is done
echo > "${tmpdir}/myfifo"
2014-06-18 05:03:42 +00:00
;;
equivs)
namever="$2"
2014-06-18 05:03:42 +00:00
# create and install a package with same name and version but without dependencies
# removing Source: field because of bug#751942
2014-06-23 09:01:33 +00:00
apt-cache show --no-all-versions $namever \
| grep -v "^Pre-Depends:" \
| grep -v "^Depends:" \
| grep -v "^Recommends:" \
| grep -v "^Suggests:" \
| grep -v "^Conflicts:" \
| grep -v "^Breaks:" \
| grep -v "^Provides:" \
| grep -v "^Replaces:" \
| grep -v "^Source:" \
| equivs-build -
name=`echo $namever | cut -d '=' -f 1 | cut -d ':' -f 1`
# we use a wildcard because there should only be a single file anyways
dpkg -i ${name}_*.deb
2014-06-05 12:14:03 +00:00
;;
*)
echo "invalid argument: $1" >&2
;;
esac
else
echo "usage: " >&2
echo " $0 tmpdir"
echo " $0 [chroot-setup|pre-realbuild|post-realbuild] tmpdir"
echo " $0 equivs pkgname"
exit 1
2014-06-05 12:14:03 +00:00
fi