create_offlinerepo.sh 2.75 KB
Newer Older
1 2 3 4
#!/bin/bash

set -e

5 6 7 8 9 10 11 12 13 14 15 16 17 18
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="$@"

19
workspace="/workspace"
20
APT_SOURCE_URL_OVERRIDE="http://ftp.halifax.rwth-aachen.de/ubuntu/"
21 22 23

rm -rf "$workspace"/offlinerepo
mkdir -p "$workspace"/offlinerepo
24
mkdir -p "$dest"
25 26 27

7z e -so "$iso_file" casper/filesystem.squashfs > "$workspace"/offlinerepo/filesystem.squashfs
unsquashfs -no-xattrs -d "$workspace"/offlinerepo/squashfs-root "$workspace"/offlinerepo/filesystem.squashfs 
28

29 30 31 32 33 34
ISO_RELEASE="$(grep DISTRIB_CODENAME "$workspace/offlinerepo/squashfs-root/etc/lsb-release" | cut -d= -f 2-)"
ISO_VERSION="$(grep DISTRIB_RELEASE "$workspace/offlinerepo/squashfs-root/etc/lsb-release" | cut -d= -f 2-)"
ISO_DESCRIPTION="$(grep DISTRIB_DESCRIPTION "$workspace/offlinerepo/squashfs-root/etc/lsb-release" | cut -d'"' -f 2)"
echo "deb $APT_SOURCE_URL_OVERRIDE ${ISO_RELEASE} main restricted universe multiverse" > "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list"
echo "deb $APT_SOURCE_URL_OVERRIDE ${ISO_RELEASE}-security main restricted universe multiverse" >> "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list"
echo "deb $APT_SOURCE_URL_OVERRIDE ${ISO_RELEASE}-updates main restricted universe multiverse" >> "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list"
35
echo "deb $APT_SOURCE_URL_OVERRIDE ${ISO_RELEASE}-backports main restricted universe multiverse" >> "$workspace/offlinerepo/squashfs-root/etc/apt/sources.list"
36 37
apt-get -o Dir="$workspace"/offlinerepo/squashfs-root update

38 39 40 41
{
	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 -d"'" -f2 | while read url; do wget -nc -P "$dest" "$url"; done
42
apt-get -o Dir="$workspace"/offlinerepo/squashfs-root install --reinstall --print-uris -qq $packages
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
mkdir -p "$dest/dists/$ISO_RELEASE/lip/binary-amd64"
( cd "$dest" && dpkg-scanpackages . | gzip > "dists/$ISO_RELEASE/lip/binary-amd64/Packages.gz" )

cat <<EOF > "$dest/dists/$ISO_RELEASE/lip/binary-amd64/Release"
Archive: $ISO_RELEASE
Version: $ISO_VERSION
Component: lip
Origin: Ubuntu
Label: Ubuntu
Architecture: amd64
EOF

touch "$dest/.aptignr"
cat <<EOF > "$dest/Release"
Origin: Ubuntu
Label: LIP Ubuntu Extra Packages
Suite: $ISO_RELEASE
Version: $ISO_VERSION
Codename: $ISO_RELEASE
Date: $(LC_ALL=C date -u)
Architectures: amd64
Components: lip
Description: $ISO_DESCRIPTION
EOF
68

69
# Maybe sort files into the usual directory structure ("pool/main/g/glib2.0...")