Add FAQ on ARM and BitTorrent
[tails/vicves.git] / auto / build
blob7970337779e125151ec344fb8e033051cbd89fed
1 #!/bin/bash
3 # set -x
5 umask 022
7 ### functions
9 fatal () {
10 echo "$*" >&2
11 exit 1
14 ### Main
16 # we require building from git
17 git rev-parse --is-inside-work-tree &> /dev/null \
18 || fatal "${PWD} is not a Git tree."
20 . config/amnesia
21 if [ -e config/amnesia.local ] ; then
22 . config/amnesia.local
25 # a clean starting point
26 rm -rf cache/stages_rootfs
28 # get LB_BINARY_IMAGES
29 . config/binary
31 # get LB_ARCHITECTURE and LB_DISTRIBUTION
32 . config/bootstrap
34 # build the doc wiki
35 ./build-wiki
37 # refresh translations of our programs
38 ./refresh-translations || fatal "refresh-translations failed ($?)."
40 # save variables that are needed by chroot_local-hooks
41 echo "LB_DISTRIBUTION=${LB_DISTRIBUTION}" >> config/chroot_local-includes/usr/share/amnesia/build/variables
42 echo "AMNESIA_SUPPORTED_LANGUAGES='${AMNESIA_SUPPORTED_LANGUAGES}'" >> config/chroot_local-includes/usr/share/amnesia/build/variables
43 echo "POTFILES_DOT_IN='$(
44 /bin/grep -E --no-filename '[^ #]*\.in$' po/POTFILES.in \
45 | sed -e 's,^config/chroot_local-includes,,' | tr "\n" ' '
46 )'" \
47 >> config/chroot_local-includes/usr/share/amnesia/build/variables
49 # fix permissions on some source files that will be copied as is to the chroot.
50 # they may be wrong, e.g. if the Git repository was cloned with a strict umask.
51 chmod -R go+rX config/binary_local-includes/
52 chmod -R go+rX config/chroot_local-includes/etc
53 chmod 0440 config/chroot_local-includes/etc/sudoers.d/*
54 chmod go+rX config/chroot_local-includes/home
55 chmod go+rX config/chroot_local-includes/lib
56 chmod go+rX config/chroot_local-includes/lib/live
57 chmod -R go+rx config/chroot_local-includes/lib/live/config
58 chmod go+rX config/chroot_local-includes/live
59 chmod -R go+rX config/chroot_local-includes/usr
60 chmod -R go+rx config/chroot_local-includes/usr/local/bin
61 chmod -R go+rx config/chroot_local-includes/usr/local/sbin
62 chmod -R go+rX config/chroot_local-includes/usr/share/doc/tails
63 chmod -R go+rX config/chroot_apt
64 chmod -R go+rX config/chroot_sources
66 # build the image
68 : ${MKSQUASHFS_OPTIONS:='-comp xz'}
69 MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -wildcards -ef chroot/usr/share/amnesia/build/mksquashfs-excludes"
70 export MKSQUASHFS_OPTIONS
72 # get git branch or tag so we can set the basename appropriately, i.e.:
73 # * if we build from a tag: tails-$ARCH-$TAG.iso
74 # * if we build from a branch: tails-$ARCH-$BRANCH-$VERSION-$DATE.iso
75 # * if Jenkins builds from a branch: tails-$ARCH-$BRANCH-$VERSION-$TIME-$COMMIT.iso
76 if GIT_REF="$(git symbolic-ref HEAD)"; then
77 GIT_BRANCH="${GIT_REF#refs/heads/}"
78 CLEAN_GIT_BRANCH=$(echo "$GIT_BRANCH" | sed 's,/,_,g')
79 if [ -n "$JENKINS_URL" ]; then
80 GIT_SHORT_ID="$(git rev-parse --short HEAD)"
81 BUILD_BASENAME="tails-${LB_ARCHITECTURE}-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_NOW}-${GIT_SHORT_ID}"
82 else
83 BUILD_BASENAME="tails-${LB_ARCHITECTURE}-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_TODAY}"
85 else
86 GIT_CURRENT_COMMIT="$(git rev-parse HEAD)"
87 if GIT_TAG="$(git describe --tags --exact-match ${GIT_CURRENT_COMMIT})"; then
88 CLEAN_GIT_TAG=$(echo "$GIT_TAG" | sed 's,/,_,g')
89 BUILD_BASENAME="tails-${LB_ARCHITECTURE}-${CLEAN_GIT_TAG}"
90 else
91 # this shouldn't reasonably happen (e.g. only if you checkout a
92 # tag, remove the tag and then build)
93 fatal "Neither a Git branch nor a tag, exiting."
97 case "$LB_BINARY_IMAGES" in
98 iso)
99 BUILD_FILENAME_EXT=iso
100 BUILD_FILENAME=binary
102 iso-hybrid)
103 BUILD_FILENAME_EXT=iso
104 BUILD_FILENAME=binary-hybrid
106 tar)
107 BUILD_FILENAME_EXT=tar.gz
108 BUILD_FILENAME=binary-tar
110 usb-hdd)
111 BUILD_FILENAME_EXT=img
112 BUILD_FILENAME=binary
115 fatal "Image type ${LB_BINARY_IMAGES} is not supported."
117 esac
118 BUILD_DEST_FILENAME="${BUILD_BASENAME}.${BUILD_FILENAME_EXT}"
119 BUILD_MANIFEST="${BUILD_DEST_FILENAME}.list"
120 BUILD_PACKAGES="${BUILD_DEST_FILENAME}.packages"
121 BUILD_LOG="${BUILD_DEST_FILENAME}.buildlog"
123 echo "Building $LB_BINARY_IMAGES image ${BUILD_BASENAME}..."
124 set -o pipefail
125 if time eatmydata lb build noauto ${@} 2>&1 | tee "${BUILD_LOG}" ; then
126 echo "Image was successfully created"
127 echo "Renaming generated files..."
128 mv -i "${BUILD_FILENAME}.${BUILD_FILENAME_EXT}" "${BUILD_DEST_FILENAME}"
129 mv -i binary.packages "${BUILD_PACKAGES}"
130 else
131 fatal "lb build failed ($?)."