#!/bin/bash

set -x

APTTMP=${WORK_DIR}/tmp
mkdir -pv ${WORK_DIR}/tmp/
REPO_LIST=/etc/apt/sources.list
KEY_FILE=/etc/apt/trusted.gpg

PKG=$1

if [ ! -n "$PKG" ];then
    echo "PKGS is NULL"
    exit 0
fi

mkdir -pv $APTTMP/$CODENAME-$ARCH/
mkdir -pv $APTTMP/$CODENAME-$ARCH/apt/trusted.gpg.d
mkdir -pv $APTTMP/$CODENAME-$ARCH/apt/sources.list.d/
mkdir -pv $APTTMP/$CODENAME-$ARCH/apt/preferences.d/
mkdir -pv $APTTMP/$CODENAME-$ARCH/apt-state/lists/
mkdir -pv $APTTMP/$CODENAME-$ARCH/apt-cache/archives/
touch $APTTMP/$CODENAME-$ARCH/status
cp $REPO_LIST $APTTMP/$CODENAME-$ARCH/apt/
cp $KEY_FILE  $APTTMP/$CODENAME-$ARCH/apt/

options=" -q -o Dir::State::status=$APTTMP/$CODENAME-$ARCH/status  \
             -o Dir::State=$APTTMP/$CODENAME-$ARCH/apt-state/      \
             -o Dir::Cache=$APTTMP/$CODENAME-$ARCH/apt-cache/      \
             -o Dir::Etc=$APTTMP/$CODENAME-$ARCH/apt/              \
             -o APT::Cache::AllVersions=0                          \
             -o APT::Cache::ShowVersion=1                          \
             -o APT::Architecture=$ARCH                            \
             -o APT::Architectures::=$ARCH                         \
             -o Acquire::Languages=none"

sections="main non-free contrib"

#pkg=`debootstrap --print-debs --no-check-gpg --include=${PKGS} --components=main,non-free,contrib --arch=amd64 kui /tmp/123 http://10.1.10.21/server-dev/`
apt-get $options update -y
apt-get $options download $PKG

