#!/bin/sh
#
#	apt-walkabout apply
#
#	Upgrades the target system using the current source list,
#	package lists and downloaded packages.  The upgrade by default
#	uses --no-download and --fix-missing so that no downloads are
#	tried.
#
#	Run this on your target system.
#	Run this after doing an "apt-walkabout fetch".
#
set -e

if [ ! -f bin/apply ]; then
    echo "apt-walkabout: aborted, we're not in an apt-walkabout instance"
    exit 1
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 \
    ${command}
