build.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. if [ "_$BRANCH" == "_" ]; then
  3. echo "Please specify BRANCH environment variable." >&2
  4. exit 1
  5. fi
  6. if [ "_$BASE" == "_" ]; then
  7. echo "Please specify BASE environment variable (Gluon, i.e. 'v2014.3' or commit-id)." >&2
  8. exit 1
  9. fi
  10. if [ "_$VERSION" == "_" -a "$BRANCH" != "experimental" ]; then
  11. echo "Please specify VERSION environment variable (not necessary for experimental branch)." >&2
  12. exit 1
  13. fi
  14. MY_DIR=$(dirname $0)
  15. MY_DIR=$(readlink -f "$MY_DIR")
  16. CODE_DIR="src"
  17. pushd $MY_DIR > /dev/null
  18. . functions.sh
  19. if [ ! -d "$CODE_DIR" ]; then
  20. info "Code directory does not exist yet - fetching Gluon ..."
  21. git clone https://github.com/freifunk-gluon/gluon.git "$CODE_DIR"
  22. fi
  23. if [ ! -d "$CODE_DIR/site" ]; then
  24. info "Site repository does not exist, fetching it ..."
  25. git clone https://git.c3pb.de/freifunk-pb/site-ffpb.git "$CODE_DIR/site"
  26. fi
  27. ### CHECKOUT GLUON
  28. progress "Checking out GLUON '$BASE' ..."
  29. cd $CODE_DIR
  30. # TODO: check if gluon got modified and bail out if necessary
  31. git fetch ; git checkout -q $BASE
  32. [ "$?" -eq "0" ] || abort "Failed to checkout '$BASE' gluon base version, mimimi." >&2
  33. GLUON_COMMIT=$(git rev-list --max-count=1 HEAD)
  34. ### CHECKOUT SITE REPO
  35. progress "Pulling SITE REPO for '$BRANCH' ..."
  36. cd site
  37. # TODO: check if site got modified locally and bail out if necessary
  38. git checkout -q $BRANCH ; git pull
  39. [ "$?" -eq "0" ] || abort "Failed to checkout '$BRANCH' branch in site repository, mimimi."
  40. SITE_COMMIT=$(git rev-list --max-count=1 HEAD)
  41. cd ..
  42. ### CLEAN
  43. if [ "$BRANCH" != "experimental" ]; then
  44. progress "Cleaning your build environment ..."
  45. make clean
  46. fi
  47. ### PREPARE
  48. progress "Preparing the build environment (make update) ..."
  49. make update
  50. [ "$?" -eq "0" ] || abort "Failed to update the build environment, mimimi."
  51. ### BUILD TOOLCHAIN
  52. progress "Building toolchain if necessary (this is not possible on a fresh build) ..."
  53. make toolchain -j 1
  54. ### BUILD FIRMWARE
  55. progress "Building the firmware - please stand by!"
  56. if [ "$BRANCH" != "experimental" ]; then
  57. GLUON_BRANCH=$BRANCH GLUON_RELEASE=$VERSION make
  58. else
  59. GLUON_BRANCH=experimental make -j 4
  60. fi
  61. [ "$?" -eq "0" ] || abort "Failed to build the firmware, mimimi."
  62. cd ..
  63. # write build info
  64. progress "Writing build info ..."
  65. mkdir -p "output/${BRANCH}"
  66. echo -en "" > "output/${BRANCH}/build_info.txt"
  67. echo "VERSION=${VERSION}" >> "output/${BRANCH}/build_info.txt"
  68. echo "GLUON=${GLUON_COMMIT} # ${BASE}" >> "output/${BRANCH}/build_info.txt"
  69. echo "SITE=${SITE_COMMIT} # ${VERSION}" >> "output/${BRANCH}/build_info.txt"
  70. # compress all binaries into 7z archive
  71. progress "Assembling images.7z ..."
  72. [ -e "output/${BRANCH}/images.7z" ] && rm "output/${BRANCH}/images.7z"
  73. 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?)."
  74. # generate and copy manifest
  75. progress "Generating and copying manifest ..."
  76. make manifest || abort "Failed to generate the manifest, try running 'make manifest' in '$CODE_DIR' directory manually."
  77. cp "${CODE_DIR}/images/sysupgrade/${BRANCH}.manifest" "output/${BRANCH}/"
  78. success "We're done, go and checkout your new firmware in output/${BRANCH}!"
  79. popd > /dev/null