#!/bin/sh name0=`basename "$0"` get_name() { echo "$1" | sed -e 's/_.*$//' } get_version() { echo "$1" | sed -e 's/^[^_]*_//' -e 's/-.*$//' } get_arch() { echo "$1" | sed -e 's/^.*_\([a-z0-9-]*\)\.deb$/\1/' } get_multiarch() { pkg="$1" dpkg --info "$pkg" | sed -e 's/^ *Multi-Arch: *//' -e t -e d } get_properties() { _pkg="$1" _name=`get_name "$_pkg"` _version=`get_version "$_pkg"` _arch=`get_arch "$_pkg"` if [ -z "$_pkg" -o -z "$_name" -o -z "$_version" -o -z "$_arch" ] then echo "prepare_package bug: pkg='$_pkg' name='$_name' version='$_version' arch='_$arch'" >&2 exit 1 fi } prepare_package() { _pkg="$1" get_properties "$_pkg" # alien may have left its working directory behind rm -rf "$_name-$_version" if ! alien --to-tgz "$_pkg" >"/tmp/$name0.$$" 2>&1 then echo "$name0:error: alien --to-tgz '$_pkg' failed" >&2 cat "/tmp/$name0.$$" >&2 rm -f "/tmp/$name0.$$" exit 1 fi _dir="$_name-$_arch" rm -rf "$_dir" mkdir "$_dir" tar xfz $_name-*.tgz -C "$_dir" rm $_name-*.tgz _include=`get_arch_include "$_dir"` [ -n "$_include" ] && mv "$_include" "$_dir/usr/include/ARCH" echo "$_dir" } get_arch_include() { _dir="$1" for _i in "$_dir"/usr/include/*-linux-gnu* \ "$_dir"/usr/include/*-kfreebsd-gnu* \ "$_dir"/usr/include/*-gnu do if [ -d "$_i" ] then if [ -z "$_include" ] then _include="$_i" elif [ "$_i" != "$_include" ] then echo "ambiguous include directory: $_include != $_i" >&2 return fi fi done echo "$_include" } done="" is_done() { if echo "$done" | grep "$1" >/dev/null then return 0 fi done="$done $1" return 1 } check_packages() { pkg1="$1" doforeign="$2" is_done "$pkg1" && return arch1=`get_arch "$pkg1"` multiarch1=`get_multiarch "$pkg1"` dir1=`prepare_package "$pkg1"` || exit 1 glob=`echo "$pkg1" | sed -e 's/_.*$/_*.deb/'` for pkg2 in $glob do is_done "$pkg2" && continue arch2=`get_arch "$pkg2"` multiarch2=`get_multiarch "$pkg2"` if [ "$multiarch1" != "$multiarch2" ] then echo "The $arch1 package is '$multiarch1' but the $arch2 one is '$multiarch2'" fi case "$doforeign" in no) [ "$multiarch1" = "foreign" ] && continue ;; only) [ "$multiarch1" != "foreign" ] && continue ;; *) ;; esac dir2=`prepare_package "$pkg2"` || exit 1 diff -ur "$dir1" "$dir2" | egrep -v "/usr/lib: [a-z0-9_]*-((linux|kfreebsd)-gnu[a-z]*|gnu)$" done } clean_package() { pkg="$1" get_properties "$pkg" rm -rf "$_name-$_version" rm -rf "$_name-$_arch" } if [ "$1" = "--help" ] then echo "Usage: $name0 [debfile] [yes|no|only]" echo "or $name0 clean" echo echo "Checks whether files differ that could prevent the packages from being marked Multi-Arch: same" echo echo "Where:". echo " debfile Is a Debian package file. All architectures of that package are then" echo " tested. If omitted, all package files found in the current directory" echo " are checked." echo " yes|no|only Indicates whether to also process multiarch foreign packages, skip" echo " them or only process them." echo " clean Removes the package trees created for the checks." elif [ "$1" = "clean" ] then for deb in *.deb do clean_package "$deb" done elif [ -n "$1" ] then check_packages "$1" "yes" else for deb in *.deb do check_packages "$deb" "no" done echo echo "Foreign packages:" for deb in *.deb do check_packages "$deb" "only" done fi