#!/bin/sh
#
# $Id: update-sourcedeps,v 1.18 2000/05/03 13:11:08 rnhodek Exp $
#
# $Log: update-sourcedeps,v $
# Revision 1.18  2000/05/03 13:11:08  rnhodek
# Switch back to buildd.debian.org after andrea on auric has been fixed.
#
# Revision 1.17  2000/05/03 09:44:14  rnhodek
# Needs quotes around "~buildd" so that it isn't expanded.
#
# Revision 1.16  2000/05/03 09:38:10  rnhodek
# Change location of src-deps: Use samosa.debian.org/~buildd/andrea, as
# buildd.debian.org is now some other machine where CVS isn't handled
# properly.
#
# Revision 1.15  1999/10/19 15:25:08  rnhodek
# Call sourcedeps-makerev.
#
# Revision 1.14  1999/06/25 08:54:58  rnhodek
# Limit wget tries to 3.
#
# Revision 1.13  1999/06/21 08:30:49  rnhodek
# Changed host and path from where to fetch src-deps.
#
# Revision 1.12  1999/06/11 07:46:41  rnhodek
# Determine arch at runtime and access new arch-dep directories at
# james.nocrew.org.
#
# Revision 1.11  1999/05/06 09:15:05  rnhodek
# If anything was really updated, print a message for which distribs.
#
# Revision 1.10  1999/05/03 13:36:30  rnhodek
# Skip a distrib (and don't error-exit) if it doesn't exist.
#
# Revision 1.9  1999/04/22 15:31:11  rnhodek
# Added a trap to remove tmp dir on every shell exit -- formerly the tmp
# dir stayed in place if the script exited due to set -e.
#
# Revision 1.8  1999/02/24 11:01:20  rnhodek
# Use cp+chmod instead of install to avoid "operation not permitted"
# errors (/etc not writable for users).
#
# Revision 1.7  1999/02/08 23:47:24  james
# Andrea does stable now (oo err).
#
# Revision 1.6  1998/12/01 07:22:06  james
# Rewritten to use andrea instead of the old system.
#
# Revision 1.5  1998/10/24 12:39:17  james
# Remove the temporary directory even when exiting with non-zero status.
#
# Revision 1.4  1998/09/30 14:01:15  rnhodek
# Dir for source-dependencies is now /etc
#
# Revision 1.3  1998/09/30 14:00:11  rnhodek
# Additionally read a global config file /etc/sbuild.conf.
# Some more defaults and checks for config vars.
# source-dependencies file now expected in /etc, to avoid dependency on
# wanna-build.conf ($basedir); also it's a config file that should be in
# /etc.
# Hardware default distrib to unstable, config not really needed and
# avoid dependency on wanna-build.conf as above.
# Introduce %individual_stalled_pkg_timeout for higher timeouts for some
# packages.
#
# Revision 1.2  1998/09/25 13:18:15  rnhodek
# Fix typo.
# Insert CVS headers.
#

set -e

set +e	# don't die if .sbuildrc is missing
dbfull=$(cat /etc/sbuild.conf /etc/sbuild.conf.local ~/.sbuildrc 2>/dev/null | \
	sed -n '/^\$source_dependencies\>/s/.*"\(.*\)".*/\1/p' | tail -1)
set -e

dbdir=${dbfull%/*}
if [ -z "$dbdir" ]; then
    dbdir=/var/lib/sbuild
fi
file=source-dependencies

tmp=/tmp/update-sourcedep.$$
arch=$(dpkg --print-installation-architecture)
host=buildd.debian.org
dir=andrea/$arch

mkdir $tmp
cd $tmp

trap 'rm -rf $tmp ; exit 1' 1 2 3 13 15
trap 'rm -rf $tmp' 0

done=""
for distribution in stable testing unstable; do

	name=$file-$distribution
    if wget --tries=3 -q http://$host/$dir/$name.gz; then
		gunzip $name.gz
		if ! cmp -s $name $dbdir/$name; then
			done="$done $distribution"
			cp $name $dbdir/
			chmod 664 $dbdir/$name
			if [ -x /usr/bin/sourcedeps-makerev ]; then
				/usr/bin/sourcedeps-makerev $dbdir/$name >$dbdir/$name.rev
			fi
		fi
	fi
done

if [ -n "$done" ]; then
	echo "Updated source-dependencies for:$done"
fi

exit 0
