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.

101 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. environments=$available
  40. # Hook to build travis test envs
  41. if [[ "${TRAVIS_BRANCH}" != "" ]]; then
  42. re='^[0-9]+\.[0-9]+\.[0-9]+$'
  43. if ! [[ ${TRAVIS_BRANCH} =~ $re ]]; then
  44. environments=$travis
  45. fi
  46. fi
  47. fi
  48. # Get current version
  49. version=$(grep APP_VERSION espurna/config/version.h | awk '{print $3}' | sed 's/"//g')
  50. echo "Building for version $version"
  51. # Create output folder
  52. mkdir -p firmware
  53. if [ ! -e node_modules/gulp/bin/gulp.js ]; then
  54. echo "--------------------------------------------------------------"
  55. echo "Installing dependencies..."
  56. npm install --only=dev
  57. fi
  58. echo "--------------------------------------------------------------"
  59. echo "Get revision..."
  60. revision=$(git rev-parse HEAD)
  61. revision=${revision:0:7}
  62. cp espurna/config/version.h espurna/config/version.h.original
  63. sed -i -e "s/APP_REVISION \".*\"/APP_REVISION \"$revision\"/g" espurna/config/version.h
  64. # Recreate web interface
  65. echo "--------------------------------------------------------------"
  66. echo "Building web interface..."
  67. node node_modules/gulp/bin/gulp.js || exit
  68. # Build all the required firmware images
  69. echo "--------------------------------------------------------------"
  70. echo "Building firmware images..."
  71. mkdir -p ../firmware/espurna-$version
  72. if [ ${par_build} ]; then
  73. to_build=$(echo ${environments} | awk -v par_thread=${par_thread} -v par_total_threads=${par_total_threads} '{ for (i = 1; i <= NF; i++) if (++j % par_total_threads == par_thread ) print $i; }')
  74. else
  75. to_build=${environments}
  76. fi
  77. for environment in $to_build; do
  78. echo -n "* espurna-$version-$environment.bin --- "
  79. platformio run --silent --environment $environment || exit 1
  80. stat -c %s .pioenvs/$environment/firmware.bin
  81. mv .pioenvs/$environment/firmware.bin ../firmware/espurna-$version/espurna-$version-$environment.bin
  82. done
  83. echo "--------------------------------------------------------------"
  84. mv espurna/config/version.h.original espurna/config/version.h