Move branches around.
[tails-test.git] / auto / build
blob1845bd61e4a5235db9232105995b4d9f0f8a0254
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 "POTFILES_DOT_IN='$(
43 /bin/grep -E --no-filename '[^ #]*\.in$' po/POTFILES.in \
44 | sed -e 's,^config/chroot_local-includes,,' | tr "\n" ' '
45 )'" \
46 >> config/chroot_local-includes/usr/share/amnesia/build/variables
48 # fix permissions on some source files that will be copied as is to the chroot.
49 # they may be wrong, e.g. if the Git repository was cloned with a strict umask.
50 chmod -R go+rX config/binary_local-includes/
51 chmod -R go+rX config/chroot_local-includes/etc
52 chmod 0440 config/chroot_local-includes/etc/sudoers.d/*
53 chmod go+rX config/chroot_local-includes/home
54 chmod go+rX config/chroot_local-includes/lib
55 chmod go+rX config/chroot_local-includes/lib/live
56 chmod -R go+rx config/chroot_local-includes/lib/live/config
57 chmod go+rX config/chroot_local-includes/live
58 chmod -R go+rX config/chroot_local-includes/usr
59 chmod -R go+rx config/chroot_local-includes/usr/local/bin
60 chmod -R go+rx config/chroot_local-includes/usr/local/sbin
61 chmod -R go+rX config/chroot_local-includes/usr/share/doc/tails
62 chmod -R go+rX config/chroot_local-includes/var
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 -Xbcj x86 -b 1024K -Xdict-size 1024K'}
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" | tr '/-' '_~')
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"
122 BUILD_START_FILENAME="${BUILD_DEST_FILENAME}.start.timestamp"
123 BUILD_END_FILENAME="${BUILD_DEST_FILENAME}.end.timestamp"
125 echo "Building $LB_BINARY_IMAGES image ${BUILD_BASENAME}..."
126 set -o pipefail
127 date --utc '+%s' > "$BUILD_START_FILENAME"
128 time eatmydata lb build noauto ${@} 2>&1 | tee "${BUILD_LOG}"
129 RET=$?
130 if [ -e "${BUILD_FILENAME}.${BUILD_FILENAME_EXT}" ]; then
131 if [ "$RET" -eq 0 ]; then
132 date --utc '+%s' > "$BUILD_END_FILENAME"
133 echo "Image was successfully created"
134 else
135 echo "Warning: image created, but lb build exited with code $RET"
137 echo "Renaming generated files..."
138 mv -i "${BUILD_FILENAME}.${BUILD_FILENAME_EXT}" "${BUILD_DEST_FILENAME}"
139 mv -i binary.packages "${BUILD_PACKAGES}"
140 else
141 fatal "lb build failed ($?)."