config 8.05 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
12
    fatal "${PWD} is not a Git tree. Exiting."
13 14
fi

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

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

29 30 31 32 33 34 35
# 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)"
36
    BUILD_BASENAME="tails-amd64-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_NOW}-${GIT_SHORT_ID}"
37 38 39
else
    if git_on_a_tag; then
        CLEAN_GIT_TAG=$(git_current_tag | tr '/-' '_~')
40
	BUILD_BASENAME="tails-amd64-${CLEAN_GIT_TAG}"
41 42 43 44 45 46 47 48 49 50
    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."

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

56 57
    echo "Merging base branch ${GIT_BASE_BRANCH}"
    echo "(at commit ${BASE_BRANCH_GIT_COMMIT})..."
58
    faketime -f "${SOURCE_DATE_FAKETIME}" \
59
        git merge --no-edit "${BASE_BRANCH_GIT_COMMIT}" \
60
	    || fatal "Failed to merge base branch."
61 62 63 64
    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')
65
    GIT_BASE_BRANCH_SHORT_ID=$(git rev-parse --verify --short "${BASE_BRANCH_GIT_COMMIT}")
66 67 68 69 70 71 72
    [ -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
73 74
mkdir -p tmp
echo "BUILD_BASENAME='${BUILD_BASENAME}'" > tmp/build_environment
amnesia's avatar
amnesia committed
75

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

90
# init variables
91
RUN_LB_CONFIG="lb config noauto"
amnesia's avatar
amnesia committed
92

93
# init config/ with defaults for the target distribution
94
$RUN_LB_CONFIG --distribution stretch ${@}
amnesia's avatar
amnesia committed
95

96
# set up everything for time-based snapshots:
97
if [ -n "${APT_SNAPSHOTS_SERIALS:-}" ]; then
98
    echo "Fixing 'latest' APT snapshots serials to: '${APT_SNAPSHOTS_SERIALS}'."
99
    apt-snapshots-serials prepare-build "${APT_SNAPSHOTS_SERIALS}"
100
else
intrigeri's avatar
intrigeri committed
101
    apt-snapshots-serials prepare-build
102
fi
103 104 105 106 107 108 109
# 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"
110

111 112
DEBIAN_MIRROR="$(apt-mirror debian)"
DEBIAN_SECURITY_MIRROR="$(apt-mirror debian-security)"
113 114
TORPROJECT_MIRROR="$(apt-mirror torproject)"

115 116 117
[ -n "$DEBIAN_MIRROR" ]          || fatal "\$DEBIAN_MIRROR is empty"
[ -n "$DEBIAN_SECURITY_MIRROR" ] || fatal "\$DEBIAN_SECURITY_MIRROR is empty"
[ -n "$TORPROJECT_MIRROR" ]      || fatal "\$TORPROJECT_MIRROR is empty"
118

119 120 121 122 123
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 \
124
    || fatal "APT mirror substitution failed with exit code $?"
125

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

163 164 165 166
install -d config/chroot_local-includes/etc/amnesia/

# environment
TAILS_WIKI_SUPPORTED_LANGUAGES="$(ikiwiki-supported-languages ikiwiki.setup)"
167 168
[ -n "$TAILS_WIKI_SUPPORTED_LANGUAGES" ] \
   || fatal "\$TAILS_WIKI_SUPPORTED_LANGUAGES is empty"
169 170 171
echo "TAILS_WIKI_SUPPORTED_LANGUAGES='${TAILS_WIKI_SUPPORTED_LANGUAGES}'" \
   >> config/chroot_local-includes/etc/amnesia/environment

amnesia's avatar
amnesia committed
172
# version
173
echo "${AMNESIA_FULL_VERSION}" > config/chroot_local-includes/etc/amnesia/version
amnesia's avatar
amnesia committed
174
if git rev-list HEAD 2>&1 >/dev/null; then
175 176
   git rev-list HEAD | head -n 1 >> config/chroot_local-includes/etc/amnesia/version
fi
177 178
echo "live-build: `dpkg-query -W -f='${Version}\n' live-build`" \
   >> config/chroot_local-includes/etc/amnesia/version
179 180 181 182 183
# os-release
cat >> config/chroot_local-includes/etc/os-release <<EOF
TAILS_PRODUCT_NAME="Tails"
TAILS_VERSION_ID="$AMNESIA_VERSION"
EOF
184 185 186
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
187 188

# changelog
189
cp debian/changelog config/chroot_local-includes/usr/share/doc/amnesia/Changelog
190

191
# custom APT sources
192 193
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
194

195 196 197 198 199 200 201 202
# 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/
203

204 205 206 207
# 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
208
# custom debootstrap script, setting some APT magic to log downloads:
209 210 211 212 213 214
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
215 216 217 218

# 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/