build-tails 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/sh
  2. # This script is used by both our Vagrant and Jenkins -based build environments.
  3. set -e
  4. as_root_do() {
  5. sudo \
  6. ${RSYNC_PROXY:+RSYNC_PROXY="$RSYNC_PROXY"} \
  7. ${http_proxy:+http_proxy="$http_proxy"} \
  8. ${https_proxy:+https_proxy="$https_proxy"} \
  9. ${ftp_proxy:+ftp_proxy="$ftp_proxy"} \
  10. ${no_proxy:+no_proxy="$no_proxy"} \
  11. ${JENKINS_URL:+JENKINS_URL="$JENKINS_URL"} \
  12. ${MKSQUASHFS_OPTIONS:+MKSQUASHFS_OPTIONS="$MKSQUASHFS_OPTIONS"} \
  13. "$@"
  14. }
  15. usable_memory() {
  16. free -b | awk '/cache:/ { print $4 }'
  17. }
  18. cleanup() {
  19. [ -n "$BUILD_DIR" ] || return 0
  20. cd /
  21. remove_build_dirs
  22. sudo rm -rf "$BUILD_DIR"
  23. }
  24. remove_build_dirs() {
  25. for mountpoint in $(old_build_dirs | tac) ; do
  26. sudo umount -f -l "$mountpoint"
  27. sudo rm -rf "$mountpoint"
  28. done
  29. }
  30. old_build_dirs() {
  31. mount | \
  32. perl -ni -E 'say $mountpoint if (($mountpoint) = ($_ =~ m{^(?:aufs|tmpfs|devpts-live|proc-live|sysfs-live) on (/tmp/tails-build(?:-tmpfs)?\.[/[:alnum:]]+)}))'
  33. }
  34. trap cleanup EXIT
  35. if [ -n "$JENKINS_URL" ]; then
  36. if [ -z "$WORKSPACE" ]; then
  37. echo "WORKSPACE environment variable is not set. Aborting." >&2
  38. exit 2
  39. fi
  40. if [ -z "$GIT_BRANCH" ]; then
  41. echo "GIT_BRANCH environment variable is not set. Aborting." >&2
  42. exit 4
  43. fi
  44. if [ -z "$GIT_COMMIT" ]; then
  45. echo "GIT_COMMIT environment variable is not set. Aborting." >&2
  46. exit 5
  47. fi
  48. REV="${GIT_BRANCH##origin/}"
  49. COMMIT="$GIT_COMMIT"
  50. ARTIFACTS_DIR="$WORKSPACE/build-artifacts"
  51. else
  52. # Build triggered by Vagrant
  53. WORKSPACE=/home/vagrant/amnesia
  54. ARTIFACTS_DIR=/home/vagrant
  55. COMMIT="$(git --git-dir=/amnesia.git rev-parse --verify HEAD)"
  56. if git --git-dir=/amnesia.git symbolic-ref HEAD >/dev/null 2>&1; then
  57. # We are building from a branch
  58. REV="${1:-$(git --git-dir=/amnesia.git name-rev --name-only HEAD)}"
  59. else
  60. # We are (hopefully) building from a tag
  61. if ! REV="${1:-$(git --git-dir=/amnesia.git describe --tags --exact-match ${COMMIT})}"; then
  62. echo "It seems we are building from an untagged detached HEAD. Aborting." >&2
  63. exit 1
  64. fi
  65. fi
  66. test -d "$WORKSPACE" || git clone /amnesia.git "$WORKSPACE"
  67. cd "$WORKSPACE"
  68. git fetch --tags origin
  69. fi
  70. if [ "$TAILS_RAM_BUILD" ]; then
  71. remove_build_dirs
  72. fi
  73. cd "$WORKSPACE"
  74. git checkout --force "$REV"
  75. git reset --hard "$COMMIT"
  76. git submodule update --init
  77. if as_root_do systemctl --quiet is-active apt-cacher-ng.service ; then
  78. as_root_do ./auto/scripts/update-acng-config
  79. as_root_do systemctl restart apt-cacher-ng.service
  80. fi
  81. if [ -n "$JENKINS_URL" ]; then
  82. git clean --force -d -x
  83. fi
  84. if [ "$TAILS_CLEAN_BUILD" ]; then
  85. as_root_do lb clean --all
  86. git clean -fdx
  87. fi
  88. install -m 0755 -d "$ARTIFACTS_DIR"
  89. if [ -z "$JENKINS_URL" ]; then
  90. ./build-website
  91. fi
  92. BUILD_DIR=$(mktemp -d /tmp/tails-build.XXXXXXXX)
  93. if [ "$TAILS_RAM_BUILD" ]; then
  94. as_root_do mount -t tmpfs -o "noatime,size=100%,mode=0770,uid=root,gid=${USER}" tmpfs "${BUILD_DIR}"
  95. fi
  96. as_root_do rsync -a "$WORKSPACE"/ "$BUILD_DIR"/
  97. cd "$BUILD_DIR"
  98. as_root_do lb config --cache false
  99. as_root_do lb build
  100. if [ -n "$JENKINS_URL" ]; then
  101. ISO=$(ls *.iso)
  102. for file in tails-*; do
  103. sha512sum "$file" >> "$ISO.shasum"
  104. done
  105. gpg --batch --detach-sign --armor "$ISO.shasum"
  106. fi
  107. mv -f tails-* "$ARTIFACTS_DIR"