temperature-tower/build.sh

70 lines
1.6 KiB
Bash
Raw Normal View History

2023-11-26 12:58:19 -07:00
#! /bin/sh
set -e
2023-11-26 13:04:23 -07:00
# paramsets contains the location of the OpenSCAD parameter sets.
# see https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Customizer#Saving_Parameters_value_in_JSON_file
paramsets=params.json
2023-11-26 12:58:19 -07:00
2023-11-26 13:04:23 -07:00
# run executes a program after printing the commandline to stdout.
2023-11-26 12:58:19 -07:00
run () {
echo "=== $*"
"$@"
}
2023-11-26 13:04:23 -07:00
# render turns OpenSCAD echo into 3mf temperature changes.
#
# It does this by kludging together a PrusaSlicer-specific Metadata file.
2023-11-26 12:58:19 -07:00
render () {
basename=$1; shift
2023-11-26 15:34:26 -07:00
logfile=$basename.log
run openscad -o $basename "$@" temp-tower.scad 2>&1 | tee $logfile
2023-11-26 12:58:19 -07:00
2023-11-26 15:34:26 -07:00
rm -rf Metadata
2023-11-26 12:58:19 -07:00
mkdir -p Metadata
2023-11-26 15:34:26 -07:00
cat $logfile | while IFS=# read _ _ custom type path text _; do
[ "$custom#$type" = "CUSTOM#3mf" ] || continue
echo $text >> $path
done
2023-11-26 12:58:19 -07:00
run zip $basename $custom
2023-11-26 15:34:26 -07:00
rm $custom $logfile
2023-11-26 12:58:19 -07:00
rmdir Metadata
}
2023-11-26 13:04:23 -07:00
# paramsets lists all defined parameter sets, one per line.
2023-11-26 12:58:19 -07:00
paramsets () {
2023-11-26 13:04:23 -07:00
cat $paramsets | jq -r '.parameterSets | keys[] | select(length > 0)'
2023-11-26 12:58:19 -07:00
}
case "$1" in
-h|-help|--help)
cat <<EOD
2023-11-26 13:04:23 -07:00
Usage: $0 [-paramsets] [PARAMSET ...]
2023-11-26 12:58:19 -07:00
Generates .3mf files with temperature changes
for each given parameter set.
2023-11-26 13:04:23 -07:00
Parameter sets are specified in $paramsets.
2023-11-26 12:58:19 -07:00
-paramsets List all defined parameter sets, and exit.
EOD
exit 1
;;
-p*|--p*)
paramsets
exit
;;
"")
paramsets | while read paramset; do
2023-11-26 13:04:23 -07:00
render $paramset.3mf -P $paramset -p $paramsets
2023-11-26 12:58:19 -07:00
done
;;
*)
for paramset in "$@"; do
2023-11-26 13:04:23 -07:00
render $paramset.3mf -P $paramset -p $paramsets
2023-11-26 12:58:19 -07:00
done
;;
esac