build 4.94 KB
Newer Older
1
#!/bin/bash
amnesia's avatar
amnesia committed
2

3
4
set -e
set -u
intrigeri's avatar
intrigeri committed
5
set -x
amnesia's avatar
amnesia committed
6

anonym's avatar
anonym committed
7
. "$(dirname $0)/scripts/utils.sh"
8

9
# get $BUILD_BASENAME
10
. tmp/build_environment
11

amnesia's avatar
amnesia committed
12
13
umask 022

14
15
16
17
18
19
20
21
### Clone all output, from this point on, to the log file

BUILD_LOG="${BUILD_BASENAME}.buildlog"
exec >  >(tee -a "$BUILD_LOG")
trap "kill -9 $! 2>/dev/null" EXIT HUP INT QUIT TERM
exec 2> >(tee -a "$BUILD_LOG" >&2)
trap "kill -9 $! 2>/dev/null" EXIT HUP INT QUIT TERM

22
23
### functions

24
25
26
27
print_iso_size () {
   local isofile="$1"
   [ -f "$isofile" ] || return 23
   size=$(stat --printf='%s' "$isofile")
28
   echo "I: The ISO is ${size} bytes large."
29
30
}

31
32
### Main

33
# we require building from git
34
35
git rev-parse --is-inside-work-tree &> /dev/null \
   || fatal "${PWD} is not a Git tree."
36

37
38
39
. config/amnesia
if [ -e config/amnesia.local ] ; then
   . config/amnesia.local
amnesia's avatar
amnesia committed
40
41
42
43
44
fi

# a clean starting point
rm -rf cache/stages_rootfs

45
# get LB_BINARY_IMAGES
46
47
. config/binary

48
# get LB_ARCHITECTURE and LB_DISTRIBUTION
49
. config/bootstrap
50

51
# save variables that are needed by chroot_local-hooks
52
echo "KERNEL_VERSION=${KERNEL_VERSION}" \
53
   >> config/chroot_local-includes/usr/share/tails/build/variables
54
echo "KERNEL_SOURCE_VERSION=${KERNEL_SOURCE_VERSION}" \
55
56
   >> config/chroot_local-includes/usr/share/tails/build/variables
echo "LB_DISTRIBUTION=${LB_DISTRIBUTION}" >> config/chroot_local-includes/usr/share/tails/build/variables
57
58
59
60
echo "POTFILES_DOT_IN='$(
         /bin/grep -E --no-filename '[^ #]*\.in$' po/POTFILES.in \
       | sed -e 's,^config/chroot_local-includes,,' | tr "\n" ' '
   )'" \
61
   >> config/chroot_local-includes/usr/share/tails/build/variables
62

63
64
# fix permissions on some source files that will be copied as is to the chroot.
# they may be wrong, e.g. if the Git repository was cloned with a strict umask.
65
chown    0:0   config/chroot_local-includes/etc/resolv.conf
66
chmod -R go+rX config/binary_local-includes/
67
chmod -R go+rX config/chroot_local-includes/etc
68
chmod    0440  config/chroot_local-includes/etc/sudoers.d/*
69
70
71
chmod    go+rX config/chroot_local-includes/lib
chmod    go+rX config/chroot_local-includes/lib/live
chmod -R go+rx config/chroot_local-includes/lib/live/config
72
chmod    go+rX config/chroot_local-includes/lib/live/mount
73
chmod -R go+rX config/chroot_local-includes/lib/systemd
74
chmod    go+rX config/chroot_local-includes/live
75
76
77
chmod -R go+rX config/chroot_local-includes/usr
chmod -R go+rx config/chroot_local-includes/usr/local/bin
chmod -R go+rx config/chroot_local-includes/usr/local/sbin
78
chmod -R go+rX config/chroot_local-includes/usr/share/doc
79
chmod -R go+rX config/chroot_local-includes/var
80
81
chmod -R go+rX config/chroot_apt
chmod -R go+rX config/chroot_sources
82

83
# normalize file timestamps
84
85
86
find \
   config/binary_local-includes \
   config/chroot_local-includes \
87
   wiki/src \
88
   -exec touch --date="@$SOURCE_DATE_EPOCH" '{}' \;
89

90
# build the image
amnesia's avatar
amnesia committed
91

92
# we need /debootstrap/deburis to build a manifest of used packages:
93
DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS:-} --keep-debootstrap-dir"
94

95
# we're not ready for merged-/usr yet: Debian#843461, Tails#11903
96
DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS:-} --no-merged-usr"
97

98
99
100
# use our own APT repository's key:
DEBOOTSTRAP_GNUPG_HOMEDIR=$(mktemp -d)
gpg --homedir "$DEBOOTSTRAP_GNUPG_HOMEDIR" \
101
    --no-tty \
102
    --import config/chroot_sources/tails.chroot.gpg
103
104
105
DEBOOTSTRAP_GNUPG_KEYRING="$DEBOOTSTRAP_GNUPG_HOMEDIR/pubring.kbx"
[ -e "$DEBOOTSTRAP_GNUPG_KEYRING" ] \
   || fatal "No debootstrap GnuPG keyring was created."
106
DEBOOTSTRAP_OPTIONS="$DEBOOTSTRAP_OPTIONS --keyring=$DEBOOTSTRAP_GNUPG_KEYRING"
107
108

export DEBOOTSTRAP_OPTIONS
109

110
: ${MKSQUASHFS_OPTIONS:='-comp xz -Xbcj x86 -b 1024K -Xdict-size 1024K -no-exports'}
111
MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -mem 512M -wildcards -ef chroot/usr/share/tails/build/mksquashfs-excludes"
112
export MKSQUASHFS_OPTIONS
113

114
# build the doc wiki
elouann's avatar
elouann committed
115
./build-website
116
117
118
119

# refresh translations of our programs
./refresh-translations || fatal "refresh-translations failed ($?)."

120
BUILD_ISO_FILENAME="${BUILD_BASENAME}.iso"
121
122
123
BUILD_MANIFEST="${BUILD_BASENAME}.build-manifest"
BUILD_APT_SOURCES="${BUILD_BASENAME}.apt-sources"
BUILD_PACKAGES="${BUILD_BASENAME}.packages"
124
BUILD_USB_IMAGE_FILENAME="${BUILD_BASENAME}.img"
amnesia's avatar
amnesia committed
125

126
127
128
129
130
131
132
133
134
(
   echo "Mirrors:"
   apt-mirror debian
   apt-mirror debian-security
   apt-mirror torproject
   echo "Additional sources:"
   cat config/chroot_sources/*.chroot
) > "$BUILD_APT_SOURCES"

135
echo "I: Building ISO image ${BUILD_ISO_FILENAME}..."
136
time lb build noauto ${@}
137
138
[ -e binary.iso ] || fatal "lb build failed ($?)."

139
echo "I: ISO image was successfully created"
140
print_iso_size binary.iso
141

142
echo "I: Hybriding it..."
143
144
145
146
isohybrid $AMNESIA_ISOHYBRID_OPTS binary.iso || fatal "isohybrid failed"
print_iso_size binary.iso
truncate -s %2048 binary.iso
print_iso_size binary.iso
147

148
echo "I: Renaming generated files..."
149
150
mv -i binary.iso "${BUILD_ISO_FILENAME}"
mv -i binary.packages "${BUILD_PACKAGES}"
151

152
echo "I: Generating build manifest..."
153
generate-build-manifest chroot/debootstrap "${BUILD_MANIFEST}"
154

155
echo "I: Creating USB image ${BUILD_USB_IMAGE_FILENAME}..."
156
create-usb-image-from-iso "${BUILD_ISO_FILENAME}"