diff --git a/scripts/zmk_build.sh b/scripts/zmk_build.sh index 1793568..8297fd0 100755 --- a/scripts/zmk_build.sh +++ b/scripts/zmk_build.sh @@ -5,13 +5,17 @@ while [[ $# -gt 0 ]]; do case $1 in # needed when user isn't in docker group -s|--su) - DOCKER_SUDO="sudo" + SUDO="sudo" ;; -l|--local) RUNWITH_DOCKER="false" ;; + -c|--clear-cache) + CLEAR_CACHE="true" + ;; + # comma or space separated list of boards (use quotes if space separated) # if ommitted, will compile list of boards in build.yaml -b|--board) @@ -20,7 +24,7 @@ while [[ $# -gt 0 ]]; do ;; -v|--version) - WEST_VERSION="$2" + ZEPHYR_VERSION="$2" shift ;; @@ -69,8 +73,8 @@ while [[ $# -gt 0 ]]; do done # Set defaults -[[ -z $WEST_VERSION ]] && WEST_VERSION="3.0" -[[ -z $RUNWITH_DOCKER ]] && RUNWITH_DOCKER=true +[[ -z $ZEPHYR_VERSION ]] && ZEPHYR_VERSION="3.0" +[[ -z $RUNWITH_DOCKER ]] && RUNWITH_DOCKER="true" [[ -z $OUTPUT_DIR ]] && OUTPUT_DIR="$WINHOME/Downloads" [[ -z $LOG_DIR ]] && LOG_DIR="/tmp" @@ -83,7 +87,9 @@ done [[ -z $BOARDS ]] && BOARDS="$(grep '^[[:space:]]*\-[[:space:]]*board:' $HOST_CONFIG_DIR/build.yaml | sed 's/^.*: *//')" -DOCKER_IMG="zmkfirmware/zmk-dev-arm:$WEST_VERSION" +[[ -z $CLEAR_CACHE ]] && CLEAR_CACHE="false" + +DOCKER_IMG="zmkfirmware/zmk-dev-arm:$ZEPHYR_VERSION" # +-------------------------+ # | AUTOMATE CONFIG OPTIONS | @@ -121,20 +127,37 @@ fi if [[ $RUNWITH_DOCKER = true ]] then echo "Build mode: docker" - DOCKER_CMD="$DOCKER_SUDO docker run --name zmk --rm -w $DOCKER_ZMK_DIR/app \ + DOCKER_CMD="$SUDO docker run --name zmk-$ZEPHYR_VERSION --rm \ --mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \ --mount type=bind,source=$HOST_CONFIG_DIR,target=$DOCKER_CONFIG_DIR,readonly \ - --mount type=volume,source=zmk-root-user-$WEST_VERSION,target=/root \ - --mount type=volume,source=zmk-zephyr-$WEST_VERSION,target=$DOCKER_ZMK_DIR/zephyr \ - --mount type=volume,source=zmk-zephyr-modules-$WEST_VERSION,target=$DOCKER_ZMK_DIR/modules \ - --mount type=volume,source=zmk-zephyr-tools-$WEST_VERSION,target=$DOCKER_ZMK_DIR/tools \ - $DOCKER_IMG" - SUFFIX="${WEST_VERSION}_docker" + --mount type=volume,source=zmk-root-user-$ZEPHYR_VERSION,target=/root \ + --mount type=volume,source=zmk-zephyr-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/zephyr \ + --mount type=volume,source=zmk-zephyr-modules-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/modules \ + --mount type=volume,source=zmk-zephyr-tools-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/tools" + + # Reset volumes + if [[ $CLEAR_CACHE = true ]] + then + $SUDO docker volume rm $(sudo docker volume ls -q | grep "^zmk-.*-$ZEPHYR_VERSION$") + fi + + # Update west if needed + OLD_WEST="/root/west.yml.old" + $DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" /bin/bash -c " \ + if [[ ! -f .west/config ]]; then west init -l app/; fi \ + && if [[ -f $OLD_WEST ]]; then md5_old=\$(md5sum $OLD_WEST | cut -d' ' -f1); fi \ + && [[ \$md5_old != \$(md5sum app/west.yml | cut -d' ' -f1) ]] \ + && west update \ + && cp app/west.yml $OLD_WEST" + + # Build parameters + DOCKER_PREFIX="$DOCKER_CMD -w $DOCKER_ZMK_DIR/app $DOCKER_IMG" + SUFFIX="${ZEPHYR_VERSION}_docker" CONFIG_DIR="$DOCKER_CONFIG_DIR/config" else echo "Build mode: local" - SUFFIX="${WEST_VERSION}" + SUFFIX="${ZEPHYR_VERSION}" CONFIG_DIR="$HOST_CONFIG_DIR/config" fi @@ -143,7 +166,7 @@ compile_board () { echo -en "\n$(tput setaf 2)Building $1... $(tput sgr0)" BUILD_DIR="${1}_$SUFFIX" LOGFILE="$LOG_DIR/zmk_build_$1.log" - $DOCKER_CMD west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \ + $DOCKER_PREFIX west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \ -- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev > "$LOGFILE" 2>&1 if [[ $? -eq 0 ]] then diff --git a/scripts/zmk_docker_install.sh b/scripts/zmk_docker_install.sh deleted file mode 100755 index caa02e9..0000000 --- a/scripts/zmk_docker_install.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -# Parse input arguments -while [[ $# -gt 0 ]]; do - case $1 in - # needed when user isn't in docker group - -s|--sudu) - SUDO="sudo" - ;; - - -v|--version) - WEST_VERSION="$2" - shift - ;; - - --host-zmk-dir) - HOST_ZMK_DIR="$2" - shift - ;; - - --docker-zmk-dir) - DOCKER_ZMK_DIR="$2" - shift - ;; - - *) - echo "Unknown option $1" - exit 1 - ;; - - esac - shift -done - -# Set defaults -[[ -z $WEST_VERSION ]] && WEST_VERSION="3.0" -[[ -z $HOST_ZMK_DIR ]] && HOST_ZMK_DIR="$HOME/zmk" -[[ -z $DOCKER_ZMK_DIR ]] && DOCKER_ZMK_DIR="/workspace/zmk" - -DOCKER_IMG="zmkfirmware/zmk-dev-arm:$WEST_VERSION" -DOCKER_CMD="$SUDO docker run --name zmk-$WEST_VERSION --rm \ - --mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \ - --mount type=volume,source=zmk-root-user-$WEST_VERSION,target=/root \ - --mount type=volume,source=zmk-zephyr-$WEST_VERSION,target=$DOCKER_ZMK_DIR/zephyr \ - --mount type=volume,source=zmk-zephyr-modules-$WEST_VERSION,target=$DOCKER_ZMK_DIR/modules \ - --mount type=volume,source=zmk-zephyr-tools-$WEST_VERSION,target=$DOCKER_ZMK_DIR/tools" - -# Reset volumes -$SUDO docker volume rm $(sudo docker volume ls -q | grep "^zmk-.*-$WEST_VERSION$") - -# Install west -$DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" west init -l app/ -$DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" west update - -# Install docosaurus -$DOCKER_CMD -w "$DOCKER_ZMK_DIR/docs" "$DOCKER_IMG" npm ci - diff --git a/scripts/zmk_run_docker.sh b/scripts/zmk_run_docker.sh new file mode 100755 index 0000000..9435c77 --- /dev/null +++ b/scripts/zmk_run_docker.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +# This script sets up a docker development environment and starts an interactive shell. +# For a one-stop-shop script for building boards, which sets up a build environment in +# the background and re-uses it across runs, see zmk_build.sh instead. + +# Parse input arguments +while [[ $# -gt 0 ]]; do + case $1 in + # needed when user isn't in docker group + -s|--sudu) + SUDO="sudo" + ;; + + -c|--clear-cache) + CLEAR_CACHE="true" + ;; + + -d|--install-doc-tools) + DOC_TOOLS="true" + ;; + + -v|--version) + ZEPHYR_VERSION="$2" + shift + ;; + + --host-config-dir) + HOST_CONFIG_DIR="$2" + shift + ;; + + --host-zmk-dir) + HOST_ZMK_DIR="$2" + shift + ;; + + --docker-config-dir) + DOCKER_CONFIG_DIR="$2" + shift + ;; + + --docker-zmk-dir) + DOCKER_ZMK_DIR="$2" + shift + ;; + + *) + echo "Unknown option $1" + exit 1 + ;; + + esac + shift +done + +# Set defaults +[[ -z $ZEPHYR_VERSION ]] && ZEPHYR_VERSION="3.0" + +[[ -z $HOST_ZMK_DIR ]] && HOST_ZMK_DIR="$HOME/zmk" +[[ -z $HOST_CONFIG_DIR ]] && HOST_CONFIG_DIR="$HOME/zmk-config" + +[[ -z $DOCKER_ZMK_DIR ]] && DOCKER_ZMK_DIR="/workspace/zmk" +[[ -z $DOCKER_CONFIG_DIR ]] && DOCKER_CONFIG_DIR="/workspace/zmk-config" + +[[ -z $CLEAR_CACHE ]] && CLEAR_CACHE="false" +[[ -z $DOC_TOOLS ]] && DOC_TOOLS="false" + +DOCKER_IMG="zmkfirmware/zmk-dev-arm:$ZEPHYR_VERSION" +DOCKER_CMD="$SUDO docker run --name zmk-$ZEPHYR_VERSION --rm \ + --mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \ + --mount type=bind,source=$HOST_CONFIG_DIR,target=$DOCKER_CONFIG_DIR \ + --mount type=volume,source=zmk-root-user-$ZEPHYR_VERSION,target=/root \ + --mount type=volume,source=zmk-zephyr-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/zephyr \ + --mount type=volume,source=zmk-zephyr-modules-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/modules \ + --mount type=volume,source=zmk-zephyr-tools-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/tools" + +# Reset volumes +if [[ $CLEAR_CACHE = true ]] +then + $SUDO docker volume rm $(sudo docker volume ls -q | grep "^zmk-.*-$ZEPHYR_VERSION$") +fi + +# Update west if needed +OLD_WEST="/root/west.yml.old" +$DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" /bin/bash -c " \ + if [[ ! -f .west/config ]]; then west init -l app/; fi \ + && if [[ -f $OLD_WEST ]]; then md5_old=\$(md5sum $OLD_WEST | cut -d' ' -f1); fi \ + && [[ \$md5_old != \$(md5sum app/west.yml | cut -d' ' -f1) ]] \ + && cp app/west.yml $OLD_WEST \ + && west update" + +# Install docosaurus +if [[ $DOC_TOOLS = true ]] +then + $DOCKER_CMD -w "$DOCKER_ZMK_DIR/docs" "$DOCKER_IMG" npm ci +fi + +# Start interactive shell +$DOCKER_CMD -w "$DOCKER_ZMK_DIR" -it "$DOCKER_IMG" /bin/bash +