-
Notifications
You must be signed in to change notification settings - Fork 0
/
vnmik.validators
executable file
·280 lines (253 loc) · 6.69 KB
/
vnmik.validators
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!bash
# $Id$
# this file is part of VnMiK-4.0.0
# check whether the OS is supported
check_OS()
{
if [ "x$OS" != "xWindows_NT" ]; then
stat_fail --exit "require WinNT-liked system"
else
stat_done "you are using WinNT-liked system. that's good enough for VnMiK"
fi
}
# check if directory is writable
check_RWDir()
{
local EXIT_IF_FAIL=''
if [ "x$1" == "x--exit" ]; then
EXIT_IF_FAIL='--exit'
shift
fi
if [ "x$1" != "x" ]; then
if [ ! -d "$1" -o ! -w "$1" ]; then
stat_fail $EXIT_IF_FAIL "un-writable directory: $1"
else
stat_log "writable directory: $1"
fi
else
stat_warn "($FUNCNAME) missing argument"
fi
}
# check if files are writable and readable
#
# $0 [--no-touch] [--exit] [--prefix PREFIX/] file file...
# PREFIX must be ended by a slash...
check_RWFiles()
{
local NOTOUCH=0
local EXIT_IF_FAIL=''
local FilePrefix=''
local retcode=0
# magic scanning for options, 31 May 2008
while [ "x${1:0:2}" == "x--" ]; do
case "$1" in
"--no-touch") NOTOUCH=1;;
"--exit") EXIT_IF_FAIL="--exit";;
"--prefix") shift; FilePrefix="$1";;
*) continue;
esac
shift
done
local testfile=
while [ "x$1" != "x" ]; do
testfile="$FilePrefix$1"
if [ -e "$testfile" ]; then
if [ -f "$testfile" ]; then
if [ ! -w "$testfile" ]; then
stat_fail $EXIT_IF_FAIL "un-writable file: $testfile"
retcode=1
fi
else
stat_fail $EXIT_IF_FAIL "not a file: $testfile"
retcode=1
fi
else
if [ $NOTOUCH -eq 0 ]; then
echo -n '' >> "$testfile" 2>/dev/null 1>/dev/null
fi
if [ ! -f "$testfile" -o ! -w "$testfile" ]; then
stat_fail $EXIT_IF_FAIL "un-writable file: $testfile"
retcode=1
else
stat_log "writable file: $testfile"
fi
fi
shift
done
return $retcode
}
# check whether file is readable and writable
check_RWFile()
{
check_RWFiles $@
}
# check whether file is readable
check_RFiles()
{
local retcode=0
while [ "x$1" != "x" ]; do
if [ ! -f "$1" -o ! -r "$1" ]; then
stat_warn "un-readable: $1"
retcode=1
fi
shift
done
return $retcode
}
# check for diskspace. require $MINSIZE (as MB)
# this new version requires MINSIZE is parsed as $1
check_DiskSpace()
{
local MINSIZE="$1"
[ "x$MINSIZE" != "x" ] || MINSIZE=0
local DISKSPACE=$(df "$PREFIX" | tail -1 | gawk '{print $4;}')
DISKSPACE=$((DISKSPACE/1024))
if [ $DISKSPACE -gt $MINSIZE ]; then
stat_done "disk space ok (require $MINSIZE MB, have $DISKSPACE MB)"
else
stat_fail --exit "disk space NOT enough (require $MINSIZE MB, have $DISKSPACE MB)"
fi
}
# check for `reg.exe' program
# #1: --exit ( exit if failed )
check_RegeditProgram()
{
stat_log "checking for registry program"
type -P reg.exe >/dev/null 2>&1
if [ $? -ge 1 ]; then
stat_fail $1 "registry tool not found"
else
stat_done "registry tool found"
stat_log "registry found at `type -P reg.exe`"
fi
}
check_RWRegistryDatabase() # check if $1 is writable. $1 is any REG. key
{
stat_log "checking read/write permission to registry database"
local MKEY
if [ "x$1" == "x" ]; then
MKEY="HKCU"
else
MKEY="$1"
fi
regtool -q set "/$MKEY/Software/VnMiK" "$VNMIKID" > /dev/null 2>&1
if [ $? -ge 1 ]; then
stat_warn "unwritable: /$MKEY/Software/VnMiK"
else
stat_log "writable: /$MKEY/Software/VnMiK"
fi
}
# create basic directories and files for vnmik
check_RWVnMik()
{
stat_log "checking read/write permission of $PREFIX"
local FILELIST="VERSION lock tmp tmpi log.all"
local DIRLIST="\
tex.editor \
tex.config \
tex.base \
tex.user \
tex.var \
tex.apps \
tex.doc \
bin \
vnmik.log \
vnmik.package \
"
for D in $DIRLIST; do
mkdir -p $PREFIX/$D > /dev/null 2>&1
check_RWDir --exit $PREFIX/$D
done
check_RWFiles --exit --prefix "$PREFIX/vnmik.log/" $FILELIST
}
# locate PDF acrobat reader
check_PDFReader()
{
if [ "x$PDFREADER" != "x" ] ; then
if [ -f "$PDFREADER" -a -x "$PDFREADER" ]; then
stat_done "pdfreader: $PDFREADER"
return 0
else
stat_done "unexcutable: $PDFREADER"
return 1
fi
fi
# Though FoxitReader is faster and getting more popular today
# it doesnot support DDE commands. We still use Acrobat Reader
# as it is the only way we can work with texniccenter...
# If you like Foxit just replace `AcroExch' by `FoxitReader'
local PDF_READER_REG_PATH=/HKCR/AcroExch.Document/shell/open/command/
stat_warn "force to use Sumatra PDF Viewer"
export PDFREADER=$PREFIX/tex.bin/spdf.exe
}
check_UserHome()
{
[ "x$USERHOME" != "x" ] && return 0 \
|| stat_warn "cannot locate User's Home"
}
check_PowerPrivilege()
{
stat_log "checking power priviledge"
[ $ISPOWERED -eq 1 ] && return 1
regtool -q set "/HKLM/Software/VnMiK" "$VNMIKID" > /dev/null 2>&1
[ $? -eq 0 ] && export ISPOWERED=1
stat_log "is powerered = $ISPOWERED"
return $ISPOWERED
}
check_PreviousInstance() # check for previous instance of setup program
{
stat_log "checking previous instance of setup program"
if [ -f $PREFIX/vnmik.log/lock ]; then
stat_warn "setup program is running OR being locked"
stat_fail --no-clean --exit "please remove $PREFIX/vnmik.log/lock"
else
stat_done "good. there isnot any previous instance"
fi
}
check_PATHinRegistry() # check for /HKCU/Environment/PATH
{
stat_log "checking PATH in registry database"
stat_log "this test is needed to change search-directories for programs"
stat_log "TODO: how to refresh the system after something was added to PATH?"
regtool -q check '/HKCU/Environment/' > /dev/null 2>&1
if [ $? -ge 1 ]; then
# there is no /HKCU/Environment/
stat_log "there not PATH in /HKCU/. try to add default value"
regtool -q add '/HKCU/Environment' > /dev/null 2>&1
regtool -q set '/HKCU/Environment/PATH' '%PATH%' > /dev/null 2>&1
fi
# test again...
stat_log "test for PATH in /HKCU/, again"
regtool -q get '/HKCU/Environment/PATH' > /dev/null 2>&1
if [ $? -ge 1 ]; then
# there is no /HKCU/Environment/PATH
stat_log "PATH not found in /HKCU/. try to add once again"
regtool -q set '/HKCU/Environment/PATH' '%PATH%' > /dev/null 2>&1
stat_log "check for PATH in /HKCU/ again"
regtool -q get '/HKCU/Environment/PATH' > /dev/null 2>&1
if [ $? -ge 1 ]; then
stat_fail "un-writable/readable registry key: /HKCU/Environment/PATH"
else
stat_log "writable registry key: /HKCU/Environment/PATH"
fi
else
stat_log "writable registry key: /HKCU/Environment/PATH"
fi
}
check_PreviousVersion() # check for previous version of VnMiK
{
stat_log "checking previous VnMiK version; current: $VERSION ($VNMIKID)"
if [ -f $LOGDIR/VERSION ]; then
query 'y' "overwrite `cygpath -w $PREFIX`"
if [ $? -ge 1 ]; then
stat_fail --exit "query failed"
else
stat_done "query passed"
fi
# elif [ -d $PREFIX ]; then
# stat_fail --exit "please delete $PREFIX"
else
stat_done "previous VnMiK: none"
fi
}
stat_log "library loaded: vnmik.validators"