summaryrefslogtreecommitdiff
path: root/run.sh
diff options
context:
space:
mode:
authorEdward <ed@itsed.com>2021-08-19 15:40:34 -0400
committerEdward <ed@itsed.com>2021-08-19 15:40:34 -0400
commit3a74bee2fcd1561f5cf23a4f57fe41062203313e (patch)
treefcae83d219fa8c50936fe3f2c39e74a82cd55491 /run.sh
parent092c1ec1d91728c3292011f060c2fe5a163998df (diff)
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=<name> argument to the script will set the config_name and save_dir. dactyl_manuform.py now also accepts a --config=<name> 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.
Diffstat (limited to 'run.sh')
-rwxr-xr-xrun.sh84
1 files changed, 63 insertions, 21 deletions
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 <docker-image-tag>] [-c <configuration-name>] <command>"
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/<configuration-name>.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