#!/usr/bin/env bash set -ueo pipefail if (( $# < 1 )); then echo "Invalid CLI args." echo "Usage:" echo "./build.sh path/to/printer.env [-c]" exit 1 fi if ! [ -f "$1" ]; then echo "Printer env file not found." echo "Path: $1" exit 1 fi if (( $# == 2 )); then if [ $2 == "-c" ]; then echo "Check mode- will not compile a binary!!!" export TEST_MODE=1 fi else export TEST_MODE=0 fi echo "Printer env file found: $1" echo -n "Loading config variables... " source "$1" echo "OK" if (( $TEST_MODE == 0 )); then filename="fw-${name// /_}-${board// /_}-ver$config_version.$fw_ext" echo "Artifact name will be: ""$filename""" fi if ! [ -d Marlin ]; then git clone https://github.com/MarlinFirmware/Marlin --depth 1 else cd Marlin git fetch --all git reset --hard origin/bugfix-2.1.x cd .. fi echo -n "Copying custom config files... " cp "$(dirname "$1")"/*.h Marlin/Marlin/ echo "OK" cd Marlin if (( $TEST_MODE == 0 )); then echo "Running PlatformIO build!" pio run -e "$pio_env" echo -n "Finished building. Copying firmware."$fw_ext"... " mkdir -p ../output cp .pio/build/"$pio_env"/firmware.$fw_ext ../output/"$filename" echo "OK" else echo "Running PlatformIO checks!" pio check -e "$pio_env" echo -n "Finished checks." fi cd ../../