Last active
March 21, 2017 16:58
-
-
Save mpontillo/334bb65e30fad6d2d28aaa40dcbd0b74 to your computer and use it in GitHub Desktop.
Example of how to create a container to mirror Trusty and Xenial (complete with boot images for MAAS).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONTAINER=mirror | |
lxc launch ubuntu:x $CONTAINER | |
# Wait for the container to come online. | |
wait-for-systemd-container.sh $CONTAINER | |
# Ensure packages are up to date and install dependencies. | |
lxc exec $CONTAINER -- apt-get update | |
lxc exec $CONTAINER -- apt-get dist-upgrade -yu | |
lxc exec $CONTAINER -- apt-get install apt-mirror simplestreams ubuntu-cloudimage-keyring nginx aptly | |
# Import Ubuntu archive keys | |
lxc exec $CONTAINER -- sudo -Hu ubuntu /bin/bash -c \ | |
"gpg --no-default-keyring --keyring /usr/share/keyrings/ubuntu-archive-keyring.gpg --export | "` | |
`"gpg --no-default-keyring --keyring trustedkeys.gpg --import" | |
# Import MAAS PPA keys | |
lxc exec $CONTAINER -- sudo -Hu ubuntu \ | |
gpg --no-default-keyring --keyring trustedkeys.gpg --keyserver keys.gnupg.net --recv-keys 5CFF1EA993EE8CC5 | |
lxc exec $CONTAINER -- sudo -Hu ubuntu \ | |
gpg --no-default-keyring --keyring trustedkeys.gpg --keyserver keys.gnupg.net --recv-keys 04E7FDC5684D4A1C | |
# Create PPA mirrors | |
lxc exec $CONTAINER -- sudo -Hu ubuntu aptly mirror create maas-maintainers-experimental3-xenial http://ppa.launchpad.net/maas-maintainers/experimental3/ubuntu/ xenial || true | |
lxc exec $CONTAINER -- sudo -Hu ubuntu aptly mirror create maas-stable-trusty http://ppa.launchpad.net/maas/stable/ubuntu/ trusty || true | |
lxc exec $CONTAINER -- sudo -Hu ubuntu aptly mirror create maas-next-xenial http://ppa.launchpad.net/maas/next/ubuntu/ xenial || true | |
lxc exec $CONTAINER -- sudo -Hu ubuntu \ | |
aptly mirror update maas-maintainers-experimental3-xenial | |
lxc exec $CONTAINER -- sudo -Hu ubuntu \ | |
aptly mirror update maas-stable-trusty | |
lxc exec $CONTAINER -- sudo -Hu ubuntu \ | |
aptly mirror update maas-next-xenial | |
lxc exec $CONTAINER -- sudo -Hu ubuntu mkdir -p /home/ubuntu/var | |
cat > mirror.list << EOF | |
set base_path /home/ubuntu | |
set mirror_path $base_path/mirror | |
set skel_path $base_path/skel | |
set var_path $base_path/var | |
set cleanscript $var_path/clean.sh | |
set nthreads 20 | |
set _tilde 0 | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse | |
# debian installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-security main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-updates main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-proposed main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-backports main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-security main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-updates main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-proposed main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-amd64 http://archive.ubuntu.com/ubuntu xenial-backports main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-security main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-updates main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-proposed main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu trusty-backports main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-security main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-updates main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-proposed main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-i386 http://archive.ubuntu.com/ubuntu xenial-backports main/debian-installer restricted/debian-installer multiverse/debian-installer universe/debian-installer | |
deb-src http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse | |
deb-src http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse | |
clean http://archive.ubuntu.com/ubuntu | |
EOF | |
cat > postmirror.sh << EOF | |
#!/bin/bash | |
DISTS="trusty xenial" | |
ARCHIVE="archive.ubuntu.com" | |
for dist in $DISTS; do | |
echo "Synchronizing $dist..." | |
mkdir -p $HOME/extras/archive.ubuntu.com/ubuntu/dists/$dist/main/uefi | |
rsync --recursive --times --links --hard-links --delete --delete-after --verbose \ | |
rsync://$ARCHIVE/ubuntu/dists/$dist/main/uefi/ \ | |
$HOME/extras/archive.ubuntu.com/ubuntu/dists/$dist/main/uefi | |
done | |
# Note: this requires /var/www/html to be owned by the user performing the mirror | |
cd /var/www/html | |
rm -rf ubuntu.working | |
echo "Linking archive..." | |
cp -al $HOME/mirror/archive.ubuntu.com/ubuntu ubuntu.working | |
for dist in $DISTS; do | |
echo "Linking $dist..." | |
rm -rf ubuntu.working/dists/$dist/main/uefi | |
cp -al $HOME/extras/archive.ubuntu.com/ubuntu/dists/$dist/main/uefi \ | |
ubuntu.working/dists/$dist/main/uefi | |
done | |
mv ubuntu ubuntu.old | |
mv ubuntu.working ubuntu | |
rm -rf ubuntu.old | |
$HOME/var/clean.sh | |
EOF | |
chmod +x postmirror.sh | |
lxc file push mirror.list.amd64 $CONTAINER/etc/apt/mirror.list | |
lxc file push postmirror.sh $CONTAINER/home/ubuntu/var/postmirror.sh | |
lxc exec $CONTAINER -- chown ubuntu:ubuntu /var/www/html | |
lxc exec $CONTAINER -- sudo -Hu ubuntu apt-mirror |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright 2016 Canonical Ltd. This software is licensed under the | |
# GNU Affero General Public License version 3 (see the file LICENSE). | |
# Exit immediately if a command exits with a non-zero status. | |
set -o errexit | |
# Treat unset variables as an error when substituting. | |
set -o nounset | |
CONTAINER=$1 | |
if [ "$CONTAINER" == "" ]; then | |
echo "Required argument: LXD container name" | |
exit 1 | |
fi | |
t=0 | |
while [ "$(lxc exec $CONTAINER -- systemctl is-system-running | \ | |
sed 's/degraded/running/')" != "running" ]; do | |
sleep 0.1 | |
let t=$t+1 || true | |
done | |
let q=$t%4 || true | |
let t=$t/10 || true | |
echo "(waited $t.$q seconds for container startup)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment