build.sh 4.4 KB

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