1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#!/bin/sh
#
# get-packages <type> <package> ... | <update> ...
#
# Download deb or udeb package with the help of apt-get
# type : deb | udeb
#
# Files:
# sources.list.udeb / sources.list.udeb.local
# sources.list.deb / sources.list.deb.local
#
# Environment:
# APTDIR - basename for the apt directory (default: apt.$TYPE)
# DEBUG - build debug udebs from source (default: n)
# DEBUGUDEBDIR - directory for debug udebs (default: debugudebs)
# UDEBDIR - directory for ready-to-use udebs (default: udebs)
# LOCALUDEBDIR - directory for locally provided udebs (default: localudebs)
# ONLINE - update Packages files (default: y)
set -e
# parse parameters
TYPE=$1
shift
PACKAGES=$*
# Setup environment
if [ ! $APTDIR ]; then
APTDIR="apt"
fi
if [ ! $DEBUGUDEBDIR ]; then
DEBUGUDEBDIR="debugudebs"
fi
if [ ! $UDEBDIR ]; then
UDEBDIR="udebs"
fi
if [ ! $LOCALUDEBDIR ]; then
LOCALUDEBDIR="localudebs"
fi
if [ ! $ONLINE ]; then
ONLINE="y"
fi
if [ ! $KEYRING ]; then
KEYRING=/etc/apt/trusted.gpg
fi
# Set APTDIR according to type
# debs are kept in another apt cache so only the needed Packages files
# are downloaded and autoclean doesnt run wild.
APTDIR=$APTDIR.$TYPE
# Set sources.list file
if [ -f sources.list.$TYPE.local ]; then
LIST=sources.list.$TYPE.local
else
LIST=sources.list.$TYPE
make sources.list.$TYPE
fi
# localudebs support
apt-ftparchive packages $LOCALUDEBDIR > $LOCALUDEBDIR/Packages
cat $LOCALUDEBDIR/Packages | gzip > $LOCALUDEBDIR/Packages.gz
if [ -s $LOCALUDEBDIR/Packages ]; then
echo "*" >&2
echo "* Warning: Building with localudebs." >&2
echo "* Secure apt validation will be disabled for this build." >&2
echo "* This build should not be used for official purposes." >&2
echo "*" >&2
SECOPTS="--allow-unauthenticated"
fi
# All these options make apt read the right sources list, and use APTDIR for
# everything so it need not run as root.
APT_GET="apt-get --assume-yes \
-o Dir::Etc::sourcelist=`pwd`/$LIST \
-o Dir::State=`pwd`/$APTDIR/state \
-o Debug::NoLocking=true \
-o Dir::Cache=`pwd`/$APTDIR/cache \
-o Acquire::Retries=3 \
-o Apt::Architecture=`dpkg-architecture -qDEB_HOST_ARCH` \
-o Apt::GPGV::TrustedKeyring="$KEYRING" \
$SECOPTS"
# Prepare APTDIR
mkdir -p $APTDIR/state/lists/partial
mkdir -p $APTDIR/cache/archives/partial
echo -n > $APTDIR/state/status
if [ "$TYPE" = "deb" ]; then
APT_GET="$APT_GET -o Dir::State::Status=`pwd`/$APTDIR/state/status"
else
# Prime status file with a few system libraries that don't
# currently have udebs, or which udebs still depend on for various
# reasons.
echo -n > $APTDIR/state/status
# Some archs have libc6, others have libc6.1. libgcc1 is not used
# on all architectures.
for i in libc6 libc6.1 libnewt0.52 libgcc1; do
if dpkg -s $i >/dev/null 2>&1; then
dpkg -s $i | grep -v Depends: >> $APTDIR/state/status
echo >> $APTDIR/state/status
fi
done
APT_GET="$APT_GET -o Dir::State::Status=`pwd`/$APTDIR/state/status"
fi
# Update package lists and autoclean cache.
if [ "$ONLINE" = "y" ]; then
$APT_GET update || {
echo "Failed to update the Packages file. This usually means either of:"
echo
echo "A) $LIST does not contain a valid repository."
echo " You can override the generated sources.list.$TYPE"
echo " with sources.list.$TYPE.local if you haven't done so yet."
echo
echo "B) The repository in $LIST is not reachable."
echo " If you are not working online, use 'export ONLINE=n' to skip updating"
echo " the Packages files. Beware that this can result in images with"
echo " out-of-date packages and should be used for private development only."
exit 1
}
$APT_GET autoclean
else
# A Release.gpg may not be cached, allow continuing w/o it in
# offline mode.
APT_GET="$APT_GET --allow-unauthenticated"
$APT_GET --no-list-cleanup update || echo "Ignoring update failure in offline mode"
fi
if [ "$PACKAGES" = update ]; then
exit 0
fi
# Get udebs.
if [ "$DEBUG" = y ]; then
mkdir -p $DEBUGUDEBDIR
cd $DEBUGUDEBDIR
export DEB_BUILD_OPTIONS="debug"
$APT_GET source --build --yes $PACKAGES
cd ..
else
echo Need to download: $PACKAGES
if [ -n "$PACKAGES" ]; then
$APT_GET -dy install $PACKAGES
fi
fi
# Now the (u)debs are in APTDIR/cache/archives/ (and maybe DEBUGUDEBDIR)
# but there may be other (u)debs there too besides those we asked for. So
# link those we asked for to UDEBDIR, renaming them to more useful names.
rm -rf $UDEBDIR
mkdir -p $UDEBDIR
lnpkg() {
local pkg=$1; local dir=$2 debdir=$3
local L="`find $dir -name "${pkg}_*" 2>/dev/null | sort | tail -n 1`"
if [ -e "$L" ]; then
ln -f $L $debdir/$pkg.$TYPE
fi
}
for package in $PACKAGES; do
lnpkg $package $APTDIR/cache/archives $UDEBDIR
lnpkg $package $DEBUGUDEBDIR $UDEBDIR
if [ ! -e $UDEBDIR/$package.$TYPE ]; then
echo "Needed $package not found (looked in $APTDIR/cache/archives/, $DEBUGUDEBDIR/)";
exit 1
fi
done
|