Whamcloud - gitweb
LU-4156 wireshark: Fix build against wireshark 1.10.x
[fs/lustre-release.git] / lustre / contrib / wireshark / wsbuild
1 #!/bin/sh -vx
2
3 #
4 # Script creates wireshark RPM and an separate  RPM with the wireshare lnet/lustre plugins,
5 # installs and test whether the plugins can be selected as filters.
6
7
8 #
9 #       H E L P E R    F U N C T I O N S
10 #
11
12
13 error() {
14     local msg="$1"
15
16     [ -n "$msg" ] && echo -e "\n${0##*/}: $msg" >&1
17
18 }
19
20 fatal() {
21 #    cleanup
22     error "$2"
23     exit $1
24 }
25
26     # Wipe away the temporary build / install directory + content
27 cleanup () {
28
29     echo "Cleanup ${BUILD_DIR}"
30     cd ${BUILD_DIR}
31     if [ $? -ne 0 ] ; then
32         echo "Can't change to ${BUILD_DIR} for clean-up. No clean-up performed."
33         exit 1
34     fi
35         # remove wireshark source directory and tarball and auxiliary directory to tar plugin sources
36     rm -rf wireshark-${WS_VERSION} wireshark-${WS_VERSION}.tar.bz2 ${PLUGIN_RPM_NAME}-${WS_VERSION}/ ${PLUGIN_RPM_NAME}-${WS_VERSION}-root/
37 }
38
39
40 #
41 #       M A I N 
42 #
43
44     # Enable download and compile environment settings
45 source ${0%/wsbuild}/wsconfig.sh
46 if [ $? -ne 0 ] ; then
47     echo "FAILED"
48     fatal 1 "Can't source download and compile evironmnent defined in ${0%/wsbuild}/wsconfig.sh"
49 fi
50
51     # Check whether prereqisited software is installed
52 echo "Prerequisite software installations:"
53 for pkg in $PREREQUISITE_RPMS
54 do
55     echo -e "\tPackage '$pkg'\t installed: \c"
56     rpm -q $pkg > /dev/null 2>&1
57     if [ $? -ne 0 ] ; then
58         echo "NO"
59         fatal 1 "RPM (software) '$pkg' not installed. Can't compile wireshark."
60     fi
61     echo "YES"
62
63 done
64
65     # Change CWD to top level build directory
66 echo -e "Change to top level builddir: \c"
67 cd $BUILD_DIR
68 if [ $? -ne 0 ] ; then
69     echo "FAILED"
70     fatal 1 "Can't change to directory '${BUILD_DIR}'. Make sure that directory exist."
71 fi
72 echo "OK"
73
74
75     # Download wireshark
76 if [ ! -x /usr/bin/curl ] ; then
77     fatal 1 "curl not installed. Can't download wireshark."
78 fi
79 ws_file_name=`basename ${WS_SOURCE_URL}`
80 # echo "ws_file_name: $ws_file_name"
81 echo -e "Download wireshare source tarball: \c"
82     # Download desired wireshark tarball
83 /usr/bin/curl ${WS_SOURCE_URL} --output ${BUILD_DIR}/${ws_file_name}
84 if [ $? -ne 0 ] ; then
85     echo "FAILED"
86     fatal 1 "Can't download wireshark version ${WS_VERSION}. Check configuration."
87 fi
88 echo "OK"
89
90
91
92 echo -e "Inflating wireshark tarball: \c"
93 ${UNTAR} ${ws_file_name}
94 if [ $? -ne 0 ] ; then
95     echo "FAILED"
96     fatal 1 "Can't untar file '${ws_file_name}'."
97 fi
98 echo "OK"
99
100
101     # Build wireshark software
102 cd ${BUILD_DIR}/wireshark-${WS_VERSION}
103 if [ $? -ne 0 ] ; then
104     fatal 1 "Can't change to directory '${BUILD_DIR}/wireshark-${WS_VERSION}'."
105 fi
106
107
108     # Executing configure first to create the make file and 
109     # rpm spec file. Procedure is a bit ood, since `make rpm-package' 
110     # is running configure again.
111 echo -e "Execute wireshark's configure script: \c"
112 ./configure
113 if [ $? -ne 0 ] ; then
114     echo "FAILED"
115     echo "----------- configure output ---------------------"
116     cat Configure-$$.log
117     echo "--------------------------------"
118     fatal 1 "configure script in ${BUILD_DIR}/wireshark-${WS_VERSION} stops with errors"
119 fi
120 echo "OK"
121
122
123     # Currently code works distribution using RPM for package management only, i.e.:
124     # for RHEL/CentOS, SLES (suse)
125     #
126     # Code to support distributions using debian software packaging
127     # have to be added.
128
129     # SLES SP1, 2 specific handling
130 if [ -r /etc/SuSE-release ] ; then
131
132         # Correct RPM spec file to build correctly:
133         # Note: changes are based on wireshark version 1.6.8
134         #
135         # -1- Adjust BuildRoot macro. 
136         #    Otherwise packaging will fail since SuSe expand BuildRoot to '/tmp/...'
137         #    Files can't be found by packaging program
138         #
139         # -2- Correct libdir macro.
140         #    Set library prefix to '/usr/lib64'
141         #
142         # -3- Correct file globing used for packaging library files
143         #    Globbing pattern set to '%prefix/lib64/*' in %files section
144         #    to capture the accordingly to change -2-
145         #
146     sed -e "s#\(BuildRoot:[[:space:]]*\)/[a-zA-Z0-9_]*\(/wireshark-%{PACKAGE_VERSION}-root\)#\1${BUILD_DIR}packaging/rpm/BUILD\2#" \
147         -e 's#\(.* \./configure .*\)#\1 --libdir=/usr/lib64#' \
148         -e 's#^\(%prefix/lib\)/\*#\164/\*#' ./packaging/rpm/SPECS/wireshark.spec > new-$$.spec
149         if [ $? -ne 0 ] ; then
150             fatal 1 "Can't modify wireshark SPEC file to build under SLES"
151         fi
152             # Move modified SPEC into effect
153         mv new-$$.spec ./packaging/rpm/SPECS/wireshark.spec
154         if [ $? -ne 0 ] ; then
155             fatal 1 "Can't copy modified wireshark SPEC file (SLES to ${BUILD_DIR}/packaging/rpm/SPECS/wireshark.spec"
156         fi
157
158 fi
159
160     
161 echo -e "Create wireshark RPM: \c"
162 make rpm-package
163 if [ $? -ne 0 ] ; then
164     echo "FAILED"
165     echo "----------- make rpm-package output ---------------------"
166     cat make-rpm-$$.log
167     echo "--------------------------------"
168     fatal 1 "make rmp-package failed in  ${BUILD_DIR}/wireshark-${WS_VERSION}"
169 fi
170 # Package successfully built in ${BUILD_DIR}/wireshark-${WS_VERSION}/packaging/rpm/RPMS.
171 echo "OK"
172
173
174 cd ${BUILD_DIR}
175 if [ $? -ne 0 ] ; then
176     fatal 1 "Can't change into directory ${BUILD_DIR}"
177 fi
178
179 PLUGINS_LIBDIR=''
180     # SLES SP1, 2 installs 64Bit libs and binaries into /usr/lib64
181     # 
182 if [ -r /etc/SuSE-release ] ; then
183
184     PLUGINS_LIBDIR='/usr/lib64/wireshark/plugins/%ver/*'
185 else
186     PLUGINS_LIBDIR='/usr/lib/wireshark/plugins/%ver/*'
187 fi
188
189 echo -e "Create Lustre/LNet wireshark plugin RPM: \c"
190
191     # Insert the associated version, name and build directory info
192     # to the SPEC template. Use '#' 
193     # as delimiters since path info will be substituted
194 sed -e "s#XXX-TOP-LEVEL-BUILD-DIR-XXX#${BUILD_DIR}#" \
195     -e "s#XXX-LUSTRE-PLUGIN-VERSION-XXX#${WS_VERSION}#" \
196     -e "s#XXX-LUSTRE-PLUGIN-RPM-NAME-XXX#${PLUGIN_RPM_NAME}#" \
197     -e "s#XXX-LUSTRE-PLUGIN-LIBDIR-XXX#${PLUGINS_LIBDIR}#" \
198     lustre-wireshark-plugins-template.spec > ${PLUGIN_RPM_NAME}.spec
199 if [ $? -ne 0 ] ; then
200     echo "FAILED"
201     fatal 1 "Can't create SPEC file for Lustre/LNet wireshark plugins"
202 fi
203
204
205     # Create tarball containing source files plugins to be used rpmbuid mechanism
206 if [ -d ${PLUGIN_RPM_NAME}-${WS_VERSION} ] ; then
207     rm -rf lustre-wireshark-plugins-1.6.8
208     if [ $? -ne 0 ] ; then
209         fatal 1 "Can't cleanup auxiliary directory to create tarball of Lustre/LNet plugins"
210     fi
211 fi
212     # Create auxiliary directory
213 mkdir ${PLUGIN_RPM_NAME}-${WS_VERSION}
214 if [ $? -ne 0 ] ; then
215     echo "FAILED"
216     fatal 1 "Can't create packaging directory to create source tarball for lustre wireshark plugins"
217 fi
218 cp README Makefile packet-lnet.c packet-lustre.c ${PLUGIN_RPM_NAME}-${WS_VERSION}
219 if [ $? -ne 0 ] ; then
220     echo "FAILED"
221     fatal 1 "Can't copy files for rpm source tar ball into helper directory for Lustre/LNet wireshark plugins"
222 fi
223
224 $TAR ${PLUGIN_RPM_NAME}-${WS_VERSION}.tar.bz2 ${PLUGIN_RPM_NAME}-${WS_VERSION}/
225 if [ $? -ne 0 ] ; then
226     echo "FAILED"
227     fatal 1 "Can't create rpm source tar ball for Lustre/LNet wireshark plugins"
228 fi
229
230     # install source tarball into build directory
231 cp ${PLUGIN_RPM_NAME}-${WS_VERSION}.tar.bz2 ${BUILD_DIR}/wireshark-${WS_VERSION}/packaging/rpm/SOURCES
232 if [ $? -ne 0 ] ; then
233     echo "FAILED"
234     fatal 1 "Can't copy source tar ball for Lustre/LNet wireshark plugins build directory"
235 fi
236
237 rpmbuild -bb --define "_topdir ${BUILD_DIR}/wireshark-${WS_VERSION}/packaging/rpm" ${PLUGIN_RPM_NAME}.spec
238 if [ $? -ne 0 ] ; then
239     echo "FAILED"
240     fatal 1 "Can't create RPM for Lustre/LNet wireshark plugins"
241 fi
242
243 exit 0