]> git.ipfire.org Git - thirdparty/systemd.git/blame - semaphoreci/setup.sh
scripts: use 4 space indentation
[thirdparty/systemd.git] / semaphoreci / setup.sh
CommitLineData
841e1049 1#!/bin/bash
841e1049
EV
2set -ex
3
59273a0c
MP
4# default to Debian testing
5DISTRO=${DISTRO:-debian}
6RELEASE=${RELEASE:-buster}
7ARCH=${ARCH:-amd64}
8CONTAINER=${RELEASE}-${ARCH}
0d427d37
MP
9MAX_CACHE_AGE=604800 # one week
10CACHE=${SEMAPHORE_CACHE_DIR:=/tmp}/${CONTAINER}.img.tar.gz
11
12create_container() {
13 # create autopkgtest LXC image; this sometimes fails with "Unable to fetch
14 # GPG key from keyserver", so retry a few times
15 for retry in $(seq 5); do
16 sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH && break
17 sleep $((retry*retry))
18 done
19
20 # unconfine the container, otherwise some tests fail
21 echo 'lxc.apparmor.profile = unconfined' | sudo tee -a /var/lib/lxc/$CONTAINER/config
22
23 sudo lxc-start -n $CONTAINER
24
25 # enable source repositories so that apt-get build-dep works
26 sudo lxc-attach -n $CONTAINER -- sh -ex <<EOF
27sed 's/^deb/deb-src/' /etc/apt/sources.list >> /etc/apt/sources.list.d/sources.list
28# wait until online
29while [ -z "\$(ip route list 0/0)" ]; do sleep 1; done
30apt-get -q update
31apt-get -y dist-upgrade
32apt-get install -y eatmydata
33EOF
34 sudo lxc-stop -n $CONTAINER
35
36 # cache it
37 sudo tar cpzf "$CACHE" /var/lib/lxc/$CONTAINER
38}
59273a0c
MP
39
40# remove semaphore repos, some of them don't work and cause error messages
41sudo rm -f /etc/apt/sources.list.d/*
42
43# enable backports for latest LXC
44echo 'deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse' | sudo tee -a /etc/apt/sources.list.d/backports.list
45sudo apt-get -q update
46sudo apt-get install -y -t xenial-backports lxc
47sudo apt-get install -y python3-debian git dpkg-dev fakeroot
48
0d427d37 49AUTOPKGTESTDIR=$SEMAPHORE_CACHE_DIR/autopkgtest
59273a0c
MP
50[ -d $AUTOPKGTESTDIR ] || git clone --quiet --depth=1 https://salsa.debian.org/ci-team/autopkgtest.git "$AUTOPKGTESTDIR"
51
0d427d37
MP
52# use cached container image, unless older than a week
53if [ -e "$CACHE" ] && [ $(( $(date +%s) - $(stat -c %Y "$CACHE") )) -le $MAX_CACHE_AGE ]; then
54 sudo tar -C / -xpzf "$CACHE"
55else
56 create_container
57fi