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 --- run.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 run.sh (limited to 'run.sh') 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 From 092c1ec1d91728c3292011f060c2fe5a163998df Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 19 Aug 2021 09:45:07 -0400 Subject: added a 'build' command also removed check for a command argument; just let an empty command fall through to the default case --- run.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'run.sh') diff --git a/run.sh b/run.sh index 998e81d..2e07595 100755 --- a/run.sh +++ b/run.sh @@ -11,7 +11,9 @@ IMAGE_TAG="dactyl-keyboard" REBUILD=false; # get the command the user would like to run -COMMAND=${1:?A command is required. Try \'run help\'} +COMMAND=${1} + + case $COMMAND in help) @@ -20,6 +22,7 @@ case $COMMAND in echo "" echo "Available Commands:" echo " help show this help" + echo " build rebuild the docker image" echo " generate output the keyboard files to the 'things' directory" echo " configure " echo " release " @@ -29,6 +32,10 @@ case $COMMAND in echo " -i the tag that should be applied to the docker image" exit 0 ;; + build) + docker build -t ${IMAGE_TAG} -f docker/Dockerfile . + exit 0 + ;; generate) SCRIPT=dactyl_manuform.py ;; @@ -43,8 +50,6 @@ case $COMMAND in exit 1 esac - - # check for command line flags while getopts 'ri:' flag; do case "${flag}" in @@ -53,6 +58,8 @@ while getopts 'ri:' flag; do 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=$? @@ -64,12 +71,9 @@ 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 "." -- cgit v1.2.3 From 3a74bee2fcd1561f5cf23a4f57fe41062203313e Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 19 Aug 2021 15:40:34 -0400 Subject: allow multiple config files generate_configuration.py now only generates a configuration file; it no longer also runs dactyl_manuform.py. it will save the generated configuration file to the configs directory, and it will be named according to the config_name. passing a --config= argument to the script will set the config_name and save_dir. dactyl_manuform.py now also accepts a --config= argument. if non is passed, the default values from generate_configuration.py are used. otherwise, the defaults will be overridden by the values from the config specified. because of these changes, i removed run_config.json. it should have default values anyway, so it seemed reduandant and confusing. the run command has also been updated to allow for the config changes, and some bugs have also been fixed. --- run.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 21 deletions(-) (limited to 'run.sh') diff --git a/run.sh b/run.sh index 2e07595..ad6a922 100755 --- a/run.sh +++ b/run.sh @@ -10,26 +10,71 @@ IMAGE_TAG="dactyl-keyboard" # by default, don't rebuild the image REBUILD=false; -# get the command the user would like to run -COMMAND=${1} +# leave config empty to use default values +CONFIG="" + + +# check for command line flags +while test $# -gt 0; do + case "$1" in + -r|--rebuild) + REBUILD=true + shift + ;; + -t|--tag) + if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then + IMAGE_TAG=$2 + shift 2 + else + echo "Error: Argument for $1 is missing" >&2 + exit 1 + fi + ;; + -c|--config) + CONFIG=$2 + shift 2 + ;; + -*|--*) + echo "Error: Unknown flag $1" >&2 + exit 1 + ;; + *) + COMMAND=$1 + shift; + ;; + esac +done case $COMMAND in help) + echo "Dactyl-Manuform Keyboard Generator" + echo "" + echo "Use this tool to configure and generate files for building a keyboard. All" + echo "commands will be run in a Docker contianer, which will be built if it does" + echo "not already exist." + echo "" + echo "" echo "Usage:" - echo " run [command]" + echo " run [-r] [-i ] [-c ] " echo "" echo "Available Commands:" - echo " help show this help" - echo " build rebuild the docker image" - echo " generate output the keyboard files to the 'things' directory" - echo " configure " - echo " release " + echo " help Show this help" + echo " build Rebuild the docker image" + echo " release Run model_builder.py" + echo " generate Output the keyboard files to the './things' directory" + echo " configure Generate a configuration file with default values. The config" + echo " file will be saved to configs/.json. If the" + echo " -c flag is not set, the defailt config_name will be used." echo "" echo "Flags:" - echo " -r rebuild the docker image" - echo " -i the tag that should be applied to the docker image" + echo " -c Set the configuration file to use. This should be the name of the file" + echo " only, without a file extension, and it is relative to the './configs'" + echo " directory. For example, '-c my-custom-dm' will refer to a file located" + echo " at './configs/my-custom-dm.json'" + echo " -r Rebuild the docker image" + echo " -t The tag that should be applied to the docker image" exit 0 ;; build) @@ -50,15 +95,6 @@ case $COMMAND in 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}) @@ -70,9 +106,13 @@ if $REBUILD || [ $INSPECT_RETURN_CODE -ne 0 ]; then fi +# if a config file was specified, set the command line argument for the python script +if [[ ! -z $CONFIG ]]; then + CONFIG_OPTION="--config=${CONFIG}" +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 +docker run --name dm-run -d --rm -v "`pwd`/src:/app/src" -v "`pwd`/things:/app/things" -v "`pwd`/configs:/app/configs" ${IMAGE_TAG} python3 $SCRIPT $CONFIG_OPTION > /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 @@ -80,4 +120,6 @@ while $(docker inspect --format={{.Id}} dm-run > /dev/null 2>&1); do sleep 1.5 done -echo $'\n\nDactyl-Manuform export is complete!\n' \ No newline at end of file +echo "" +echo "Dactyl-Manuform '${COMMAND}' is complete!" +echo "" \ No newline at end of file -- cgit v1.2.3