-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·510 lines (452 loc) · 13.5 KB
/
install.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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
#!/bin/bash
if test $(id -u) != "0"; then
echo "Please supply root's password to install this package. "
su -c "$0"
ret=$?
exit $ret
fi
pidfile=/var/run/yum.pid
export DEBIAN_FRONTEND=noninteractive
checkyum()
{
if test -f "$pidfile"; then
if test "$1" = "check"; then
echo "YUM is being used: enter 'q' to exit the kernel-devel list."
else
echo "YUM is being used: enter 'q' to exit the $1 installation."
fi
while test -f "$pidfile"; do
echo -n .
read -t 1 c
if test "${c}" = "q"; then
exit 1
fi
done
echo
fi
}
installpkgcentos()
{
if ! type $1 >/dev/null 2>&1; then
if ! rpm -qe --quiet $1; then
echo "Installing required package: $1"
checkyum $1
yum -y --quiet install ${1} >/dev/null 2>&1
if test $? != 0; then
echo "Failed to install package $1."
return 1
fi
fi
fi
return 0
}
checkapt()
{
lockfile=/var/lib/dpkg/lock
if test -f "$lockfile"; then
if lsof "$lockfile" >/dev/null 2>&1 ;then
if test "$1" = "check"; then
echo "APT is being used: enter 'q' to exit the linux-headers list."
else
echo "APT is being used: enter 'q' to exit the $1 installation."
fi
fi
while lsof "$lockfile" >/dev/null 2>&1; do
echo -n .
read -t 1 c
if test "${c}" = "q"; then
return 1
fi
done
fi
return 0
}
installpkgdebian()
{
if ! type $1 >/dev/null 2>&1; then
echo "Installing required package: $1"
checkapt $1
apt-get -y -qq install ${1} #>/dev/null 2>&1
if test $? != 0; then
echo "Failed to install package $1."
return 1
fi
fi
return 0
}
checkpkg()
{
if ! type $1 > /dev/null 2>&1; then
return 1
else
return 0
fi
}
downloadinstall()
{
name=$(basename "$1")
baseurl=$(dirname "$1")
rm -f /var/tmp/${name}
if type curl > /dev/null 2>&1; then
if curl --connect-timeout 10 -s "${baseurl}/" 2>&1 | grep -s -q "${name}"; then
echo "Downloading package ${name} from ${baseurl}."
curl --connect-timeout 10 -s -o /var/tmp/${name} "${baseurl}/${name}"
if test $? = 0; then
echo "Installing package ${name} from downloader."
checkyum kernel-devel
yum -y --quiet localinstall /var/tmp/${name} >/dev/null 2>&1
rm -f /var/tmp/${name}
return 0
fi
fi
fi
return 1
}
installkerneldcentos()
{
cdroms=$(ls /dev/sr* 2>/dev/null)
if test "${cdroms}" != ""; then
for i in ${cdroms}; do
mkdir -p /var/tmp/cdrom
if test -e $i; then
mount $i /var/tmp/cdrom > /dev/null 2>&1
if test $? != "0"; then
rmdir /var/tmp/cdrom
continue
fi
if test -f /var/tmp/cdrom/.discinfo; then
break
else
umount /var/tmp/cdrom
rmdir /var/tmp/cdrom
fi
fi
done
fi
#if ! test -d /var/tmp/cdrom; then
# echo "Installation media was not found."
#fi
kernels=$(rpm -qa kernel)
if test "$kernels" = ""; then
return 0
fi
kernelds=$(rpm -qa kernel-devel)
checkyum check
reps=$(yum --quiet --showduplicates list kernel-devel 2>/dev/null | grep ^Avail -A 100 | grep kernel-devel)
for kernel in ${kernels}; do
kerneld=${kernel/kernel/kernel-devel}
if echo "${kernelds}" | grep -s -q ^${kerneld}$; then
continue
fi
pkgversion=${kernel/kernel-}
pkgversion=$(echo ${pkgversion} | rev | cut -d. -f2- | rev)
inreps=0
if test "$pkgversion" != ""; then
if echo "${reps}" | grep -s -q "${pkgversion}"; then
inreps=1
fi
fi
if test -f /var/tmp/cdrom/Packages/${kerneld}.rpm; then
checkyum kernel-devel
yum -y --quiet localinstall /var/tmp/cdrom/Packages/${kerneld}.rpm >/dev/null 2>&1
if test $? != 0; then
echo "Failed to install package ${kerneld}.rpm."
fi
elif test "$inreps" = "1"; then
echo "Installing package ${kerneld}.rpm from yum repository."
checkyum kernel-devel
yum -y --quiet install ${kerneld} >/dev/null 2>&1
if test $? != 0; then
echo "Failed to install package ${kerneld}.rpm."
fi
elif test -e /etc/centos-release; then
if echo ${pkgversion} | grep -s -q 2\\.6\\.32; then
maj=6
rev=$(echo ${pkgversion} | cut -d- -f2 | cut -d. -f1)
dir=Packages
if echo ${kerneld} | grep -s -q x86_64; then
arch=x86_64
else
arch=i386
fi
case "${rev}" in
71)
dir=RPMS
min=0
;;
131)
min=1
;;
220)
min=2
;;
279)
min=3
;;
358)
min=4
;;
431)
min=5
;;
*)
min=""
;;
esac
if test "${min}" = ""; then
continue
fi
if test "${min}" -gt 3; then
downloadinstall http://mirrors.kernel.org/centos/${maj}.${min}/os/${arch}/${dir}/${kerneld}.rpm
if test $? = 0; then
continue
fi
downloadinstall http://mirrors.kernel.org/centos/${maj}.${min}/updates/${arch}/${dir}/${kerneld}.rpm
if test $? = 0; then
continue
fi
fi
downloadinstall http://mirror.symnds.com/distributions/CentOS-vault/${maj}.${min}/os/${arch}/${dir}/${kerneld}.rpm
if test $? = 0; then
continue
fi
downloadinstall http://mirror.symnds.com/distributions/CentOS-vault/${maj}.${min}/updates/${arch}/${dir}/${kerneld}.rpm
if test $? = 0; then
continue
fi
downloadinstall http://vault.centos.org/${maj}.${min}/os/${arch}/${dir}/${kerneld}.rpm
if test $? = 0; then
continue
fi
downloadinstall http://vault.centos.org/${maj}.${min}/updates/${arch}/${dir}/${kerneld}.rpm
if test $? = 0; then
continue
else
echo "Failed to download or install package ${kerneld}.rpm."
fi
fi
continue
fi
done
if test -d /var/tmp/cdrom; then
umount /var/tmp/cdrom
rmdir /var/tmp/cdrom
fi
}
installkernelddebian()
{
for i in /boot/vmlinuz-*; do
#dpkg -S $i 2>/dev/null | cut -d: -f1
pkg=`dpkg -S $i 2>/dev/null | cut -d: -f1`
if test "$pkg" != ""; then
#pkg=`echo $pkg`
#pkg=`echo $pkg`
pkgd=${pkg/image/headers}
checkapt $pkgd
echo "Installing package ${pkgd} from APT repository."
apt-get -y -qq install $pkgd
fi
done
}
#MODNAME=`grep TARGETNAME product/*/linux/Makefile | sed s'# ##'g | cut -d\= -f2 | sed s'#\r##'`
echo "Starting install R750 Linux Open Source package ............"
MODNAME=r750
if test "$NOCOMPINSTALL" = ""; then
if test -e /etc/redhat-release; then
installpkgcentos gcc
checkpkg gcc
if test $? != 0; then
echo "Package gcc not installed and failed to install. exiting ..."
exit 1
fi
installpkgcentos make
checkpkg make
if test $? != 0; then
echo "Package make not installed and failed to install. exiting ..."
exit 1
fi
installpkgcentos perl
checkpkg perl
if test $? != 0; then
echo "Package perl not installed and failed to install. exiting ..."
exit 1
fi
installkerneldcentos
elif test -e /etc/debian_version; then
installpkgdebian gcc
checkpkg gcc
if test $? != 0; then
echo "Package gcc not installed and failed to install. exiting ..."
exit 1
fi
installpkgdebian make
checkpkg make
if test $? != 0; then
echo "Package make not installed and failed to install. exiting ..."
exit 1
fi
installpkgdebian perl
checkpkg perl
if test $? != 0; then
echo "Package perl not installed and failed to install. exiting ..."
exit 1
fi
installkernelddebian
else
echo "Current running system is not a CentOS 6/Debian system."
echo -n "Do you want to continue the installation? (y/n): "
read ans
if test "$ans" != "y"; then
exit 1
fi
checkpkg gcc
if test $? != 0; then
echo "Package gcc not installed. exiting ..."
exit 1
fi
checkpkg make
if test $? != 0; then
echo "Package make not installed. exiting ..."
exit 1
fi
checkpkg perl
if test $? != 0; then
echo "Package perl not installed. exiting ..."
exit 1
fi
fi
fi
if [ "$MODNAME" == "" ]; then
echo "Could not determine driver name"
fi
rm -rf product/*/linux/*.ko
rm -rf product/*/linux/.build
rm -rf /usr/share/hptdrv/$MODNAME
mkdir -p /usr/share/hptdrv/
cp -R `pwd` /usr/share/hptdrv/$MODNAME
rm -f /usr/share/hptdrv/$MODNAME/install.sh
rm -rf /usr/share/hptdrv/$MODNAME/dist
chown -R 0:0 /usr/share/hptdrv/$MODNAME
#touch /etc/sysconfig/hptdrv || exit 1
#echo MODLIST=\"$MODNAME\" > /etc/sysconfig/hptdrv
if test -d /etc/rc.d/init.d; then
rm -f /etc/rc.d/init.d/hptdrv-monitor
install -m 755 -o root -g root dist/hptdrv-monitor /etc/rc.d/init.d/
if test -e /etc/debian_version; then
rm -f /etc/rc.d/init.d/hptmod
install -m 755 -o root -g root dist/hptmod /etc/rc.d/init.d/
str_sed=`sed -n '/Required-Start:.*hptmod/p' /etc/rc.d/init.d/udev`
if test "$str_sed" = "" ;then
sed -i '/Required-Start:/s/.*/&hptmod/' /etc/rc.d/init.d/udev
fi
fi
elif test -d /etc/init.d; then
rm -f /etc/init.d/hptdrv-monitor
install -m 755 -o root -g root dist/hptdrv-monitor /etc/init.d/
if test -e /etc/debian_version; then
rm -f /etc/init.d/hptmod
install -m 755 -o root -g root dist/hptmod /etc/init.d/
str_sed=`sed -n '/Required-Start:.*hptmod/p' /etc/init.d/udev`
if test "$str_sed" = "" ;then
sed -i '/Required-Start:/s/.*/&hptmod/' /etc/init.d/udev
fi
fi
fi
install -m 755 -o root -g root dist/hptdrv-rebuild /usr/sbin/
if test -d /var/lock/subsys; then
touch /var/lock/subsys/hptdrv-monitor
fi
if type update-rc.d >/dev/null 2>&1; then
update-rc.d -f hptdrv-monitor remove >/dev/null 2>&1
update-rc.d hptdrv-monitor defaults >/dev/null 2>&1
if test -e /etc/debian_version; then
update-rc.d -f hptmod remove >/dev/null 2>&1
if test -s /etc/init.d/.depend.boot; then
update-rc.d hptmod defaults >/dev/null 2>&1
update-rc.d hptmod enable S >/dev/null 2>&1
else
# start it before udev
update-rc.d hptmod start 03 S . >/dev/null 2>&1
fi
fi
else
if test -d /etc/rc.d/rc0.d; then
ln -sf ../init.d/hptdrv-monitor /etc/rc.d/rc0.d/K10hptdrv-monitor
fi
if test -d /etc/rc.d/rc6.d; then
ln -sf ../init.d/hptdrv-monitor /etc/rc.d/rc6.d/K10hptdrv-monitor
fi
if test -d /etc/rc.d/rc1.d; then
ln -sf ../init.d/hptdrv-monitor /etc/rc.d/rc1.d/S10hptdrv-monitor
fi
if test -d /etc/rc.d/rc2.d; then
ln -sf ../init.d/hptdrv-monitor /etc/rc.d/rc2.d/S10hptdrv-monitor
fi
if test -d /etc/rc.d/rc3.d; then
ln -sf ../init.d/hptdrv-monitor /etc/rc.d/rc3.d/S10hptdrv-monitor
fi
if test -d /etc/rc.d/rc4.d; then
ln -sf ../init.d/hptdrv-monitor /etc/rc.d/rc4.d/S10hptdrv-monitor
fi
if test -d /etc/rc.d/rc5.d; then
ln -sf ../init.d/hptdrv-monitor /etc/rc.d/rc5.d/S10hptdrv-monitor
fi
fi
OS=
[ -f /etc/lsb-release ] && OS=`sed -n '/DISTRIB_ID/p' /etc/lsb-release | cut -d'=' -f2 | tr [[:upper:]] [[:lower:]]`
if [ "${OS}" = "ubuntu" ] ;then
type upstart-udev-bridge > /dev/null 2>&1
if [ "$?" = 0 ] ;then
install -m 755 -o root -g root dist/hptdrv.conf /etc/init/
install -m 755 -o root -g root dist/udev.override /etc/init/
fi
fi
if type systemctl >/dev/null 2>&1; then
rm -f /lib/systemd/system/systemd-hptdrv.service
rm -f /usr/lib/systemd/system/systemd-hptdrv.service
if test -d /lib/systemd/system; then
install -m 644 -o root -g root dist/systemd-hptdrv.service /lib/systemd/system/
install -m 644 -o root -g root dist/hptdrv-monitor.service /lib/systemd/system/
elif test -d /usr/lib/systemd/system; then
# suse 13.1 bug
if test -f "/usr/lib/systemd/system/[email protected]"; then
mkdir -p "/usr/lib/systemd/system/[email protected]/"
install -m 644 -o root -g root dist/50-before-network-online.conf "/usr/lib/systemd/system/[email protected]/"
fi
install -m 644 -o root -g root dist/hptdrv-monitor.service /usr/lib/systemd/system/
install -m 644 -o root -g root dist/systemd-hptdrv.service /usr/lib/systemd/system/
fi
systemctl daemon-reload >/dev/null 2>&1
systemctl enable hptdrv-monitor.service >/dev/null 2>&1
systemctl enable systemd-hptdrv >/dev/null 2>&1
systemctl start hptdrv-monitor.service >/dev/null 2>&1
rm -f /etc/init.d/hptmod
install -m 755 -o root -g root dist/hptmod /etc/init.d/
fi
if [ -d /etc/initramfs-tools/scripts/init-top ]; then
install -m 755 -o root -g root dist/hptdrv /etc/initramfs-tools/scripts/init-top/
fi
#if [ -d /etc/initramfs-tools/conf.d ];then
# file_p=/etc/initramfs-tools/conf.d/driver-policy
# conf=""
# if [ -f ${file_p} ] ;then
# conf=`sed -n '/^MODULES=[a-z]*/p' ${file_p}`
# fi
# if [ "${conf}" = "" ] ;then
# echo MODULES=dep >> ${file_p}
# else
# sed -i 's/^MODULES=[a-z]*/MODULES=dep/' ${file_p}
# fi
#fi
#if [ -d /etc/dracut.conf.d ]; then
# echo "omit_drivers+=$MODNAME" > /etc/dracut.conf.d/${MODNAME}.conf
#fi
echo "Checking and building device driver for R750............"
env MODINSTALL=1 /etc/init.d/hptdrv-monitor start
if test "$NOCOMPINSTALL" = ""; then
env modules="${MODNAME}" /etc/init.d/hptdrv-monitor force-stop
if test $? != 0; then
echo "Driver r750 for some kernel built failed, please refer to file /var/log/hptdrv.log"
fi
fi
# vim: expandtab ts=2 sw=2 ai