debian-cd-clone/tools/scanpackages

184 lines
5.5 KiB
Bash
Executable File

#!/bin/sh
# Copyright 1999 Raphaël Hertzog <hertzog@debian.org>
# See the README file for the license
# This script will create the Packages.gz and the Packages.cd files
# First arg = "scan" or "install"
# Second arg = directory of the CD
#set -e
BDIR=$TDIR/$CODENAME-$ARCH
PREFIX=`echo $2 | sed "s?$BDIR/CD?$BDIR/?"`
NUM=${PREFIX##$BDIR/}
NUM=`echo $NUM | sed 's/_NONUS//g'`
if [ -n "$NONFREE" -o -n "$EXTRANONFREE" ]; then
SECTIONS="main contrib non-free"
SECTIONSNONUS="non-US/main non-US/contrib non-US/non-free"
else
SECTIONS="main contrib"
SECTIONSNONUS="non-US/main non-US/contrib"
fi
cd "$2"
if [ "$1" = "install" ]; then
if [ -e "$MIRROR/dists/$CODENAME/Release" ]; then
# Strip the MD5Sum and SHA1 fields
# Update some other information as well
sed -e "s/^Architectures: .*$/Architectures: $ARCH/" \
$MIRROR/dists/$CODENAME/Release | \
sed -e "s|^Components: .*$|Components: $SECTIONS|" | \
perl -ne 'if (/^(MD5Sum|SHA1):/i) { $f=1; next }
if ($f) {
unless (/^ /) { print; $f=0 }
} else { print }' > dists/$CODENAME/Release
fi
if [ -n "$NONUS" -a -e "$NONUS/dists/$CODENAME/non-US/Release" ]; then
# Strip the MD5Sum and SHA1 fields
# Update some other information as well
sed -e "/^ /d" -e "s/^Architectures: .*$/Architectures: $ARCH/" \
$NONUS/dists/$CODENAME/non-US/Release | \
sed -e "s|^Components: .*$|Components: $SECTIONSNONUS|" | \
perl -ne 'if (/^(MD5Sum|SHA1):/i) { $f=1; next }
if ($f) {
unless (/^ /) { print; $f=0 }
} else { print }' > dists/$CODENAME/non-US/Release
fi
for SECT in $SECTIONS; do
# Install the release files
cp $MIRROR/dists/$CODENAME/$SECT/binary-$ARCH/Release \
dists/$CODENAME/$SECT/binary-$ARCH/
if [ -n "$NONUS" ]; then
cp $NONUS/dists/$CODENAME/non-US/$SECT/binary-$ARCH/Release \
dists/$CODENAME/non-US/$SECT/binary-$ARCH/
fi
# Install the Packages and Packages.gz files
cp $PREFIX.Packages-$SECT dists/$CODENAME/$SECT/binary-$ARCH/Packages
cat $PREFIX.Packages-$SECT | gzip --best \
>dists/$CODENAME/$SECT/binary-$ARCH/Packages.gz
if [ -n "$NONUS" ]; then
cp $PREFIX.Packages-non-US-$SECT \
dists/$CODENAME/non-US/$SECT/binary-$ARCH/Packages
cat $PREFIX.Packages-non-US-$SECT | gzip --best \
>dists/$CODENAME/non-US/$SECT/binary-$ARCH/Packages.gz
fi
done
if [ -n "$LOCAL" ]; then
if [ -e ${LOCALDEBS:-$MIRROR}/dists/$CODENAME/local/binary-$ARCH/Release ]; then
cp ${LOCALDEBS:-$MIRROR}/dists/$CODENAME/local/binary-$ARCH/Release \
dists/$CODENAME/local/binary-$ARCH/
fi
cp $PREFIX.Packages-local dists/$CODENAME/local/binary-$ARCH/Packages
cat $PREFIX.Packages-local | gzip --best \
>dists/$CODENAME/local/binary-$ARCH/Packages.gz
fi
fi
# Creates the temp Packages-$SECT files
if [ "$1" != "scan" ]; then exit 0; fi
if [ ! -e "../overrides" ]; then
# Create an override file with all sections
for SECT in $SECTIONS; do
zcat $MIRROR/indices/override.$CODENAME.$SECT.gz >> ../overrides
if [ -n "$NONUS" ]; then
zcat $NONUS/indices-non-US/override.$CODENAME.$SECT.gz \
>> ../overrides
fi
done
fi
if [ ! -e "../overrides.extra" ]; then
# Create an extra override file with all sections
for SECT in $SECTIONS; do
if [ -e $MIRROR/indices/override.$CODENAME.extra.$SECT.gz ]; then
zcat $MIRROR/indices/override.$CODENAME.extra.$SECT.gz \
>> ../overrides.extra
fi
if [ -n "$NONUS" ]; then
if [ -e $NONUS/indices-non-US/override.$CODENAME.extra.gz ]; then
zcat $NONUS/indices-non-US/override.$CODENAME.extra.$SECT.gz \
>> ../overrides.extra
fi
fi
done
fi
#
# Create a Packages file for all packages on the CD
#
if [ -d pool ]; then
apt-ftparchive -o Tree::ExtraOverride=../overrides.extra \
packages pool ../overrides > $PREFIX.Packages-BOTH
fi
# We have to scan all possible dists where packages can be
DISTS=""
DISTSNONUS=""
for i in `cd dists; echo *; cd ..`; do
if [ ! -L "dists/$i" -a -d "dists/$i" ]; then
if [ -d "dists/$i/main/binary-$ARCH" -o \
-d "dists/$i/non-free/binary-$ARCH" -o \
-d "dists/$i/contrib/binary-$ARCH" ]; then
DISTS="$DISTS $i"
fi
if [ -d "dists/$i/non-US/main/binary-$ARCH" -o \
-d "dists/$i/non-US/non-free/binary-$ARCH" -o \
-d "dists/$i/non-US/contrib/binary-$ARCH" ]; then
DISTSNONUS="$DISTSNONUS $i"
fi
fi
done
for SECT in $SECTIONS; do
for DIST in $DISTS; do
apt-ftparchive -o Tree::ExtraOverride=../overrides.extra \
packages dists/$DIST/$SECT/binary-$ARCH ../overrides \
>> $PREFIX.Packages-BOTH
done
for DIST in $DISTSNONUS; do
if [ -n "$NONUS" ]; then
apt-ftparchive -o Tree::ExtraOverride=../overrides.extra \
packages dists/$DIST/non-US/$SECT/binary-$ARCH \
../overrides >> $PREFIX.Packages-BOTH
fi
done
done
# Separate non-US from the rest
grep-dctrl -FFilename -e '/non-[Uu][Ss]/' $PREFIX.Packages-BOTH \
> $PREFIX.Packages-ALLNONUS
grep-dctrl -v -FFilename -e '/non-[Uu][Ss]/' $PREFIX.Packages-BOTH \
> $PREFIX.Packages-ALL
# Split the Packages file by section
for SECT in $SECTIONS; do
grep-dctrl -FFilename -e "/$SECT/" $PREFIX.Packages-ALL \
> $PREFIX.Packages-$SECT
if [ -n "$NONUS" ]; then
grep-dctrl -FFilename -e "/$SECT/" $PREFIX.Packages-ALLNONUS \
> $PREFIX.Packages-non-US-$SECT
fi
done
if [ -n "$LOCAL" ]; then
apt-ftparchive -o Tree::ExtraOverride=../overrides.extra \
packages dists/$CODENAME/local/binary-$ARCH \
> $PREFIX.Packages-local
if [ -d pool/local ]
then
apt-ftparchive -o Tree::ExtraOverride=../overrides.extra \
packages pool/local >> $PREFIX.Packages-local
fi
fi
exit 0