summaryrefslogtreecommitdiff
path: root/clean-compile-mpost
blob: 6eba2331dead47e25e7ab5a2fdf74c274c8db19a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash

# clean-compile-mpost source.mp target-dir/ additional-file1 additional-file2 ...

if ! source=$(readlink -e "$1"); then
  >&2 printf 'Cannot read source "%s"\n' "$1"
  exit 1
fi
shift
if [ $# -eq 0 ]; then
  target_dir=$(pwd)
else
  if ! target_dir=$(readlink -e "$1"); then
    >&2 printf 'Cannot read target-dir "%s"\n' "$1"
    exit 1
  fi
  shift
fi
if ! [ -d "${target_dir}" ]; then
  >&2 printf 'Target-dir "%s" is no directory\n' "${target_dir}"
  exit 1
fi

tmp_dir=$(mktemp -d)
trap 'cd /; rm -rf --one-file-system "${tmp_dir}"' EXIT

for additional_file in "$@"; do
  if ! cp "${additional_file}" "${tmp_dir}/"; then
    >&2 printf 'Cannot not copy "%s"\n' "${additional_file}"
    exit 1
  fi
done
if ! cp "${source}" "${tmp_dir}/"; then
  >&2 printf 'Cannot not copy "%s"\n' "${additional_file}"
  exit 1
fi

cd "${tmp_dir}"
mpost "${source##*/}" || exit $?
find . \
  -type f \
  -name "*.mps" \
  -exec install -m644 -t "${target_dir}/" '{}' +