forked from tpo/betriebssysteme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.sh
executable file
·124 lines (102 loc) · 3.89 KB
/
clean.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
#
# Docu:
# - https://en.wikipedia.org/wiki/XPath
# - http://xmlstar.sourceforge.net/doc/xmlstarlet.txt
help() {
echo 'usage: clean.sh [--syssoft] Script.odp'
echo ' clean.sh --help'
echo
echo " clean up Mandl's original lecture presentation:"
echo " * remove duplicate footer elements"
echo " * remove page transition animations"
echo " * remove references to 'Wirtschaftsinformatik'"
echo
echo ' use option --syssoft to clean up Systemsoftware'
echo ' presentation.'
echo
exit 1
}
[ "$1" == "--help" ] && help
set -e # exit on error
if [ "$1" = "--debug" ]; then
DEBUG=1
shift
else
DO_NOT_INSERT_SPACE=-P
fi
[ "$1" == "--syssoft" ] && shift && SYSSOFT=1
doc="$1"
[ -z "$doc" ] && help
[ ! -e "$doc" ] && echo "ERROR: didn't find a document named '$doc'. Exiting" && exit 1
origdir=`pwd`
tmpdir=`mktemp -d /tmp/clean.XXXXXX`
cp "$doc" "$tmpdir/"
cd "$tmpdir"
mv "$doc" "$doc.zip"
unzip "$doc.zip" >/dev/null
rm "$doc.zip"
# preserve copy with spaces for debugging
if [ "$DEBUG" ]; then
xmlstarlet ed content.xml > content_orig.xml
xmlstarlet ed meta.xml > meta_orig.xml
fi
if [ "$SYSSOFT" ]; then # treat the document as a Systemsoftware presentation
cat content.xml | \
sed 's/Systemsoftware/MAS: Betriebssysteme/g' \
> content_edited.xml
else # treat the document as Mandl's presentation
# <draw:frame draw:name="Fußzeilenplatzhalter 4" presentation:style-name="pr1" draw:text-style-name="P2" draw:layer="layout" svg:width="8.042cm" svg:height="1.269cm" svg:x="8.678cm" svg:y="17.78cm" presentation:class="footer" presentation:user-transformed="true"><draw:text-box><text:p text:style-name="P1"><text:span text:style-name="T1">Betriebssysteme</text:span></text:p><text:p text:style-name="P1"><text:span text:style-name="T2"/></text:p></draw:text-box></draw:frame>
#
# ed - edit
# -d - delete
# -P - preserve white space
#
# / - starting from root select
# * - any element
# // - any descendant (!= child!)
# draw:frame - name of element
# [ - when
# . - this element's
# //* - random descendant
# [ - when that descendant
# text()='Betriebssysteme' - when the text of the element is 'Betriebssysteme'
#
# Remove random page transitions, they are annoying:
# Remove from elements <style:drawing-page-properties...> the attribute "smil:type="random":
# -d "//style:drawing-page-properties/@smil:type"
#
# Remove all transition animation definitions, they are annoying:
# Remove all elements <anim:par ...>
# -d "//anim-par"
#
cat content.xml | \
xmlstarlet ed $DO_NOT_INSERT_SPACE \
-d "/*//draw:frame[.//*[text()='Betriebssysteme']]" | \
xmlstarlet ed $DO_NOT_INSERT_SPACE \
-d "/*//draw:frame[.//*[text()='Seite ']]" | \
xmlstarlet ed $DO_NOT_INSERT_SPACE \
-d "//style:drawing-page-properties/@smil:type" | \
xmlstarlet ed $DO_NOT_INSERT_SPACE \
-d "//anim:par" \
> content_edited.xml
#
# <dc:title>Wirtschaftsinformatik</dc:title>
# -u - update
# -v - value
#
cat meta.xml | \
xmlstarlet ed $DO_NOT_INSERT_SPACE \
-u "/*//dc:title[text()='Wirtschaftsinformatik']" \
-v "MAS: Betriebssysteme" \
> meta_edited.xml
fi # [ "$SYSSOFT" ] ?
mv content_edited.xml content.xml
[ -e meta_edited.xml ] && mv meta_edited.xml meta.xml
zip -r "$origdir/new_$doc" * > /dev/null
# don't remove if you want to debug
if [ "$DEBUG" ]; then
echo "Please remove workdir '$tmpdir' when you're done"
else
rm -R "$tmpdir"
fi