Neale Pickett
·
2023-11-26
postprocess.sh
1#! /bin/sh
2
3## Postprocess a 3mf file, adding in anything in the log
4
5set -e
6
7outfile=$(realpath $1)
8infile=$(realpath $2)
9logfile=$(realpath $3)
10
11tmpdir=$(mktemp -d --tmpdir 3mf.XXXXXXXXXX)
12trap "rm -rf $tmpdir" EXIT
13
14(cd $tmpdir && unzip $infile)
15
16cat $logfile | while IFS=# read _ _ custom type path text _; do
17 [ "$custom#$type" = "CUSTOM#3mf" ] || continue
18 basepath=$(dirname $path)
19 mkdir -p $tmpdir/$basepath
20 echo $text >> $tmpdir/$path
21done
22
23(cd $tmpdir && zip -r $outfile .)