#!/bin/bash
## assumes you've already got OS_* environment set up.
set -x
set -f
CLOUDNAME="serverstack"
SWIFT_PATH="simplestreams/data/" # production: simplestreams/data/
CID_COMMON="com.canonical.serverstack.%(region)s"
REGION="" # set to empty to push to all
XPRE="" # production: set this to empty string for real
MAX_DAILY=10
MAX_RELEASED=10
HOOK_COMMAND="" # set this to full path to a command to run
#HOOK_COMMAND="$(dirname $0)/image-modify"
BASIC_FILTERS="
arch~(x86_64|amd64|i386|i686)
ftype~(disk1.img|disk.img)
"
UBUNTU_FILTERS="
release~(precise|trusty|utopic|vivid|devel)
$BASIC_FILTERS
"
[ "${TENV_SETUP:-0}" != "0" -o "${NO_TENV:-0}" != "0" ] || {
echo "expecting to be run from tenv (simplestreams/tools/tenv)";
echo "do that or export NO_TENV=1";
exit 2;
} 1>&2
[ -n "$OS_AUTH_URL" ] || {
echo "You probably need to set up your openstack creds ('. novarc')"
exit 2
} 1>&2
gmirror() {
local namepre="$1" cid="$2" url="$3"
shift 3
[ "${MAX}" = "0" ] &&
{ echo "skipping ${namepre}, MAX=0" 1>&2; return 0; }
sstream-mirror-glance -vv \
${MAX:+--max=${MAX}} ${REGION:+"--region=${REGION}"} \
"--cloud-name=${CLOUDNAME}" "--output-swift=${SWIFT_PATH}" \
"--name-prefix=${XPRE}${namepre%/}/" "--content-id=${CID_COMMON}:$cid" \
${HOOK_COMMAND:+"--modify-hook=${HOOK_COMMAND}"} \
"${url}" $FILTERS "$@"
}
fail() { [ $# -eq 0 ] || echo "$@" 1>&2; exit 2; }
## with cirros data
## add cirros signing key
# gpg-trust-pubkey ./simplestreams/examples/keys/cirros.pub
## get a local mirror (for quicker iterating)
# sstream-mirror --progress --max=2 \
# http://download.cirros-cloud.net/ ./cirros-mirror \
# arch=x86_64 ftype=disk.img
#MAX=2; gmirror "cirros/" "cirros" ./cirros-mirror/ arch=x86_64 ftype=disk.img
FILTERS=$UBUNTU_FILTERS
## released
MAX=${MAX_RELEASED};
gmirror "ubuntu-released/" "ubuntu:released" \
http://cloud-images.ubuntu.com/releases/ ||
fail "failed gmirror for ubuntu-released"
## daily
MAX=${MAX_DAILY};
gmirror "ubuntu-daily/" "ubuntu:daily" \
http://cloud-images.ubuntu.com/daily/ ||
fail "failed gmirror for ubuntu-daily"
## ubuntu-core/devel (snappy)
MAX=2
gmirror "ubuntu-core/devel/" "ubuntu:core:devel" \
http://cloud-images.ubuntu.com/snappy/ ||
fail "failed gmirror for ubuntu-snappy"
MAX=2
FILTERS="$BASIC_FILTERS"
myd=$(dirname "$0")
"$myd/simplestreams/tools/gpg-trust-pubkey" ./simplestreams/examples/keys/cirros.pub
gmirror "cirros/" "cirros" http://download.cirros-cloud.net/ ||
fail "failed cirros import"
FILTERS="$BASIC_FILTERS"
gmirror smoser-images/ smoser:images \
http://smoser.brickies.net/image-streams/streams/v1/index.json ||
fail "failed importing smoser images"