Mirror of espurna firmware for wireless switches and more
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.

124 lines
3.2 KiB

  1. #!/bin/bash
  2. set -e
  3. # defaults
  4. script_build_environments=true
  5. script_build_webui=true
  6. destination=../firmware
  7. # ALL env: sections from the .ini, even including those we don't want to build
  8. list_all_envs() {
  9. grep -E '^\[env:' platformio.ini | sed 's/\[env:\(.*\)\]/\1/g'
  10. }
  11. # -base is only supposed to be used through `extends = ...-base` for another env:
  12. # -ssl / -secure-client hard-code certificates, so not very useful to distribute those
  13. # -ota is a legacy option to conditionally load upload args, no longer needed
  14. list_available_envs() {
  15. list_all_envs | grep -Ev -- '-ota$|-ssl$|-secure-client.*$|^esp8266-.*base$' | sort
  16. }
  17. print_available() {
  18. echo "--------------------------------------------------------------"
  19. echo "Available environments:"
  20. for environment in $(list_available_envs); do
  21. echo "* $environment"
  22. done
  23. }
  24. set_default_environments() {
  25. environments=$(list_available_envs)
  26. }
  27. build_webui() {
  28. # Build system uses gulpscript.js to build web interface
  29. if [ ! -e node_modules/gulp/bin/gulp.js ]; then
  30. echo "--------------------------------------------------------------"
  31. echo "Installing dependencies..."
  32. npm ci
  33. fi
  34. # Recreate web interface (espurna/data/index.html.*.gz.h)
  35. echo "--------------------------------------------------------------"
  36. echo "Building web interface..."
  37. node node_modules/gulp/bin/gulp.js || exit
  38. }
  39. build_environments() {
  40. echo "--------------------------------------------------------------"
  41. echo "Building environment images..."
  42. local environments=$@
  43. if [ $# -eq 0 ]; then
  44. environments=$(list_available_envs)
  45. fi
  46. set -x
  47. for environment in $environments; do
  48. env ESPURNA_BUILD_NAME=$environment \
  49. ESPURNA_BUILD_DESTINATION="$destination" \
  50. ESPURNA_BUILD_SINGLE_SOURCE="1" \
  51. pio run --silent --environment $environment -t build-and-copy
  52. done
  53. set +x
  54. echo "--------------------------------------------------------------"
  55. }
  56. # Parameters
  57. print_getopts_help() {
  58. cat <<EOF
  59. Usage: $(basename "$0") [OPTION] <ENVIRONMENT>...
  60. Where ENVIRONMENT is environment name(s) from platformio.ini
  61. Options:
  62. -f VALUE Filter build stage by name to skip it
  63. Supported VALUEs are "environments" and "webui"
  64. Can be specified multiple times.
  65. -l Print available environments
  66. -d VALUE Destination to move the .bin file after building the environment
  67. -h Display this message
  68. EOF
  69. }
  70. while getopts "f:ld:h" opt; do
  71. case $opt in
  72. f)
  73. case "$OPTARG" in
  74. webui) script_build_webui=false ;;
  75. environments) script_build_environments=false ;;
  76. *)
  77. echo Must be either webui or environments
  78. exit
  79. ;;
  80. esac
  81. ;;
  82. l)
  83. print_available
  84. exit
  85. ;;
  86. d)
  87. destination=$OPTARG
  88. ;;
  89. h)
  90. print_getopts_help
  91. exit
  92. esac
  93. done
  94. shift $((OPTIND-1))
  95. # Welcome
  96. echo "--------------------------------------------------------------"
  97. echo "ESPURNA FIRMWARE BUILDER"
  98. if $script_build_webui ; then
  99. build_webui
  100. fi
  101. if $script_build_environments ; then
  102. build_environments $@
  103. fi