build.sh 4.1 KB

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