#!/bin/sh
#
#	apply, upgrades the target ... runs a dist-upgrade using our
#	package lists, with --no-download --fix-missing using the pen
#	drive archives.  [while on target system]
#
set -ex

if [ ! -f bin/apply ]; then
    echo "aborted, we're not in an apt-walkabout instance"
    exit
fi

command=${1}
if [ -z "${command}" ]; then
    command="--no-download --fix-missing dist-upgrade"
fi

# attempt a dist-upgrade using our archives only
apt-get \
    -o Dir::Etc::SourceList=${PWD}/etc/apt/sources.list \
    -o Dir::State::Lists=${PWD}/var/lib/apt/lists/ \
    -o Dir::Cache::srcpkgcache=/tmp/srcpkgcache.bin \
    -o Dir::Cache::pkgcache=/tmp/pkgcache.bin \
    -o Dir::Cache::Archives=${PWD}/var/cache/apt/archives \
    -o Debug::NoLocking=true \
    -qq --print-uris \
    ${command} > uris
cd ${PWD}/var/cache/apt/archives && puf `cut -f1 -d\' uris`
