forked from seladb/PcapPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure-mac_os_x.sh
More file actions
executable file
·144 lines (116 loc) · 4.43 KB
/
configure-mac_os_x.sh
File metadata and controls
executable file
·144 lines (116 loc) · 4.43 KB
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
#!/bin/bash
echo ""
echo "*******************************************"
echo "PcapPlusPlus Mac OS X configuration script "
echo "*******************************************"
echo ""
# set Script Name variable
SCRIPT=`basename ${BASH_SOURCE[0]}`
# help function
function HELP {
echo -e \\n"Help documentation for ${SCRIPT}."\\n
echo -e "Basic usage: $SCRIPT [-h] [--use-immediate-mode] [--install-dir] [--libpcap-include-dir] [--libpcap-lib-dir]"\\n
echo "The following switches are recognized:"
echo "--use-immediate-mode --Use libpcap immediate mode which enables getting packets as fast as possible (supported on libpcap>=1.5)"
echo ""
echo "--install-dir --Set installation directory. Default is /usr/local"
echo ""
echo "--libpcap-include-dir --libpcap header files directory. This parameter is optional and if omitted PcapPlusPlus will look for"
echo " the header files in the default include paths"
echo "--libpcap-lib-dir --libpcap pre compiled lib directory. This parameter is optional and if omitted PcapPlusPlus will look for"
echo " the lib file in the default lib paths"
echo ""
echo -e "-h|--help --Displays this help message and exits. No further actions are performed"\\n
echo -e "Examples:"
echo -e " $SCRIPT"
echo -e " $SCRIPT --use-immediate-mode"
echo -e " $SCRIPT --libpcap-include-dir /home/myuser/my-libpcap/include --libpcap-lib-dir /home/myuser/my-libpcap/lib"
echo -e " $SCRIPT --install-dir /home/myuser/my-install-dir"
echo ""
exit 1
}
HAS_PCAP_IMMEDIATE_MODE=0
# initializing libpcap include/lib dirs to an empty string
LIBPCAP_INLCUDE_DIR=""
LIBPCAP_LIB_DIR=""
# default installation directory
INSTALL_DIR=/usr/local
#Check the number of arguments. If none are passed, continue to wizard mode.
NUMARGS=$#
echo -e "Number of arguments: $NUMARGS"\\n
# if user put an illegal switch - print HELP and exit
if [ $? -ne 0 ]; then
HELP
fi
EXPECTING_VALUE=0
for i in "$@"
do
case $i in
# default switch - do nothing basically
--default)
;;
# enable libpcap immediate mode
--use-immediate-mode)
HAS_PCAP_IMMEDIATE_MODE=1 ;;
# non-default libpcap include dir
--libpcap-include-dir)
LIBPCAP_INLCUDE_DIR=$2
EXPECTING_VALUE=1 ;;
# non-default libpcap lib dir
--libpcap-lib-dir)
LIBPCAP_LIB_DIR=$2
EXPECTING_VALUE=1 ;;
# installation directory prefix
--install-dir)
INSTALL_DIR=$2
if [ ! -d "$INSTALL_DIR" ]; then
echo "Installation directory '$INSTALL_DIR' not found. Exiting..."
exit 1
fi
EXPECTING_VALUE=1 ;;
# help switch - display help and exit
-h|--help)
HELP ;;
# empty switch - just go on
--)
break ;;
# illegal switch
*)
if [ "$EXPECTING_VALUE" -eq "1" ]; then
EXPECTING_VALUE=0
else
echo -e \\n"Option $i not allowed.";
HELP;
fi ;;
esac
done
PLATFORM_MK="mk/platform.mk"
PCAPPLUSPLUS_MK="mk/PcapPlusPlus.mk"
cp -f mk/platform.mk.macosx $PLATFORM_MK
cp -f mk/PcapPlusPlus.mk.common $PCAPPLUSPLUS_MK
cat mk/PcapPlusPlus.mk.macosx >> $PCAPPLUSPLUS_MK
echo -e "\n\nPCAPPLUSPLUS_HOME := "$PWD >> $PLATFORM_MK
sed -i -e '1s|^|PCAPPLUSPLUS_HOME := '$PWD'\'$'\n''\'$'\n''|' $PCAPPLUSPLUS_MK
if (( $HAS_PCAP_IMMEDIATE_MODE > 0 )) ; then
echo -e "HAS_PCAP_IMMEDIATE_MODE := 1\n\n" >> $PCAPPLUSPLUS_MK
fi
# non-default libpcap include dir
if [ -n "$LIBPCAP_INLCUDE_DIR" ]; then
echo -e "# non-default libpcap include dir" >> $PCAPPLUSPLUS_MK
echo -e "LIBPCAP_INLCUDE_DIR := $LIBPCAP_INLCUDE_DIR" >> $PCAPPLUSPLUS_MK
echo -e "PCAPPP_INCLUDES += -I\$(LIBPCAP_INLCUDE_DIR)\n" >> $PCAPPLUSPLUS_MK
fi
# non-default libpcap lib dir
if [ -n "$LIBPCAP_LIB_DIR" ]; then
echo -e "# non-default libpcap lib dir" >> $PCAPPLUSPLUS_MK
echo -e "LIBPCAP_LIB_DIR := $LIBPCAP_LIB_DIR" >> $PCAPPLUSPLUS_MK
echo -e "PCAPPP_LIBS_DIR += -L\$(LIBPCAP_LIB_DIR)\n" >> $PCAPPLUSPLUS_MK
fi
# generate installation and uninstallation scripts
cp mk/install.sh.template mk/install.sh
sed -i.bak "s|{{INSTALL_DIR}}|$INSTALL_DIR|g" mk/install.sh && rm mk/install.sh.bak
chmod +x mk/install.sh
cp mk/uninstall.sh.template mk/uninstall.sh
sed -i.bak "s|{{INSTALL_DIR}}|$INSTALL_DIR|g" mk/uninstall.sh && rm mk/uninstall.sh.bak
chmod +x mk/install.sh
echo "PcapPlusPlus configuration is complete. Files created (or modified): $PLATFORM_MK, $PCAPPLUSPLUS_MK", mk/install.sh, mk/uninstall.sh