build.sh 4.8 KB

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