-
Notifications
You must be signed in to change notification settings - Fork 2
/
uml2png
executable file
·65 lines (55 loc) · 1.68 KB
/
uml2png
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
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# (c) 2021 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/uml2png
#
PUML="https://example.com/plantuml" #base URL for your plantuml instance
POSTURL="${PUML}/form"
#TLS="--insecure" # this can be commented out if you trust the certs
############################
PROG="${0##*/}"
UMLFILE="$1"
UMLNAME="${UMLFILE%.*}" # strip off the extension....
if [ -z "${UMLFILE}" ]
then
echo "What UML file to convert?"
exit 1
elif [ ! -r "${UMLFILE}" ]
then
echo "Can't read UML data from file: ${UMLFILE}"
exit 1
fi
urldata=$(perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' ${UMLFILE})
URL=$(curl \
--request POST \
--referer ${PUML} \
${TLS} \
--include \
--data "text=${urldata}" \
--data "submit=submit" \
$POSTURL 2>&1 | grep "Location:" | awk '{print $2}')
URL=${URL//[^[:print:]]/}
if [ -z "${PROG##*png*}" ]
then
PNG=${URL//\/uml\//\/png\/}
curl --location --silent --output ${UMLNAME}.png ${PNG}
elif [ -z "${PROG##*svg*}" ]
then
SVG=${URL//\/uml\//\/svg\/}
curl --location --silent --output ${UMLNAME}.svg ${SVG}
elif [ -z "${PROG##*eps*}" ]
then
EPS=${URL//\/uml\//\/eps\/}
curl --location --silent --output ${UMLNAME}.eps ${EPS}
elif [ -z "${PROG##*epstext*}" ]
then
EPS=${URL//\/uml\//\/epstext\/}
curl --location --silent --output ${UMLNAME}.epst ${EPS}
elif [ -z "${PROG##*txt*}" ]
then
TXT=${URL//\/uml\//\/txt\/}
curl --location --silent ${TXT}
else
echo "unknown/unsupported extension ${PROG//uml2/}"
fi