-
Notifications
You must be signed in to change notification settings - Fork 0
/
montag-docker.sh
executable file
·54 lines (43 loc) · 1.42 KB
/
montag-docker.sh
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
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
IMAGE="${MONTAG_IMAGE:-oci.guero.org/montag:latest}"
ENGINE="${CONTAINER_ENGINE:-docker}"
ENCODING="utf-8"
while getopts i:o:s:e: opts; do
case ${opts} in
i) IN_FILE=${OPTARG} ;;
o) OUT_FILE=${OPTARG} ;;
s) SWEARS_FILE=${OPTARG} ;;
e) ENCODING=${OPTARG} ;;
esac
done
if [[ -z "${IN_FILE}" ]] || [[ -z "${OUT_FILE}" ]] ; then
echo "usage:"
echo " montag-docker.sh -i <IN_FILE> -o <OUT_FILE> [-s <PROFANITY_FILE> -e <ENCODING>]"
exit 1
elif [[ ! -f "${IN_FILE}" ]]; then
echo "usage:"
echo " montag-docker.sh -i <IN_FILE> -o <OUT_FILE> [-s <PROFANITY_FILE> -e <ENCODING>]"
echo ""
echo "${IN_FILE} does not exist!"
exit 1
fi
TEMP_DIR=$(mktemp -d -t montag.XXXXXXXXXX)
function finish {
rm -rf "${TEMP_DIR}"
}
trap finish EXIT
IN_BASENAME="$(basename "${IN_FILE}")"
OUT_BASENAME="$(basename "${OUT_FILE}")"
cp "${IN_FILE}" "${TEMP_DIR}/"
if [[ -n "${SWEARS_FILE}" ]] && [[ -f "${SWEARS_FILE}" ]] ; then
cp "${SWEARS_FILE}" "${TEMP_DIR}/swears.txt"
SWEARS_MAP="-v "${TEMP_DIR}/swears.txt:/usr/local/bin/swears.txt:ro""
else
SWEARS_MAP=""
fi
"${ENGINE}" run --rm -t \
-u $([[ "${ENGINE}" == "podman" ]] && echo 0 || id -u):$([[ "${ENGINE}" == "podman" ]] && echo 0 || id -g) \
-v "${TEMP_DIR}:/data:rw" ${SWEARS_MAP} \
"${IMAGE}" -i "/data/${IN_BASENAME}" -o "/data/${OUT_BASENAME}" -e "${ENCODING}"
cp "${TEMP_DIR}/${OUT_BASENAME}" "${OUT_FILE}"
echo "${OUT_FILE}"