build-tails 3.94 KB
Newer Older
1
2
3
#!/bin/sh

set -e
4
set -x
5

6
7
8
if [ -n "${TAILS_PROXY:-}" ]; then
	export http_proxy="${TAILS_PROXY}"
fi
9
10
11

as_root_do() {
	sudo \
12
13
14
15
16
17
		${RSYNC_PROXY:+RSYNC_PROXY="${RSYNC_PROXY}"} \
		${http_proxy:+http_proxy="${http_proxy}"} \
		${https_proxy:+https_proxy="${https_proxy}"} \
		${ftp_proxy:+ftp_proxy="${ftp_proxy}"} \
		${no_proxy:+no_proxy="${no_proxy}"} \
		${MKSQUASHFS_OPTIONS:+MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS}"} \
18
                ${TAILS_MERGE_BASE_BRANCH:+TAILS_MERGE_BASE_BRANCH="${TAILS_MERGE_BASE_BRANCH}"} \
bertagaz's avatar
bertagaz committed
19
20
21
		${GIT_COMMIT:+GIT_COMMIT="${GIT_COMMIT}"} \
		${GIT_REF:+GIT_REF="${GIT_REF}"} \
		${BASE_BRANCH_GIT_COMMIT:+BASE_BRANCH_GIT_COMMIT="${BASE_BRANCH_GIT_COMMIT}"} \
22
		"${@}"
23
24
}

25
cleanup() {
26
	[ -n "${BUILD_DIR}" ] || return 0
27
	cd /
28
	remove_build_dirs
29
	sudo rm -rf "${BUILD_DIR}"
30
31
32
}

remove_build_dirs() {
33
	for mountpoint in $(old_build_dirs | tac) ; do
34
		tries=0
35
36
		sudo lsof | grep --fixed-strings "${mountpoint}" || true
		while ! sudo umount -f --verbose "${mountpoint}" && [ $tries -lt 12 ]; do
37
			sudo fuser --ismountpoint --mount "${mountpoint}" --kill || true
38
39
40
			sleep 5
			tries=$(expr $tries + 1)
		done
41
		sudo rm -rf "${mountpoint}"
42
	done
43
44
}

45
old_build_dirs() {
intrigeri's avatar
intrigeri committed
46
	mount | \
47
	perl -ni -E 'say $mountpoint if (($mountpoint) = ($_ =~ m{^(?:aufs|tmpfs|devpts-live|proc-live|sysfs-live) on (/tmp/tails-build(?:-tmpfs)?\.[/[:alnum:]]+)}))'
48
49
}

50
51
52
53
ntp_synchronized() {
	timedatectl status | grep -qs -E '^\s*NTP\s+synchronized:\s+yes$'
}

54
55
if [ "${TAILS_BUILD_FAILURE_RESCUE}" != 1 ]; then
	trap cleanup EXIT
56
	remove_build_dirs
57
58
fi

anonym's avatar
anonym committed
59
TAILS_GIT_DIR="/home/vagrant/amnesia"
60
61
62
if [ ! -d "${TAILS_GIT_DIR}" ]; then
    git clone /amnesia.git/.git "${TAILS_GIT_DIR}"
fi
anonym's avatar
anonym committed
63
cd "${TAILS_GIT_DIR}"
64
65
66
67
68
69
70
71
72
# Mirror the branches amnesia.git tracks on its "origin" remote as if
# they were on our own "origin" remote, (i.e. under the origin/$REF
# name), even if it's untrue (our own "origin" is amnesia.git and has
# only one local ref, which is the branch we work on and that it has
# checked out as a local tracking branch). We need this for the base
# branch merge we do (if the 'mergebasebranch'/TAILS_MERGE_BASE_BRANCH
# option is set) later in auto/build.
git config remote.origin.fetch +refs/remotes/origin/*:refs/remotes/origin/*
git fetch --tags
bertagaz's avatar
bertagaz committed
73
74
git checkout --force "${GIT_REF}"
git reset --hard "${GIT_COMMIT}"
75
git submodule update --init
76

77
if as_root_do systemctl --quiet is-active apt-cacher-ng.service ; then
78
	as_root_do ./auto/scripts/update-acng-config
79
	as_root_do systemctl restart apt-cacher-ng.service
80
81
fi

82
83
84
85
86
87
88
89
90
if [ "${TAILS_OFFLINE_MODE}" != 1 ]; then
	as_root_do timedatectl set-ntp true
	echo -n "Waiting for the time to be synchronized..."
	while ! ntp_synchronized; do
		sleep 1
		echo -n "."
	done
	echo " done."
fi
91
92
93
if [ -n "$TAILS_DATE_OFFSET" ]; then
	as_root_do timedatectl set-ntp false
	DESIRED_DATE=$(date --utc --date="${TAILS_DATE_OFFSET} days" '+%F %T')
94
	echo "Setting system time to ${DESIRED_DATE}"
95
96
97
	as_root_do timedatectl set-time "$DESIRED_DATE"
fi

98
99
100
101
102
103
104
105
106
107
108
109
110
if [ "${TAILS_PROXY_TYPE}" = "vmproxy" ]; then
    # The apt-cacher-ng cache disk is 15G, so let's ensure at most 10G
    # of it is used there is 5G before each build, which should be
    # enough for any build, even if we have to download a complete set
    # of new packages for a new Debian release.
    /usr/lib/apt-cacher-ng/acngtool shrink 10G -f || \
        echo "The clean-up of apt-cacher-ng's cache failed: this is" \
             "not fatal and most likely just means that some disk" \
             "space could not be reclaimed -- in order to fix that" \
             "situation you need to manually investigate " \
             "/var/cache/apt-cacher-ng/apt-cacher-ng-log/main_*.html" >&2
fi

111
BUILD_DIR=$(mktemp -d /tmp/tails-build.XXXXXXXX)
112
if [ "${TAILS_RAM_BUILD}" ]; then
113
	as_root_do mount -t tmpfs -o "noatime,size=100%,mode=0770,uid=root,gid=${USER}" tmpfs "${BUILD_DIR}"
114
fi
115
as_root_do rsync -a "${TAILS_GIT_DIR}"/ "${BUILD_DIR}"/
116

117
cd "${BUILD_DIR}"
118
as_root_do lb config --cache false
119

120
as_root_do lb build
121

bertagaz's avatar
bertagaz committed
122
mv -f tails-* "${TAILS_GIT_DIR}/"