build.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. # (c) 2014-2015 Helge Jung <hej@c3pb.de>
  3. #
  4. # This script is controlled by environment variables, the
  5. # first two being mandatory:
  6. #
  7. # BASE = Gluon Version (tag or commit, i.e. v2014.4)
  8. # BRANCH = Firmware Branch (stable/testing/experimental)
  9. # SITE = specific site repository commit-id (leave blank to use HEAD)
  10. # VERSION = the version tag (can only be empty if BRANCH=experimental)
  11. # BUILD_TS = build timestamp (format: %Y-%m-%d %H:%M:%S)
  12. # BROKEN = 0 (default) or 1, build the untested hardware model firmwares, too
  13. #
  14. if [ "_$BRANCH" == "_" ]; then
  15. echo "Please specify BRANCH environment variable." >&2
  16. exit 1
  17. fi
  18. if [ "_$BASE" == "_" ]; then
  19. echo "Please specify BASE environment variable (Gluon, i.e. 'v2014.3' or commit-id)." >&2
  20. exit 1
  21. fi
  22. if [ "_$VERSION" == "_" -a "$BRANCH" != "experimental" ]; then
  23. echo "Please specify VERSION environment variable (not necessary for experimental branch)." >&2
  24. exit 1
  25. fi
  26. MY_DIR=$(dirname $0)
  27. MY_DIR=$(readlink -f "$MY_DIR")
  28. CODE_DIR="src"
  29. pushd $MY_DIR > /dev/null
  30. [ "_$BUILD_TS" == "_" ] && export BUILD_TS=$(date +"%Y-%m-%d %H:%M:%S")
  31. . functions.sh
  32. ### CHECK THAT VERSION DOES NOT YET EXISTS
  33. [ -n "$VERSION" -a -x "versions/${VERSION}" ] && abort "There exists a version file for '$VERSION' ... you are trying to do something really stupid, aren't you?"
  34. ### INIT /src IF NECESSARY
  35. if [ ! -d "$CODE_DIR" ]; then
  36. info "Code directory does not exist yet - fetching Gluon ..."
  37. git clone https://github.com/freifunk-gluon/gluon.git "$CODE_DIR"
  38. fi
  39. ### INIT /src/site IF NECESSARY
  40. if [ ! -d "$CODE_DIR/site" ]; then
  41. info "Site repository does not exist, fetching it ..."
  42. git clone https://git.c3pb.de/freifunk-pb/site-ffpb.git "$CODE_DIR/site"
  43. fi
  44. ### CHECKOUT GLUON
  45. progress "Checking out GLUON '$BASE' ..."
  46. cd $CODE_DIR
  47. # TODO: check if gluon got modified and bail out if necessary
  48. git fetch ; git checkout -q $BASE
  49. [ "$?" -eq "0" ] || abort "Failed to checkout '$BASE' gluon base version, mimimi." >&2
  50. GLUON_COMMIT=$(git rev-list --max-count=1 HEAD)
  51. ### CHECKOUT SITE REPO
  52. progress "Checking out SITE REPO ..."
  53. cd site
  54. # TODO: check if site got modified locally and bail out if necessary
  55. if [ "_$SITE" == "_" ]; then
  56. # no specific site given - get the most current one
  57. git checkout -q $BRANCH ; git pull
  58. [ "$?" -eq "0" ] || abort "Failed to get newest '$BRANCH' in site repository, mimimi."
  59. else
  60. # commit given - use this one
  61. git checkout -q $SITE || abort "Failed to checkout requested site commit, mimimi."
  62. fi
  63. SITE_COMMIT=$(git rev-list --max-count=1 HEAD)
  64. cd ..
  65. ### CLEAN
  66. if [ "$BRANCH" != "experimental" ]; then
  67. progress "Cleaning your build environment ..."
  68. make clean
  69. fi
  70. ### PREPARE
  71. progress "Preparing the build environment (make update) ..."
  72. make update
  73. [ "$?" -eq "0" ] || abort "Failed to update the build environment, mimimi."
  74. ### BUILD TOOLCHAIN
  75. progress "Building toolchain if necessary (this is not possible on a fresh build) ..."
  76. faketime "$BUILD_TS" make toolchain -j 1
  77. ### BUILD FIRMWARE
  78. progress "Building the firmware - please stand by!"
  79. [ "_$BROKEN" == "_" ] && export BROKEN=0
  80. if [ "$BRANCH" != "experimental" ]; then
  81. GLUON_BRANCH=$BRANCH GLUON_RELEASE=$VERSION BROKEN=$BROKEN faketime "$BUILD_TS" make -j 4
  82. else
  83. GLUON_BRANCH=experimental BROKEN=$BROKEN faketime "$BUILD_TS" make -j 4
  84. fi
  85. [ "$?" -eq "0" ] || abort "Failed to build the firmware, mimimi."
  86. cd ..
  87. # write build info
  88. progress "Writing build info ..."
  89. mkdir -p "output/${BRANCH}"
  90. echo -en "" > "output/${BRANCH}/build_info.txt"
  91. echo "VERSION=${VERSION}" >> "output/${BRANCH}/build_info.txt"
  92. echo "GLUON=${GLUON_COMMIT} # ${BASE}" >> "output/${BRANCH}/build_info.txt"
  93. echo "BRANCH=${BRANCH}" >> "output/${BRANCH}/build_info.txt"
  94. echo "SITE=${SITE_COMMIT} # ${VERSION}" >> "output/${BRANCH}/build_info.txt"
  95. echo "TS=${BUILD_TS}" >> "output/${BRANCH}/build_info.txt"
  96. # compress all binaries into 7z archive
  97. progress "Assembling images.7z ..."
  98. [ -e "output/${BRANCH}/images.7z" ] && rm "output/${BRANCH}/images.7z"
  99. 7z a "output/${BRANCH}/images.7z" ${CODE_DIR}/images/sysupgrade/*.bin ${CODE_DIR}/images/factory/*.bin || abort "Failed to assemble images (did you install p7zip-full?)."
  100. # generate and copy manifest
  101. progress "Generating and copying manifest ..."
  102. pushd $CODE_DIR
  103. GLUON_BRANCH=$BRANCH make manifest || abort "Failed to generate the manifest, try running 'make manifest' in '$CODE_DIR' directory manually."
  104. popd
  105. cp "${CODE_DIR}/images/sysupgrade/${BRANCH}.manifest" "output/${BRANCH}/"
  106. # write (copy) version file
  107. cp "output/${BRANCH}/build_info.txt" "versions/${VERSION}"
  108. # The end. Finally.
  109. success "We're done, go and checkout your new firmware in output/${BRANCH}!"
  110. popd > /dev/null