forked from seladb/PcapPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-freebsd.sh
executable file
·159 lines (128 loc) · 4.87 KB
/
configure-freebsd.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
#!/usr/local/bin/bash
echo ""
echo "*******************************************"
echo "PcapPlusPlus FreeBSD 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] [--set-direction-enabled] [--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 "--set-direction-enabled --Set direction for capturing incoming packets or outgoing packets (supported on libpcap>=0.9.1)"
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 --set-direction-enabled"
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
HAS_SET_DIRECTION_ENABLED=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
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
# default switch - do nothing basically
--default)
shift ;;
# enable libpcap immediate mode
--use-immediate-mode)
HAS_PCAP_IMMEDIATE_MODE=1
shift ;;
# set direction enabled
--set-direction-enabled)
HAS_SET_DIRECTION_ENABLED=1
shift ;;
# non-default libpcap include dir
--libpcap-include-dir)
LIBPCAP_INLCUDE_DIR=$2
shift
shift ;;
# non-default libpcap lib dir
--libpcap-lib-dir)
LIBPCAP_LIB_DIR=$2
shift
shift ;;
# installation directory prefix
--install-dir)
INSTALL_DIR=$2
if [ ! -d "$INSTALL_DIR" ]; then
echo "Installation directory '$INSTALL_DIR' not found. Exiting..."
exit 1
fi
shift
shift ;;
# help switch - display help and exit
-h|--help)
HELP ;;
# empty switch - just go on
--)
break ;;
# illegal switch
*)
echo -e \\n"Option $key not allowed.";
HELP;
exit 1 ;;
esac
done
PLATFORM_MK="mk/platform.mk"
PCAPPLUSPLUS_MK="mk/PcapPlusPlus.mk"
cp -f mk/platform.mk.freebsd $PLATFORM_MK
cp -f mk/PcapPlusPlus.mk.common $PCAPPLUSPLUS_MK
cat mk/PcapPlusPlus.mk.freebsd >> $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
if (( $HAS_SET_DIRECTION_ENABLED > 0 )) ; then
echo -e "HAS_SET_DIRECTION_ENABLED := 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.freebsd.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.freebsd.template mk/uninstall.sh
sed -i.bak "s|{{INSTALL_DIR}}|$INSTALL_DIR|g" mk/uninstall.sh && rm mk/uninstall.sh.bak
chmod +x mk/uninstall.sh
echo "PcapPlusPlus configuration is complete. Files created (or modified): $PLATFORM_MK, $PCAPPLUSPLUS_MK", mk/install.sh, mk/uninstall.sh