config 7.92 KB
Newer Older
amnesia's avatar
amnesia committed
1
#! /bin/sh
2
# automatically run by "lb config"
amnesia's avatar
amnesia committed
3

4 5
set -e
set -u
6 7
set -x

8 9
. "$(dirname $0)/scripts/utils.sh"

10 11
# we require building from git
if ! git rev-parse --is-inside-work-tree; then
Tails developers's avatar
Typos.  
Tails developers committed
12
    echo "${PWD} is not a Git tree. Exiting."
13 14 15
    exit 1
fi

16 17 18
. config/amnesia
if [ -e config/amnesia.local ] ; then
   . config/amnesia.local
amnesia's avatar
amnesia committed
19
fi
20

21 22 23 24 25 26
if [ -n "${SOURCE_DATE_EPOCH}" ]; then
    CURRENT_EPOCH="$(date --utc +%s)"
    if [ "${SOURCE_DATE_EPOCH}" -gt "${CURRENT_EPOCH}" ]; then
        echo "SOURCE_DATE_EPOCH is set before the current time. Exiting."
        exit 1
    fi
anonym's avatar
anonym committed
27 28 29
else
    echo "SOURCE_DATE_EPOCH is not set. Exiting."
    exit 1
30 31
fi

32 33 34 35 36 37 38
# get git branch or tag so we can set the basename appropriately, i.e.:
# * if we build from a tag: tails-$ARCH-$TAG.iso
# * otherwise:              tails-$ARCH-$BRANCH-$VERSION-$TIME-$COMMIT.iso
GIT_BRANCH="$(git_current_branch)"
if [ -n "${GIT_BRANCH}" ]; then
    CLEAN_GIT_BRANCH=$(echo "$GIT_BRANCH" | sed 's,/,_,g')
    GIT_SHORT_ID="$(git_current_commit --short)"
39
    BUILD_BASENAME="tails-amd64-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_NOW}-${GIT_SHORT_ID}"
40 41 42
else
    if git_on_a_tag; then
        CLEAN_GIT_TAG=$(git_current_tag | tr '/-' '_~')
43
	BUILD_BASENAME="tails-amd64-${CLEAN_GIT_TAG}"
44 45 46 47 48 49 50 51 52 53
    else
	# this shouldn't reasonably happen (e.g. only if you checkout a
        # tag, remove the tag and then build)
	fatal "Neither a Git branch nor a tag, exiting."
    fi
fi

GIT_BASE_BRANCH=$(base_branch) \
    || fatal "GIT_BASE_BRANCH could not be guessed."

54
if [ "${TAILS_MERGE_BASE_BRANCH:-}" = 1 ] && \
55
       ! git_on_a_tag && [ "$GIT_BRANCH" != "$GIT_BASE_BRANCH" ] ; then
56 57
    [ -n "${BASE_BRANCH_GIT_COMMIT}" ] \
        || fatal "Base branch's top commit is not set."
58

59 60
    echo "Merging base branch ${GIT_BASE_BRANCH}"
    echo "(at commit ${BASE_BRANCH_GIT_COMMIT})..."
61
    faketime -f "${SOURCE_DATE_FAKETIME}" \
62
        git merge --no-edit "${BASE_BRANCH_GIT_COMMIT}" \
63
	    || fatal "Failed to merge base branch."
64 65 66 67
    git submodule update --init

    # Adjust BUILD_BASENAME to embed the base branch name and its top commit
    CLEAN_GIT_BASE_BRANCH=$(echo "$GIT_BASE_BRANCH" | sed 's,/,_,g')
68
    GIT_BASE_BRANCH_SHORT_ID=$(git rev-parse --verify --short "${BASE_BRANCH_GIT_COMMIT}")
69 70 71 72 73 74 75
    [ -n "${GIT_BASE_BRANCH_SHORT_ID}" ] \
        || fatal "Base branch's top commit short ID could not be guessed."
    BUILD_BASENAME="${BUILD_BASENAME}+${CLEAN_GIT_BASE_BRANCH}"
    BUILD_BASENAME="${BUILD_BASENAME}@${GIT_BASE_BRANCH_SHORT_ID}"
fi

# save variables that lb build needs
76 77
mkdir -p tmp
echo "BUILD_BASENAME='${BUILD_BASENAME}'" > tmp/build_environment
amnesia's avatar
amnesia committed
78

79 80
# sanity checks
if grep -qs -E '^Pin:\s+release\s+.*a=' config/chroot_apt/preferences ; then
anonym's avatar
anonym committed
81
    echo "Found unsupported a= syntax in config/chroot_apt/preferences,"
82 83 84
    echo "use n= instead. Exiting."
    exit 1
fi
85 86 87 88 89 90
if grep -qs -E '^Pin:\s+release\s+.*o=Debian Backports' \
	config/chroot_apt/preferences ; then
    echo "Found unsupported 'o=Debian Backports' syntax,"
    echo "in config/chroot_apt/preferences. Use o=Debian instead. Exiting."
    exit 1
fi
91 92 93 94
if [ $(dpkg --print-architecture) != amd64 ] ; then
    echo "Only amd64 build systems are supported"
    exit 1
fi
95

96
# init variables
97
RUN_LB_CONFIG="lb config noauto"
amnesia's avatar
amnesia committed
98

99
# init config/ with defaults for the target distribution
100
$RUN_LB_CONFIG --distribution stretch ${@}
amnesia's avatar
amnesia committed
101

102
# set up everything for time-based snapshots:
103
if [ -n "${APT_SNAPSHOTS_SERIALS:-}" ]; then
104
    echo "Fixing 'latest' APT snapshots serials to: '${APT_SNAPSHOTS_SERIALS}'."
105
    apt-snapshots-serials prepare-build "${APT_SNAPSHOTS_SERIALS}"
106
else
intrigeri's avatar
intrigeri committed
107
    apt-snapshots-serials prepare-build
108
fi
109 110 111 112 113 114 115
# record what APT snapshots this build is going to use, so that one
# can try to reproduce it more reliably
JENKINS_ENV_PROPERTIES=tails-build-env.list
echo "# This file is in Java property file format"   >> "$JENKINS_ENV_PROPERTIES"
echo "# (https://en.wikipedia.org/wiki/.properties)" >> "$JENKINS_ENV_PROPERTIES"
echo "APT_SNAPSHOTS_SERIALS = $(apt-snapshots-serials cat-json tmp/APT_snapshots.d)" \
   >> "$JENKINS_ENV_PROPERTIES"
116

117 118
DEBIAN_MIRROR="$(apt-mirror debian)"
DEBIAN_SECURITY_MIRROR="$(apt-mirror debian-security)"
119 120
TORPROJECT_MIRROR="$(apt-mirror torproject)"

121 122 123 124
[ -n "$DEBIAN_MIRROR" ]          || exit 1
[ -n "$DEBIAN_SECURITY_MIRROR" ] || exit 1
[ -n "$TORPROJECT_MIRROR" ]      || exit 1

125 126 127 128 129 130
perl -pi \
     -E \
       "s|^(deb(?:-src)?\s+)https?://ftp[.]us[.]debian[.]org/debian/?(\s+)|\$1$DEBIAN_MIRROR\$2| ; \
        s|^(deb(?:-src)?\s+)https?://deb[.]torproject[.]org/torproject[.]org/?(\s+)|\$1$TORPROJECT_MIRROR\$2|" \
    config/chroot_sources/*.chroot \
    || exit 1
131

amnesia's avatar
amnesia committed
132
# set Amnesia's general options
133
$RUN_LB_CONFIG \
134
   --verbose \
135
   --apt-recommends false \
136
   --architecture amd64 \
Tails developers's avatar
Tails developers committed
137
   --backports false \
138
   --binary-images iso \
139
   --binary-indices false \
140 141 142 143
   --cache          false \
   --cache-indices  false \
   --cache-packages false \
   --cache-stages   false \
144
   --checksums none \
amnesia's avatar
amnesia committed
145
   --bootappend-live "${AMNESIA_APPEND}" \
Cyril Brulebois's avatar
Cyril Brulebois committed
146
   --bootstrap debootstrap \
147
   --bootstrap-config tails-build-jessie \
148
   --archive-areas "main contrib non-free" \
149
   --includes none \
150
   --iso-application="The Amnesic Incognito Live System" \
151
   --iso-publisher="https://tails.boum.org/" \
amnesia's avatar
amnesia committed
152
   --iso-volume="TAILS ${AMNESIA_FULL_VERSION}" \
153
   --linux-flavours amd64 \
amnesia's avatar
amnesia committed
154
   --memtest none \
155 156 157 158 159
   --mirror-binary              "$DEBIAN_MIRROR" \
   --mirror-bootstrap           "$DEBIAN_MIRROR" \
   --mirror-chroot              "$DEBIAN_MIRROR" \
   --mirror-binary-security     "$DEBIAN_SECURITY_MIRROR" \
   --mirror-chroot-security     "$DEBIAN_SECURITY_MIRROR" \
160
   --packages-lists="standard" \
161
   --tasks="standard" \
intrigeri's avatar
intrigeri committed
162
   --linux-packages="linux-image-${KERNEL_VERSION}" \
163
   --syslinux-menu vesamenu \
T(A)ILS developers's avatar
T(A)ILS developers committed
164
   --syslinux-splash data/splash.png \
amnesia's avatar
amnesia committed
165
   --syslinux-timeout 4 \
166
   --initramfs=live-boot \
amnesia's avatar
amnesia committed
167 168
   ${@}

169 170 171 172 173 174 175 176
install -d config/chroot_local-includes/etc/amnesia/

# environment
TAILS_WIKI_SUPPORTED_LANGUAGES="$(ikiwiki-supported-languages ikiwiki.setup)"
[ -n "$TAILS_WIKI_SUPPORTED_LANGUAGES" ] || exit 16
echo "TAILS_WIKI_SUPPORTED_LANGUAGES='${TAILS_WIKI_SUPPORTED_LANGUAGES}'" \
   >> config/chroot_local-includes/etc/amnesia/environment

amnesia's avatar
amnesia committed
177
# version
178
echo "${AMNESIA_FULL_VERSION}" > config/chroot_local-includes/etc/amnesia/version
amnesia's avatar
amnesia committed
179
if git rev-list HEAD 2>&1 >/dev/null; then
180 181
   git rev-list HEAD | head -n 1 >> config/chroot_local-includes/etc/amnesia/version
fi
182 183
echo "live-build: `dpkg-query -W -f='${Version}\n' live-build`" \
   >> config/chroot_local-includes/etc/amnesia/version
184 185 186 187 188
# os-release
cat >> config/chroot_local-includes/etc/os-release <<EOF
TAILS_PRODUCT_NAME="Tails"
TAILS_VERSION_ID="$AMNESIA_VERSION"
EOF
189 190 191
if echo "$AMNESIA_VERSION" | grep -qs -E '~(alpha|beta|rc)[0-9]*$' ; then
    echo 'TAILS_CHANNEL="alpha"' >> config/chroot_local-includes/etc/os-release
fi
192 193

# changelog
194
cp debian/changelog config/chroot_local-includes/usr/share/doc/amnesia/Changelog
195

196
# custom APT sources
197 198
tails-custom-apt-sources > config/chroot_sources/tails.chroot \
   || fatal "tails-custom-apt-sources failed with exit code $?"
Cyril Brulebois's avatar
Cyril Brulebois committed
199

200 201 202 203 204 205 206 207
# tails-transform-mirror-url and its dependencies
install -m 0755 \
   submodules/mirror-pool-dispatcher/bin/tails-transform-mirror-url \
   config/chroot_local-includes/usr/local/bin/
install -m 0755 -d config/chroot_local-includes/usr/local/lib/nodejs
install -m 0755 \
   submodules/mirror-pool-dispatcher/lib/js/mirror-dispatcher.js \
   config/chroot_local-includes/usr/local/lib/nodejs/
208

209 210 211 212
# aufs4-standalone
rm -rf config/chroot_local-includes/usr/src/aufs4-standalone
cp -a submodules/aufs4-standalone config/chroot_local-includes/usr/src/

Cyril Brulebois's avatar
Cyril Brulebois committed
213
# custom debootstrap script, setting some APT magic to log downloads:
214 215 216 217 218 219
patch \
    --follow-symlinks \
    --output=/usr/share/debootstrap/scripts/tails-build-jessie \
    /usr/share/debootstrap/scripts/jessie \
    data/debootstrap/scripts/jessie.patch
sed -i "s,%%topdir%%,$(pwd)," /usr/share/debootstrap/scripts/tails-build-jessie
220 221 222 223

# Make the python library available in Tails
install -d -m 2777 config/chroot_local-includes/tmp/
cp -r submodules/pythonlib config/chroot_local-includes/tmp/