-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikitex-audit.in.sh
182 lines (138 loc) · 6.52 KB
/
wikitex-audit.in.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
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
#!/usr/bin/env bash
#
# wikitex-audit.sh: locates infelicities in
# WikiTeX's installation.
#
# WikiTeX: expansible LaTeX module for MediaWiki
# Copyright (C) 2004-6 Peter Danenberg
#
# WikiTeX is licensed under the Artistic License 2.0; to
# view a copy of this license, see COPYING or visit:
#
# http://dev.perl.org/perl6/rfc/346.html
#
declare -r LATEX=%LATEX%
declare -r TEXMF=$(kpsewhich -expand-var '$TEXMFMAIN')/web2c/texmf.cnf
declare -r DVIPNG=%DVIPNG%
declare -r MOGRIFY=%MOGRIFY%
declare -r CONVERT=%CONVERT%
declare -r LILYPOND=%LILYPOND%
declare -r GNUPLOT=%GNUPLOT%
declare -r DOT=%DOT%
declare -r NEATO=%NEATO%,
declare -r FDP=%FDP%,
declare -r TWOPI=%TWOPI%,
declare -r CIRCO=%CIRCO%,
declare -r SGF2DG=%SGF2DG%
declare -r TEX=%TEX%
declare -r METAPOST=%METAPOST%
declare -r PARTITION=%PARTITION%
declare -r DECRUFT=%DECRUFT%
declare -r DATABASE=%DATABASE%
declare -r DBUSER=%DBUSER%
declare -r DBPASS=%DBPASS%
declare -r MAILTO=%MAILTO%
declare -r APACHE=%APACHE%
declare -r WIKITEX=%WIKITEX%
declare -r HOST=%HOST%
declare -ri SUCCESS=0
declare -ri FAIL=1
declare -ri ABORT=2
declare -ri WARN=0
declare -ri FATAL=1
declare -ra OUTCOMES=('success' 'FAILURE')
declare -ra TESTS=('root' 'user' 'nologin' 'usrquota' 'quotaed' 'blocks' 'files' 'crontab' 'decruft' 'latex' 'shell_escape' 'openout_any' 'openin_any' 'latex\ execute' 'latex\ read' 'latex\ write' 'dvipng' 'mogrify' 'convert' 'lilypond' 'gnuplot' 'gnuplot\ execute' 'dot' 'neato' 'fdp' 'twopi' 'circo' 'sgf2dg' 'tex' 'metapost')
declare -ra DICTA=(
"You\ must\ be\ root\ to\ continue."
"User\ ${WIKITEX}\ existeth\ nought."
"User\ ${WIKITEX}\ does\ not\ have\ /sbin/nologin\ for\ a\ shell."
"usrquota\ does\ not\ appear\ in\ /etc/fstab\ for\ ${PARTITION}."
"User\ ${WIKITEX}\ has\ not\ been\ quotaed."
"Blocks\ have\ not\ been\ quotaed\ on\ ${PARTITION}\ for\ ${WIKITEX}."
"Files\ have\ not\ been\ quotaed\ on\ ${PARTITION}\ for\ ${WIKITEX}."
"There\ is\ no\ crontab\ for\ Apache\ user\ ${APACHE}."
"The\ crontab\ for\ Apache\ user\ ${APACHE}\ does\ not\ invoke\ ${DECRUFT}."
"${APACHE}\ cannot\ execute\ latex\ as\ ${WIKITEX}."
"shell_escape\ must\ be\ set\ to\ f\ in\ texmf.cnf"
"openout_any\ must\ be\ set\ to\ p\ in\ texmf.cnf"
"openin_any\ must\ be\ set\ to\ p\ in\ texmf.cnf"
"LaTeX\ appears\ to\ be\ able\ to\ execute\ scripts."
"LaTeX\ appears\ to\ be\ able\ to\ read\ files\ in\ parent\ directory."
"LaTeX\ appears\ to\ be\ able\ to\ write\ files\ in\ parent\ directory."
"${APACHE}\ cannot\ execute\ dvipng\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ mogrify\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ convert\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ lilypond\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ gnuplot\ as\ ${WIKITEX}."
"Gnuplot\ appears\ to\ be\ able\ to\ execute\ commands."
"${APACHE}\ cannot\ execute\ dot\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ neato\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ fdp\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ twopi\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ circo\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ sgf2dg\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ tex\ as\ ${WIKITEX}."
"${APACHE}\ cannot\ execute\ metapost\ as\ ${WIKITEX}."
)
declare -ar TERMS=(
'Finished\ successfully.'
'Finished\ with\ failures.'
'Aborted\ on\ fatal\ error.'
)
declare -i status=${SUCCESS}
declare -i test=0
echo -e "outcome\ttest\n-------\t----"
function au_run() {
# echo ${@}
"${@}" &> /dev/null || {
echo -e "${OUTCOMES[FAIL]}\t${TESTS[test]}: ${DICTA[test]}"
return ${FAIL}
}
echo -e "${OUTCOMES[SUCCESS]}\t${TESTS[test]}"
return ${SUCCESS}
}
abort() {
echo "${TERMS[${ABORT}]}"
exit ${ABORT}
}
au_run [ $(id -u) == 0 ] || abort && (( test++ ))
au_run id -u "${WIKITEX}" || abort && (( test++ ))
au_run awk -F : -- "/${WIKITEX}/ { if (\$7 !~ /nologin/) exit ${FAIL}; }" /etc/passwd || abort && (( test++ ))
au_run awk -- "\$1 ~ \"${PARTITION}\" { if (\$4 !~ /usrquota/) exit ${FAIL} }" /etc/fstab || abort && (( test++ ))
au_run quota -qu "${WIKITEX}" || abort && (( test++ ))
quota -vu "${WIKITEX}" | au_run awk -- "\$1 ~ \"${PARTITION}\" { if (\$4 == 0) exit ${FAIL} }" || abort && (( test++ ))
quota -vu "${WIKITEX}" | au_run awk -- "\$1 ~ \"${PARTITION}\" { if (\$7 == 0) exit ${FAIL} }" || abort && (( test++ ))
#au_run crontab -lu "${APACHE}" || abort && \
(( test++ ))
#crontab -lu "${APACHE}" | au_run grep "${DECRUFT}" || status=${FAIL} && \
(( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" latex -v || abort && (( test++ ))
#au_run grep '^shell_escape.*f$' "${TEXMF}" || abort && \
(( test++ ))
#au_run grep '^openout_any.*p$' "${TEXMF}" || abort && \
(( test++ ))
#au_run grep '^openin_any.*p$' "${TEXMF}" || abort && \
(( test++ ))
latex --interaction=nonstopmode 'wikitex-audit-shell.tex' | au_run grep -qv 'write18.*enabled' || abort && (( test++ ))
latex --interaction=nonstopmode 'wikitex-audit-read.tex' &> /dev/null
au_run [ ${?} -ne 0 ] || abort && (( test++ ))
latex --interaction=nonstopmode 'wikitex-audit-write.tex' &> /dev/null
au_run [ ${?} -ne 0 ] || abort && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" dvipng -version || abort && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" mogrify -version || abort && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" convert -version || abort && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" lilypond -v || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" gnuplot -V || status=${FAIL} && (( test++ )) && {
# echo '!cat' | sudo -u "${APACHE}" sudo -u "${WIKITEX}" gnuplot 2>&1 | au_run grep -q 'Permission denied' || abort && \
(( test++ ))
}
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" dot -V || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" neato -V || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" fdp -V || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" twopi -V || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" circo -V || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" sgf2dg -v || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" tex -v || status=${FAIL} && (( test++ ))
au_run sudo -u "${APACHE}" sudo -u "${WIKITEX}" mpost -v || status=${FAIL} && (( test++ ))
echo "${TERMS[${status}]}"
exit ${status}