#!/bin/sh
set -e

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

# prompt for the remote system username and host name
name=${1}
if [ -z "${name}" ]; then
    def=${USER}@server
    echo -n "username and system name, in user@system format [${def}] ? "
    read name
    if [ -z "${name}" ]; then
        name=${def}
    fi
fi

LISTS=var/lib/apt/lists-collected
mkdir -p ${LISTS}

HERE=/tmp/apt-walkabout.$$
mkdir ${HERE}

scp -Cvr ${name}:/var/lib/apt/lists ${HERE}
cd ${HERE}/lists

for file in *Packages *Release *Sources; do
    md5=`md5sum ${file}`
    mv ${file} ${LISTS}/
done

rm -rf ${HERE}
