-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallJacap.sh
146 lines (124 loc) · 3.62 KB
/
InstallJacap.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
#! /bin/bash
#! /bin/bash
#
# Program:
# Usage: InstallJacap <source files> <source files> [<source files>]
#
# This program can help you install Jacap rapidly
# and help configure relevant settings.
#
# History:
# 2014/7/31 Li Yunpeng First release
function GetFilename(){
ls > /tmp/InstallJavaCatalog.old
#Decompressing files
#echo "start to tar..."
tar zxvf "$1" > /dev/null
ls> /tmp/InstallJavaCatalog.new
#Get the folder's name of Java
diff /tmp/InstallJavaCatalog.old /tmp/InstallJavaCatalog.new | grep "^>" |tr -d '> '
#Delete temporary files
rm -f /tmp/InstallJavaCatalog.old
rm -f /tmp/InstallJavaCatalog.new
}
function InstallJDK() {
echo "start to install Java..."
JavaFilename=`GetFilename "$1"`
#Found the folder
#Move Java's folder to /usr/lib/jvm/
mv -i $JavaFilename /usr/lib/jvm/
echo "complete the installation of Java..."
echo "configure relevant settings about Java..."
#Add the environment variable
echo "JAVA_HOME=/usr/lib/jvm/$JavaFilename" >> /etc/profile
echo 'PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH' >> /etc/profile
source /etc/profile
} #Install JDK
#check up if log in by root
if [ `whoami` != "root" ];then
echo "Please use this command in root."
exit 1
fi
InstallCatalog=`pwd`
mkdir -p /usr/lib/jvm/
case $# in
"2")
#Exclude other documents.
if [ "`echo $1 | sed 's/^.*\.//g'`" != "gz" -a "`echo $2 | sed 's/^.*\.//g'`" != "gz" ];then
echo "File type error ."
echo "InstallJacap <*.tar.gz> <*.tar.gz> ."
fi
#Check if Java has been installed
if [ `echo $JAVA_HOME > /dev/null` ];then
echo "Java has NOT been installed."
exit 1
fi
;;
"3")
#Exclude other documents.
if [ "`echo $1 | sed 's/^.*\.//g'`" != "bin" -a "`echo $2 | sed 's/^.*\.//g'`" != "gz" -a "`echo $3 | sed 's/^.*\.//g'`" != "gz" ];then
echo "File type error ."
echo "InstallJacap <*.bin> <*.tar.gz> <*.tar.gz> ."
fi
#Check if Java has been installed
if [ ! `echo $JAVA_HOME > /dev/null` ];then
echo "Java has been already installed."
exit 1
else
#Install Java
InstallJDK $1
shift
fi
;;
*)
echo "parameter(s) error."
exit 1
;;
esac
#First determine the catalog ,Because different Java's versions can lead to configuration files which will move to different folder.
cd ${JAVA_HOME}/jre/lib
if [ -e amd64];then
Moveto=amd64
elif [ -e i386 ];then
Moveto=i386
elif [ -e i686 ]
Moveto=i686
else
echo "Not Found current catalog."
fi
Catalog=${JAVA_HOME}/jre/lib/${Moveto}
cd $InstallCatalog
#check gcc,flex,make and bison exist
echo "Check gcc,flex,make and bison exist"
dpkg -l | grep gcc > /dev/null || apt-get install gcc
dpkg -l | grep flex > /dev/null || apt-get install flex
dpkg -l | grep make > /dev/null || apt-get install make
dpkg -l | grep bison > /dev/null || apt-get install bison
LibpcapFilename=$(GetFilename "$1")
#move folder
mv -i $LibpcapFilename /usr/lib/jvm/
cd $JAVA_HOME
./configure
make
make install
cp /usr/local/lib/libpcap.so.1 $Catalog
cd $InstallCatalog
JpcapFilename=$(GetFilename "$2")
#move folder
mv -i $JpcapFilename /usr/lib/jvm/
#add "-fPIC" to "Makefile"
sed -i 's/$(CC) $(COMPILE_OPTION)/$(CC) $(COMPILE_OPTION) -fPIC/g' /usr/lib/jvm/$JpcapFilename/src/c/Makefile
cd /usr/lib/jvm/$JpcapFilename/src/c
make
#move libjpcap.so to $Catalog ps:$Catalog=${JAVA_HOME}/jre/lib/[amd64 or i386 or i686]
cp libjpcap.so $Catalog
#move jpcap.jar to ${JAVA_HOME}/jre/lib/ext
cp /usr/lib/jvm/$JpcapFilename/lib/jpcap.jar ${JAVA_HOME}/jre/lib/ext
echo "--------------------------------------"
echo "Installation has been completed."
echo "Please logoff."
echo "--------------------------------------"