From 9da33c963556a1f84c6ed3e4375f78507ebe8bf6 Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 19 Aug 2021 09:32:27 -0400 Subject: bash script now allows choosing which script to run updated bash script name --- build_docker.sh | 39 ---------------------------- run.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 39 deletions(-) delete mode 100755 build_docker.sh create mode 100755 run.sh diff --git a/build_docker.sh b/build_docker.sh deleted file mode 100755 index da10c3e..0000000 --- a/build_docker.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -cd "${0%/*}" || exit 1 - -# set the default Docker image tag to dactyl-keyboard -IMAGE_TAG="dactyl-keyboard" - -# by default, don't rebuild the image -REBUILD=false; - -# check for command line flags -while getopts 'ri:' flag; do - case "${flag}" in - r) REBUILD=true ;; # if the -r flag is set, we should rebuild the image - i) IMAGE_TAG="${OPTARG}" - esac -done - -# get the image ID, and save the return code so we'll know if the image exists -IMAGE_ID=$(docker inspect --type=image --format={{.Id}} ${IMAGE_TAG}) -INSPECT_RETURN_CODE=$? - -# if we were specifically told to rebuild, or if the image doesn't exists, then build the docker image -if $REBUILD || [ $INSPECT_RETURN_CODE -ne 0 ]; then - docker build -t ${IMAGE_TAG} -f docker/Dockerfile . -fi - -# run each of the dactyl commands in temporary containers -docker run --name dm-run -d --rm -v "`pwd`/src:/app/src" -v "`pwd`/things:/app/things" ${IMAGE_TAG} python3 -i dactyl_manuform.py > /dev/null 2>&1 -docker run --name dm-config -d --rm -v "`pwd`/:/app/src" -v "`pwd`/things:/app/things" ${IMAGE_TAG} python3 -i generate_configuration.py > /dev/null 2>&1 -docker run --name dm-release-build -d --rm -v "`pwd`/:/app/src" -v "`pwd`/things:/app/things" ${IMAGE_TAG} python3 -i model_builder.py > /dev/null 2>&1 - -# show progress indicator while until dm-run container completes -while $(docker inspect --format={{.Id}} dm-run > /dev/null 2>&1); do - echo -n "." - sleep 1.5 -done - -echo $'\n\nDactyl-Manuform export is complete!\n' \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..998e81d --- /dev/null +++ b/run.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +cd "${0%/*}" || exit 1 + + + +# set the default Docker image tag to dactyl-keyboard +IMAGE_TAG="dactyl-keyboard" + +# by default, don't rebuild the image +REBUILD=false; + +# get the command the user would like to run +COMMAND=${1:?A command is required. Try \'run help\'} + +case $COMMAND in + help) + echo "Usage:" + echo " run [command]" + echo "" + echo "Available Commands:" + echo " help show this help" + echo " generate output the keyboard files to the 'things' directory" + echo " configure " + echo " release " + echo "" + echo "Flags:" + echo " -r rebuild the docker image" + echo " -i the tag that should be applied to the docker image" + exit 0 + ;; + generate) + SCRIPT=dactyl_manuform.py + ;; + configure) + SCRIPT=generate_configuration.py + ;; + release) + SCRIPT=model_builder.py + ;; + *) + echo "Invalid command. Try 'run help'" + exit 1 +esac + + + +# check for command line flags +while getopts 'ri:' flag; do + case "${flag}" in + r) REBUILD=true ;; # if the -r flag is set, we should rebuild the image + i) IMAGE_TAG="${OPTARG}" + esac +done + +# get the image ID, and save the return code so we'll know if the image exists +IMAGE_ID=$(docker inspect --type=image --format={{.Id}} ${IMAGE_TAG}) +INSPECT_RETURN_CODE=$? + +# if we were specifically told to rebuild, or if the image doesn't exists, then build the docker image +if $REBUILD || [ $INSPECT_RETURN_CODE -ne 0 ]; then + docker build -t ${IMAGE_TAG} -f docker/Dockerfile . +fi + + + + +# run the command in a temporary container +docker run --name dm-run -d --rm -v "`pwd`/src:/app/src" -v "`pwd`/things:/app/things" ${IMAGE_TAG} python3 -i $SCRIPT > /dev/null 2>&1 + + + +# show progress indicator while until dm-run container completes +while $(docker inspect --format={{.Id}} dm-run > /dev/null 2>&1); do + echo -n "." + sleep 1.5 +done + +echo $'\n\nDactyl-Manuform export is complete!\n' \ No newline at end of file -- cgit v1.2.3