#!/bin/bash set -e usage () { echo "usage: create_offlinerepo.sh repodir isofile [list of packages]" >&2 echo >&2 echo "Downloads all packages required to fully update the system in 'isofile' and" >&2 echo "to install the listed packages and adds them to the package archive in 'repodir'." >&2 exit 1 } dest="$1" shift || usage iso_file="$1" shift || usage packages="$@" : ${workspace:="/workspace"} APT_SOURCE_URL_OVERRIDE="http://ftp.halifax.rwth-aachen.de/ubuntu/" rm -rf "$workspace"/offlinerepo mkdir -p "$workspace"/offlinerepo mkdir -p "$dest" 7z e -so "$iso_file" casper/filesystem.squashfs > "$workspace"/offlinerepo/filesystem.squashfs unsquashfs -no-progress -no-xattrs -d "$workspace"/offlinerepo/squashfs-root "$workspace"/offlinerepo/filesystem.squashfs source "$workspace/offlinerepo/squashfs-root/etc/lsb-release" echo "deb $APT_SOURCE_URL_OVERRIDE ${DISTRIB_CODENAME} main restricted universe multiverse" > "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list" echo "deb $APT_SOURCE_URL_OVERRIDE ${DISTRIB_CODENAME}-security main restricted universe multiverse" >> "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list" echo "deb $APT_SOURCE_URL_OVERRIDE ${DISTRIB_CODENAME}-updates main restricted universe multiverse" >> "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list" echo "deb $APT_SOURCE_URL_OVERRIDE ${DISTRIB_CODENAME}-backports main restricted universe multiverse" >> "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list" apt-get -o Dir="$workspace"/offlinerepo/squashfs-root update { apt-get -o Dir="$workspace"/offlinerepo/squashfs-root upgrade --print-uris -qq apt-get -o Dir="$workspace"/offlinerepo/squashfs-root install --reinstall --print-uris -qq $packages } | cut -s -d"'" -f2 | while read url; do wget -q -nc -P "$dest" "$url"; done apt-get -o Dir="$workspace"/offlinerepo/squashfs-root install --reinstall --print-uris -qq $packages mkdir -p "$dest/dists/$DISTRIB_CODENAME/lip/binary-amd64" # For some reason apt does not like the gziped package list in the installed system. Leaving the packages list uncompressed solves the problem. #( cd "$dest" && dpkg-scanpackages . | gzip > "dists/$DISTRIB_CODENAME/lip/binary-amd64/Packages.gz" ) ( cd "$dest" && dpkg-scanpackages . > "dists/$DISTRIB_CODENAME/lip/binary-amd64/Packages" ) cat < "$dest/dists/$DISTRIB_CODENAME/lip/binary-amd64/Release" Archive: $DISTRIB_CODENAME Version: $DISTRIB_RELEASE Component: lip Origin: Ubuntu Label: Ubuntu Architecture: amd64 EOF touch "$dest/.aptignr" cat < "$dest/Release" Origin: Ubuntu Label: LIP Ubuntu Extra Packages Suite: $DISTRIB_CODENAME Version: $DISTRIB_RELEASE Codename: $DISTRIB_CODENAME Date: $(LC_ALL=C date -u) Architectures: amd64 Components: lip Description: $DISTRIB_DESCRIPTION EOF # Maybe sort files into the usual directory structure ("pool/main/g/glib2.0...")