#!/bin/bash
#
#       <apt-archive>
#
#       Generate packages list from /archive
#
#       Copyright 2012 Canonical, Ltd..
#           Christopher Townsend <christopher.townsend@canonical.com>
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
# vim:ts=8:sw=8:et:tw=0
#

# $1 -> early/late

#This allows things that aren't signed to be installed
if [ ! -f /etc/apt/apt.conf.d/00AllowUnauthenticated ]; then
   cat > /etc/apt/apt.conf.d/00AllowUnauthenticated << EOF
APT::Get::AllowUnauthenticated "true";
Aptitude::CmdLine::Ignore-Trust-Violations "true";
Acquire::AllowInsecureRepositories "true";
EOF
fi

#extra sources need to be disabled for this
if find /etc/apt/sources.list.d/ -type f | grep sources.list.d; then
   mkdir -p /etc/apt/sources.list.d.old
   mv /etc/apt/sources.list.d/* /etc/apt/sources.list.d.old
fi

#Produce a dynamic list
pushd /archive
   apt-ftparchive packages . > Packages
   apt-ftparchive release . > Release
popd
echo "deb [allow-insecure=yes] file:/archive ./" > /etc/apt/sources.list.d/temparchive.list

#fill up the cache
apt-get update -o Dir::Etc::sourcelist="sources.list.d/temparchive.list" \
   -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
