-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·185 lines (150 loc) · 5.3 KB
/
build.sh
File metadata and controls
executable file
·185 lines (150 loc) · 5.3 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
#
timestamp=$(date)
function apply_template()
{
inputfile="$1"
outputfile=${inputfile%.in}
xsltproc \
--stringparam pagesrc "$3" \
--stringparam timestamp "$timestamp" \
--stringparam asset_href_base "$2" \
--stringparam link_href_base "https://libvirt.org/" \
--stringparam edit_href_base "https://gitlab.com/libvirt/libvirt-security-notice/-/blob/master/" \
site.xsl \
"$inputfile" > "$outputfile"
if [ $? -ne 0 ]; then
echo "\nFailed to apply template on $inputfile\n";
return 1
fi
rm "$inputfile"
}
function index_build() {
mv "$1" "$1.tmp"
cat > "$1" << EOF
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div class="document">
$2
<h1>Libvirt Security Notice Index</h1>
$(cat "$1.tmp")
</div>
</body>
</html>
EOF
rm "$1.tmp"
}
function index_entry() {
lsn=$1
link=$2
summary=$3
CVE=$4
echo -n "<li><a href='$link'><span class='noticeid'>LSN-$lsn"
if [ -n "$CVE" ]; then
echo -n " (CVE-$CVE)"
fi
echo "</span>: $summary</a></li>"
}
rm -rf build
mkdir build
cp -R libvirt-assets/* build
cp -R assets/* build
echo '<security-notice-list xmlns="http://security.libvirt.org/xmlns/security-notice-list/1.0">' > build/index.xml
for dir in $(ls -d notices/*/ | sort -n -r); do
year=${dir#notices/}
year=${year%/}
mkdir build/$year
echo $year
echo "<div><h2><a href='$year/index.html'>$year</a></h2><ul>" >> build/index.html.in
echo "<div><h2>$year</h2><ul>" > build/$year/index.html.in
for file in $dir*.xml; do
notice=$(basename -s .xml $file)
# 'xmllint' doesn't allow to specify namespace for your XPath query
CVE=$(sed "$file" -e 's/ xmlns="[^"]\+"//' | xmllint --xpath 'string(//reference/advisory[@type="CVE"]/@id)' -)
summary=$(sed "$file" -e 's/ xmlns="[^"]\+"//' | xmllint --xpath 'string(//summary)' -)
echo -n " LSN-$year-$notice"
echo -n " [schema]"
if ! xmllint --noout --relaxng schema.rng "$file" 2> /dev/null;
then
echo
echo "schema validation failed"
exit 1
fi
echo -n " [index]"
echo -n " <security-notice name='$year/$notice.xml'" >> build/index.xml
if [ -n "$CVE" ]; then
echo -n " CVE=\"CVE-$CVE\"" >> build/index.xml
fi
echo "/>" >> build/index.xml
index_entry "$year-$notice" "$year/$notice.html" "$summary" "$CVE" >> build/index.html.in
index_entry "$year-$notice" "$notice.html" "$summary" "$CVE" >> build/$year/index.html.in
echo -n " [xml]"
cp "$file" "build/$year/$notice.xml" || exit 1
echo -n " [txt]"
xsltproc templates/lsn2text.xsl "$file" > "build/$year/$notice.txt" || exit 1
echo -n " [html]"
xsltproc templates/lsn2html.xsl "$file" > "build/$year/$notice.html.in" || exit 1
apply_template "build/$year/$notice.html.in" "../" "$file" || exit 1
echo
done
echo "</ul></div>" >> build/index.html.in
echo "</ul></div>" >> build/$year/index.html.in
index_build build/$year/index.html.in "<div class='toplink'><a href='../index.html'>Libvirt Security Notice Index</a> > $year</div>"
apply_template build/$year/index.html.in "../"
done
echo '</security-notice-list>' >> build/index.xml
echo 'index [html]'
cat >> build/index.html.in << EOF
<div>
<h2>Other resources:</h2>
<ul>
<li><a href="index.xml">List of security notices in XML</a></li>
<li><a href="schema.html">Description of the libvirt security notice XML schema</a></li>
</ul>
</div>
EOF
index_build build/index.html.in
apply_template build/index.html.in ""
RST2HTML_PROGS=("rst2html5" "rst2html5.py" "rst2html5-3")
unset RST2HTML_BIN
for i in ${RST2HTML_PROGS[@]}; do
# There are two versions of rst2html5 in the wild: one is the version
# coming from the docutils package, and the other is the one coming
# from the rst2html5 package. These versions are subtly different,
# and the wiki can only be successfully generated using the docutils
# version.
#
# The only reliable way to tell the two binaries apart seems to be
# looking look at their version information: the docutils version
# will report
#
# rst2html5 (Docutils ..., Python ..., on ...)
#
# whereas the rst2html5 version will report
#
# rst2html5 ... (Docutils ..., Python ..., on ...)
#
# with the additional bit of information being the version number for
# the rst2html5 package itself.
#
# Use this knowledge to detect the version that we know doesn't work
# for building the wiki and ignore it
ver=$($i --version 2>/dev/null | awk '{print $2}')
if test "$ver" = "(Docutils"; then
RST2HTML_BIN=$i
break;
fi
done
if test -z ${RST2HTML_BIN+x}; then
echo "rst2html5 not found, please install the docutils package" >&2
exit 1
fi
echo "schema doc [html]"
${RST2HTML_BIN} --stylesheet= --strict \
docs/schema.rst > build/schema.html.in || exit 1
apply_template build/schema.html.in "" docs/schema.rst
echo "404 doc [html]"
${RST2HTML_BIN} --stylesheet= --strict \
404.rst > build/404.html.in || exit 1
apply_template build/404.html.in "/" 404.rst