-
Notifications
You must be signed in to change notification settings - Fork 0
/
vnmik.package.installer
executable file
·337 lines (287 loc) · 7.54 KB
/
vnmik.package.installer
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!bash
# $Id$ $
# This file is part of VnMiK-4.0.0 <http://vnmik.sf.net>
##############################################################################
# FILE TYPE EXTENSIONS
##############################################################################
export CAB_SUFFIX='.cab'
export RAR_SUFFIX='.r'
export TBZ_SUFFIX='.tar.bz2'
export ZZ_SUFFIX="$PKG_SUFFIX"
##############################################################################
# 7z archives
##############################################################################
# #1: package; $2: destination
ZZ_EXTRACT()
{
stat_log "extracting package $1 using z program"
local pkg="$1"
local dest="$2"
z xfvj "$pkg" -C "$dest"
}
ZZ_TEST()
{
stat_log "testing package integrety for $1"
z tfvj "$1" >/dev/null 2>&1
local error=$?
stat_log "return status: $error"
return $error
}
ZZ_GREP()
{
# replace all \ by /
grep 'Extracting ' "$1" | gawk '{print $2}' | sed -e 's/\\/\//g'
}
##############################################################################
# format for vnmik-4.0.0
##############################################################################
# cannot use alias. donnot know why
#alias ZZ_TEST=Z_TEST
#alias ZZ_EXTRACT=Z_EXTRACT
#alias ZZ_GREP=Z_GREP
##############################################################################
# for cabinet files
##############################################################################
# cabinet extrating
CAB_EXTRACT()
{
Z_EXTRACT "$1" "$2"
}
CAB_TEST()
{
Z_TEST $* >/dev/null 2>&1
}
CAB_GREP()
{
Z_GREP $*
}
##############################################################################
# for RAR packages
##############################################################################
RAR_EXTRACT()
{
Z_EXTRACT "$1" "$2"
}
RAR_TEST()
{
Z_TEST $* >/dev/null 2>&1
}
RAR_GREP()
{
Z_GREP $*
}
##############################################################################
# for TBZ packages
##############################################################################
TBZ_EXTRACT()
{
Z_EXTRACT "$1" "$2"
}
TBZ_TEST()
{
Z_TEST $* >/dev/null 2>&1
}
TBZ_GREP()
{
Z_GREP $*
}
##############################################################################
# install packages *.FOO
##############################################################################
# #1: type: CAB, RAR, TBZ, TGZ, ZZ
# #2: packages
# date: 2006 Aug 06
# update: 30 May 2008 (added ZZ)
install_package_A()
{
stat_log "installing packages of type $1. running CORE version"
stat_log "package to be installed: $2"
local TYPE=$1
local XSUFFIX=
eval XSUFFIX=\$${TYPE}_SUFFIX # get the suffix for type. Excellent stuff :)
stat_log "suffix for packages of this type: $XSUFFIX"
local DEST="$PREFIX"
stat_log "package will be installed to $DEST"
shift # skip package TYPE
while [ "x$1" != "x" ]; do
local pkgfile="$1"
stat_log "installing package $pkgfile"
export PACKAGE=`basename "$pkgfile" $XSUFFIX`
stat_prefix "> $PACKAGE> "
# check whether package does exist and readable
if [ ! -f "$pkgfile" -o ! -r "$pkgfile" ]; then
stat_warn "unreadable: $1"
# add this package to list of FAILED packages
export PACKAGE_FAIL="$PACKAGE $PACKAGE_FAIL"
shift # ok. skip to next package
continue # skip to next package in WHILE loop
fi
stat_msg ''
# check for md5sum
if [ -f $pkgfile.md5sum -a -r $pkgfile.md5sum ]; then
stat_log "testing package using md5sum"
md5sum -c $pkgfile.md5sum > /dev/null 2>&1
else
stat_log "we donnot find any md5sum file for package. We try to use ${TYPE}_TEST"
${TYPE}_TEST "$1"
fi
if [ $? -ge 1 ]; then # some errors occured
stat_warn "package corrupted"
export PACKAGE_FAIL="$PACKAGE $PACKAGE_FAIL"
else # everything seems OK
# the log directory must be readable
check_RWFile $LOGDIR/log.$PACKAGE
if [ $? -gt 0 ]; then
shift
continue
fi
stat_msh "extracting..."
${TYPE}_EXTRACT "$1" "$DEST" > $LOGDIR/log.$PACKAGE 2>/dev/null
stat_log "package extracted; type: $TYPE; return value $?"
# ${TYPE}_GREP $LOGDIR/tmp > $LOGDIR/log.$PACKAGE
if [ -f $LOGDIR/z.$PACKAGE ];
then
stat_msg "post-install"
source $LOGDIR/z.$PACKAGE
${PACKAGE}_install
else
stat_log "post-install script not found: $LOGDIR/z.$PACKAGE"
fi
#stat_log "WARNING: skip fixing file modes (heavy task)"
# fix_mode_by_log "$LOGDIR/log.$PACKAGE"
export PACKAGE_OK="$PACKAGE $PACKAGE_OK"
fi
shift
done
}
install_package() # install packages *.r
{
local run_texhash=1
if [ "x$1" == "x--skip-texhash" ]; then
run_texhash=0
shift
fi
stat_log "install packages; running FRONT-END version"
if [ "x$1" == "x" ]; then
stat_warn "($FUNCNAME) nothing to do. no package was specified"
return 1
fi
check_RWVnMik # check for readable directory
# global list of failed/ok packages
PACKAGE_FAIL=
PACKAGE_OK=
# R: 7z packages
local R_PACKAGE=
local C_PACKAGE=
local B_PACKAGE=
local Z_PACKAGE=
local PKG_EXT=
while [ "x$1" != "x" ]; do
PKG_EXT="${1:(-4)}"
if [ "x$PKG_EXT" == "x.cab" ]; then
C_PACKAGE="$C_PACKAGE $1"
else
PKG_EXT="${1:(-2)}"
if [ "x$PKG_EXT" == "x.r" ]; then
R_PACKAGE="$R_PACKAGE $1"
elif [ "x$PKG_EXT" == "x.4" ]; then
Z_PACKAGE="$Z_PACKAGE $1"
else
PKG_EXT="${1:(-8)}"
if [ "x$PKG_EXT" == "x.tar.bz2" ]; then
B_PACKAGE="$B_PACKAGE $1"
else
stat_warn "unknown package: $1"
fi
fi
fi
shift
done
# skip series C,R,B (vnmik 4.0.0)
install_package_A ZZ $Z_PACKAGE
stat_prefix ''
# save list of installed packages to log file
if [ -n "$PACKAGE_OK" ]; then
stat_done "package(s) installed:"
for pkg in $PACKAGE_OK; do
stat_done " $pkg"
done
for p in $PACKAGE_OK; do
echo "$p" >> "$LOGDIR/log.packages"
done
fi
[ -n "$PACKAGE_FAIL" ] && stat_warn "package(s) failed: $PACKAGE_FAIL"
stat_log "skip update texdatabase in ($FUNCNAME). please check it out manually"
# [ $run_texhash == 0 ] || ( [ -n "$PACKAGE_OK" ] && texmf_texhash )
unset PACKAGE
unset PACKAGE_OK
unset PACKAGE_FAIL
}
vnmik()
{
local repos="http://download.tuxfamily.org/viettug/vnmik/repos/"
usage()
{
stat_log "($FUNCNAME) missing parameter. printing the usage page..."
msg "example:"
msg "\tvnmik list :\t list all package"
msg "\tvnmik ins :\t install package"
msg "\tvnmik get :\t download a package from VietTUG repository"
}
check_arg()
{
if [ "x$2" == "x" ]; then
stat_log "$FUNCNAME $1 missing parameter"
msg "missing paramater"
usage
return 1
fi
}
stat_msg "welcome to vnmik package manager"
stat_log "vnmik was called with option(s): $*"
case $1 in
"list")
ls $PKGDIR/*$PKG_SUFFIX 2>/dev/null
if [ $? == 0 ]; then
stat_done "package in $PKGDIR:"
for pkg in $PKGDIR/*$PKG_SUFFIX; do
msg "\t" `basename $pkg $PKG_SUFFIX`
done
else
msg "no package found in $PKGDIR/"
fi
;;
"ins")
check_arg $* || return 1
local pkg_name=$2
local pkg="$PKGDIR/$pkg_name$PKG_SUFFIX"
[ -f $pkg ] || (stat_warn "package not found: $2") || return 2
local do_install=0
grep -q $pkg_name $LOGDIR/log.packages
if [ $? -ge 1 ]; then
do_install=1
else
query y "package $pkg_name already installed. Re-install"
if [ $? == 0 ]; then
do_install=1
fi
fi
[ $do_install == 0 ] || install_package $pkg
;;
"get")
check_arg $* || return 1
local pkg="$2$PKG_SUFFIX"
stat_msg "downloading $pkg from $repos"
if [ -f $PKGDIR/$pkg ]; then
query "y" "Package does exist. overwrite"
[ $? == 0 ] || return 1
fi
wget "$repos/$pkg$PKG_SUFFIX" -O $PKGDIR/$pkg
stat_log "wget returns $?"
;;
*)
usage
;;
esac
}
stat_log "library loaded: vnmik.package.installer"