diff options
Diffstat (limited to 'run.sh')
-rwxr-xr-x | run.sh | 84 |
1 files changed, 63 insertions, 21 deletions
@@ -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 |