#!/bin/sh
#
# Download the Debian ttf-bitstream-vera package, extract its files, and create
# a CD image of them.
#
# <debianarchist@memebeam.org>


# Configuration {
PACKAGE_NAME="ttf-bitstream-vera"
POOL_BASE_URL="http://http.us.debian.org/debian/"
WORKDIR="${PACKAGE_NAME}_files"
IMAGE_NAME="debianarchist-bitstream.iso"
# }

# Look up a specific version of the package in the local package cache
# and generate a URL to the file in the package pool.
FILENAME=($(apt-cache show --no-all-versions $PACKAGE_NAME | grep Filename:))
FILENAME=${FILENAME[1]}
BASENAME=$(basename $FILENAME)
URL=$POOL_BASE_URL$FILENAME

# Download the package.
wget --quiet --continue $URL

# Extract payload from the package.
rm -rf $WORKDIR
mkdir $WORKDIR
dpkg-deb --extract $BASENAME $WORKDIR

# Remove files specific to Debian (optional)
# ISSUE: fragile code that needs to be kept current with package
if [ ${1:-""} == "--purify" ]; then
    rm -rf $WORKDIR/etc/
    rm -rf $WORKDIR/usr/share/bug/
    rm -rf $WORKDIR/usr/share/doc/ttf-bitstream-vera/*Debian*
fi

# Make CD image.
mkisofs -r -J -o $IMAGE_NAME $WORKDIR
