Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.2 KiB

6 years ago
6 years ago
  1. #!/bin/bash
  2. # Welcome
  3. echo "--------------------------------------------------------------"
  4. echo "ESPURNA FIRMWARE BUILDER"
  5. # Available environments
  6. travis=$(grep env: platformio.ini | grep travis | sed 's/\[env://' | sed 's/\]/ /' | sort)
  7. available=$(grep env: platformio.ini | grep -v ota | grep -v ssl | grep -v travis | sed 's/\[env://' | sed 's/\]/ /' | sort)
  8. # Parameters
  9. while getopts "lp" opt; do
  10. case $opt in
  11. l)
  12. echo "--------------------------------------------------------------"
  13. echo "Available environments:"
  14. for environment in $available; do
  15. echo "* $environment"
  16. done
  17. exit
  18. ;;
  19. p)
  20. par_build=1
  21. par_thread=${BUILDER_THREAD:-0}
  22. par_total_threads=${BUILDER_TOTAL_THREADS:-4}
  23. if [ ${par_thread} -ne ${par_thread} -o \
  24. ${par_total_threads} -ne ${par_total_threads} ]; then
  25. echo "Parallel threads should be a number."
  26. exit
  27. fi
  28. if [ ${par_thread} -ge ${par_total_threads} ]; then
  29. echo "Current thread is greater than total threads. Doesn't make sense"
  30. exit
  31. fi
  32. ;;
  33. esac
  34. done
  35. shift $((OPTIND-1))
  36. environments=$@
  37. # Environments to build
  38. if [ $# -eq 0 ]; then
  39. if [[ "${TRAVIS_BUILD_STAGE_NAME}" = "Release" ]] && [ ${par_build} ]; then
  40. environments=$(echo ${available} | \
  41. awk -v par_thread=${par_thread} -v par_total_threads=${par_total_threads} \
  42. '{ for (i = 1; i <= NF; i++) if (++j % par_total_threads == par_thread ) print $i; }')
  43. elif [[ "${TRAVIS_BUILD_STAGE_NAME}" = "Test" ]]; then
  44. environments=$travis
  45. else
  46. environments=$available
  47. fi
  48. fi
  49. # Get current version
  50. version=$(grep APP_VERSION espurna/config/version.h | awk '{print $3}' | sed 's/"//g')
  51. echo "Building for version $version"
  52. # Create output folder
  53. mkdir -p firmware
  54. if [ ! -e node_modules/gulp/bin/gulp.js ]; then
  55. echo "--------------------------------------------------------------"
  56. echo "Installing dependencies..."
  57. npm install --only=dev
  58. fi
  59. echo "--------------------------------------------------------------"
  60. echo "Get revision..."
  61. revision=$(git rev-parse HEAD)
  62. revision=${revision:0:7}
  63. cp espurna/config/version.h espurna/config/version.h.original
  64. sed -i -e "s/APP_REVISION \".*\"/APP_REVISION \"$revision\"/g" espurna/config/version.h
  65. # Recreate web interface
  66. echo "--------------------------------------------------------------"
  67. echo "Building web interface..."
  68. node node_modules/gulp/bin/gulp.js || exit
  69. # Build all the required firmware images
  70. echo "--------------------------------------------------------------"
  71. echo "Building firmware images..."
  72. mkdir -p ../firmware/espurna-$version
  73. for environment in $environments; do
  74. echo -n "* espurna-$version-$environment.bin --- "
  75. platformio run --silent --environment $environment || exit 1
  76. stat -c %s .pioenvs/$environment/firmware.bin
  77. mv .pioenvs/$environment/firmware.bin ../firmware/espurna-$version/espurna-$version-$environment.bin
  78. done
  79. echo "--------------------------------------------------------------"
  80. mv espurna/config/version.h.original espurna/config/version.h