forked from Baael/moxa-nport-driver-3.11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mxinst
451 lines (386 loc) · 10.8 KB
/
mxinst
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
##########################################################################
# Copyright (C) 2003-2012 Moxa Inc.
# All Rights Reserved.
#
#
# Version History :
# date author comment
# 12/04/2003 James first version
# 07/01/2004 James compatible with Real TTY V1
##########################################################################
################################################################################
# define value and default value setting
################################################################################
DirTmp=$0
DirTmp=${DirTmp%/mxinst}
TempDir=$DirTmp
NPPATH="/usr/lib/npreal2"
ProductName="MOXA NPort Server Real TTY Driver V1.18.27"
OS="linux"
Device=""
check=""
EntryPwd=`pwd`
driverPath="/usr/lib/npreal2/driver"
MX_MOD=npreal2
################################################################################
# interrupt_quit1()
# to quit install by interrupt or quit
################################################################################
interrupt_quit1() {
echo "\nInstallation aborted by INTERRUPT !"
exit 1
}
################################################################################
# interrupt_quit2()
# to quit install by interrupt or quit
################################################################################
interrupt_quit2() {
echo "\nInstallation aborted by INTERRUPT !"
clean_tempfile
exit 1
}
interrupt_nothing1() {
exit 1
}
interrupt_nothing2() {
clean_tempfile
exit 1
}
################################################################################
# clean_tempfile()
################################################################################
#clean_tempfile () {
# [ -d $TempDir ] && {
# rm -rf $TempDir > /dev/null 2>&1
# }
# [ -d $NPPATH ] && {
# rm -rf $NPPATH > /dev/null 2>&1
# }
# sync; sync
#}
clean_tempfile () {
sync;
}
################################################################################
# get_OsName()
# get the OS name.
################################################################################
get_OsName() {
if [ -f /etc/redhat-release ]
then
OS="linux"
elif [ -f /etc/SuSE-release ]
then
OS="SuSE"
elif [ -f /etc/gentoo-release ]
then
OS="gentoo"
elif [ -f /etc/debian_version ]
then
OS="debian"
fi
}
################################################################################
# tar_files()
# tar the needed file to disk at $TempDir
# And copy the Driver.o file
################################################################################
tar_files() {
echo -n "Tar files, please wait ..."
[ -d $TempDir ] || mkdir $TempDir > /dev/null 2>&1
cd $TempDir
#[ "$Device" = "harddisk" ] || {
# tar xvf $Device $TempDir/linux.tar.Z > /dev/null 2>&1
# [ $? != 0 ] && {
# [ -d $TempDir ] && rm -rf $TempDir > /dev/null 2>&1
# echo "\nDevice name error ! It cannot tar file !"
# exit 1
# }
#}
#gunzip $TempDir/linux.tar.Z > /dev/null 2>&1
#tar xvf $TempDir/linux.tar > /dev/null 2>&1
tar xvfz $TempDir/linux.tgz > /dev/null 2>&1
#rm -rf linux.tar
echo " OK!"
}
################################################################################
# chk_libssl()
# Check /usr/lib/libssl.so.x
# and link to /tmp/moxa/libsll.so
################################################################################
chk_libssl() {
sslpath=$(find /usr/lib64 -name "libssl.so*" 2> /dev/null)
if [ -z "$sslpath" ]
then
sslpath=$(find /usr/lib -name "libssl.so*" 2> /dev/null)
newsslpath=$(find /usr/lib/i386-linux-gnu -name "libssl.so*" 2> /dev/null)
if [ -z "$sslpath" ]
then
echo
echo 'Can not find libssl.so file in your system,'
echo 'Please install openssl package if you want to use'
echo 'security function.'
exit 0
else
if [ -z "$newsslpath" ]
then
echo "libssl.so.x.x in /usr/lib/"
ls /usr/lib | grep libssl.so* | head -1 |
awk '{system("ln -s /usr/lib/"$0 " libssl.so")}'
else
echo "libssl.so.x.x in /usr/lib/i386-linux-gnu"
ls /usr/lib/i386-linux-gnu | grep libssl.so* | head -1 |
awk '{system("ln -s /usr/lib/i386-linux-gnu/"$0 " libssl.so")}'
fi
fi
else
ls /usr/lib64 | grep libssl.so* | head -1 |
awk '{system("ln -s /usr/lib64/"$0 " libssl.so")}'
fi
}
########################################################
#
# Main procedures
# To read the shell program input argument and process it.
#
########################################################
trap interrupt_quit1 1 3 9 15 # trap signal
trap interrupt_nothing1 2
if [ "$#" -ge 3 ]
then
print_usage
exit 1
fi
echo "
===============================================================================
Copyright (C) 2002-2014 Moxa Inc.
All Rights Reserved.
$ProductName Installation.
System Imformation: Kernel `uname -r`; Machine `uname -m`.
===============================================================================
"
get_OsName
if [ "$OS" = "debian" ]
then
touch /etc/init.d/npreals
fi
trap interrupt_quit2 1 3 9 15 # trap signal
trap interrupt_nothing2 2 # trap signal SIGINT
########################################################
# check configuration file. (npreal2d.cf)
########################################################
if [ -f /usr/lib/npreal2/driver/npreal2d.cf ]
then
echo 'There is an Real TTY Driver installed in your system.'
echo 'Continue to install will overwrite the old driver.'
echo 'Do you want to continue installing? [y/N].'
read check
case $check in
[n])
exit 0
;;
[N])
exit 0
;;
[y])
;;
[Y])
;;
*)
exit 0
;;
esac
fi
########################################################
# rmmove module
########################################################
ps -ef | grep npreal2d | awk '$0 !~ /grep/ {system("kill -15 "$2)}'
ps -ef | grep npreal2d | awk '$0 !~ /grep/ {system("kill -9 "$2)}'
lsmod | grep npreal2 |
awk '$0 != "" {system("rmmod npreal2")}'
########################################################
# install driver
########################################################
echo ''
tar_files
echo "Building driver..."
mkdir -p /lib/modules/`uname -r`/kernel/drivers/char > /dev/null 2>&1
mkdir -p /lib/modules/`uname -r`/misc > /dev/null 2>&1
echo
echo 'If you want to use secure communication with target,'
echo 'you might choose [y] to enable the SSL function.'
echo 'Note: This function support RealCOM with secure mode only.'
echo 'Do you want to enable secure function? [y/N].'
read check
case $check in
[n])
if [ "$1" = "SP1" ]
then
make $1 PATH1=$(pwd)
elif [ "$1" = "polling" ]
then
make clean
make all PATH1=$(pwd) POLLING=-DOFFLINE_POLLING
else
make all PATH1=$(pwd)
fi
;;
[N])
if [ "$1" = "SP1" ]
then
make $1 PATH1=$(pwd)
elif [ "$1" = "polling" ]
then
make clean
make all PATH1=$(pwd) POLLING=-DOFFLINE_POLLING
else
make all PATH1=$(pwd)
fi
;;
[y])
if [ ! -f "$TempDir/libssl.so" ]
then
chk_libssl
fi
if [ "$1" = "SP1" ]
then
make SP1_ssl PATH1=$(pwd)
elif [ "$1" = "m64" ]
then
make ssl64 PATH1=$(pwd)
elif [ "$1" = "mppc64" ]
then
make ppc64 PATH1=$(pwd)
elif [ "$1" = "SP1_m64" ]
then
make SP1_ssl64 PATH1=$(pwd)
elif [ "$1" = "polling" ]
then
make clean
make ssl PATH1=$(pwd) POLLING=-DOFFLINE_POLLING
else
make ssl PATH1=$(pwd)
fi
;;
[Y])
if [ ! -f "TempDir/libssl.so" ]
then
chk_libssl
fi
if [ "$1" = "SP1" ]
then
make SP1_ssl PATH1=$(pwd)
elif [ "$1" = "m64" ]
then
make ssl64 PATH1=$(pwd)
elif [ "$1" = "mppc64" ]
then
make ppc64 PATH1=$(pwd)
elif [ "$1" = "SP1_m64" ]
then
make SP1_ssl64 PATH1=$(pwd)
elif [ "$1" = "polling" ]
then
make clean
make ssl PATH1=$(pwd) POLLING=-DOFFLINE_POLLING
else
make ssl PATH1=$(pwd)
fi
;;
*)
if [ "$1" = "polling" ]
then
make clean
make all PATH1=$(pwd) POLLING=-DOFFLINE_POLLING
else
make $1 PATH1=$(pwd)
fi
;;
esac
echo "Check Driver..."
[ -e $MX_MOD.o -a -e npreal2d.o -a -e npreal2d_redund ] || {
echo "FAILED !!!"
echo " "
echo "Install Not Completed !"
echo " "
clean_tempfile
exit 0
}
########################################################
# Process File
########################################################
#$TempDir/npfile
flag=0
mkdir -p $NPPATH > /dev/null 2>&1
mkdir -p $driverPath > /dev/null 2>&1
[ -f /usr/lib/npreal2/driver/npreal2d.cf ] || {
echo -n "Copying configurations files ... "
cp -f $(pwd)/npreal2d.cf $driverPath
flag=$?
[ $flag = 0 ] || {
echo "FAILED! ($flag)"
exit 0
}
echo "OK!"
}
### driver ###
NowPath=$(pwd)
echo -n "Copying driver files ... "
cp -f $NowPath/killp $driverPath
cp -f $NowPath/npreal2d_redund $driverPath
cp -f $NowPath/npreal2d $driverPath
#cp -f $NowPath/$MX_MOD $driverPath
cp -f $NowPath/Makefile $driverPath
cp -f $NowPath/npreal2d.c $driverPath
cp -f $NowPath/npreal2.h $driverPath
cp -f $NowPath/npreal2d.cf $driverPath/config
cp -f $NowPath/npreal2.c $driverPath
#cp -f $NowPath/linux.mak $driverPath
cp -f $NowPath/mxaddsvr $driverPath
cp -f $NowPath/mxdelsvr $driverPath
cp -f $NowPath/mxcfmat $driverPath
cp -f $NowPath/mxloadsvr $driverPath
cp -f $NowPath/mxmknod $driverPath
cp -f $NowPath/mxrmnod $driverPath
cp -f $NowPath/mxuninst $driverPath
cp -f $NowPath/mxsetsec $driverPath
cp -f $NowPath/README.TXT $NPPATH
cp -f $NowPath/VERSION.TXT $NPPATH
cp -f $NowPath/kernel2.6.txt $NPPATH
echo "OK!"
### module ###
#cp -f $driverPath/npreal2.o /lib/modules/`uname -r`/kernel/drivers/char
#cp -f $driverPath/npreal2.o /lib/modules/`uname -r`/misc
ps -ef | grep npreal2 |
awk '$0 !~ /grep/ {system("kill -15 "$2)}'
ps -ef | grep npreal2 |
awk '$0 !~ /grep/ {system("kill -9 "$2)}'
########################################################
# load module
########################################################
echo "Load driver..."
modprobe $MX_MOD
[ "$?" = "0" ] || {
echo ""
echo "Failed!!! please contact the provider"
echo ""
exit 0
}
echo "OK!"
########################################################
# Delete the line with npreal2 and append
# "modprobe npreal2" in /etc/rc.d/rc.local.
########################################################
cd $NPPATH/driver
./mxloadsvr install
echo ''
echo "
===============================================================================
Installation process is completed.
The all driver files are installed on /usr/lib/npreal2/driver.
Now you can "cd /usr/lib/npreal2/driver" and run "./mxaddsvr" to add tty port.
===============================================================================
"
#[ -d $TempDir ] && {
# rm -rf $TempDir > /dev/null 2>&1
#}