meta-flow: Correctly set destination MAC in mf_set_flow_value().
[sliver-openvswitch.git] / rhel / kmodtool-openvswitch-el5.sh
1 #!/bin/bash
2
3 # kmodtool - Helper script for building kernel module RPMs
4 # Copyright (c) 2003-2008 Ville Skyttä <ville.skytta@iki.fi>,
5 #                         Thorsten Leemhuis <fedora@leemhuis.info>
6 #                         Jon Masters <jcm@redhat.com>
7 #
8 # Permission is hereby granted, free of charge, to any person obtaining
9 # a copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish,
12 # distribute, sublicense, and/or sell copies of the Software, and to
13 # permit persons to whom the Software is furnished to do so, subject to
14 # the following conditions:
15 #
16 # The above copyright notice and this permission notice shall be
17 # included in all copies or substantial portions of the Software.
18 #
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 shopt -s extglob
28
29 myprog="kmodtool"
30 myver="0.10.10_kmp3"
31 knownvariants=@(BOOT|PAE|@(big|huge)mem|debug|enterprise|kdump|?(large)smp|uml|xen[0U]?(-PAE)|xen)
32 kmod_name=
33 kver=
34 verrel=
35 variant=
36 kmp=
37
38 get_verrel ()
39 {
40   verrel=${1:-$(uname -r)}
41   verrel=${verrel%%$knownvariants}
42 }
43
44 print_verrel ()
45 {
46   get_verrel $@
47   echo "${verrel}"
48 }
49
50 get_variant ()
51 {
52   get_verrel $@
53   variant=${1:-$(uname -r)}
54   variant=${variant##$verrel}
55   variant=${variant:-'""'}
56 }
57
58 print_variant ()
59 {
60   get_variant $@
61   echo "${variant}"
62 }
63
64 get_rpmtemplate ()
65 {
66     local variant="${1}"
67     local dashvariant="${variant:+-${variant}}"
68     case "$verrel" in
69         *.el*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
70         *.EL*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
71         *)     kdep="kernel-%{_target_cpu} = ${verrel}${variant}"     ;;
72     esac
73
74     echo "%package       -n kmod-${kmod_name}${dashvariant}"
75
76     if [ -z "$kmp_provides_summary" ]; then
77         echo "Summary:          ${kmod_name} kernel module(s)"
78     fi
79
80     if [ -z "$kmp_provides_group" ]; then
81         echo "Group:            System Environment/Kernel"
82     fi
83
84     if [ ! -z "$kmp_version" ]; then
85         echo "Version: %{kmp_version}"
86     fi
87
88     if [ ! -z "$kmp_release" ]; then
89         echo "Release: %{kmp_release}"
90     fi
91     
92     if [ ! -z "$kmp" ]; then
93         echo "%global _use_internal_dependency_generator 0"
94     fi
95     
96     cat <<EOF
97 Provides:         kernel-modules = ${verrel}${variant}
98 Provides:         ${kmod_name}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
99 EOF
100     
101     if [ -z "$kmp" ]; then
102         echo "Requires:         ${kdep}"
103     fi
104
105 #
106 # RHEL5 - Remove common package requirement on general kmod packages.
107 # Requires: ${kmod_name}-kmod-common >= %{?epoch:%{epoch}:}%{version}
108 #
109
110     cat <<EOF
111 Requires(post):   /sbin/depmod
112 Requires(postun): /sbin/depmod
113 EOF
114
115 if [ "no" != "$kmp_nobuildreqs" ]
116 then
117     echo "BuildRequires: kernel${dashvariant}-devel-%{_target_cpu} = ${verrel}"
118 fi
119
120 if [ "" != "$kmp_override_preamble" ]
121 then
122     cat "$kmp_override_preamble"
123 fi
124
125 cat <<EOF
126 %description   -n kmod-${kmod_name}${dashvariant}
127 This package provides the ${kmod_name} kernel modules built for the Linux
128 kernel ${verrel}${variant} for the %{_target_cpu} family of processors.
129 %post          -n kmod-${kmod_name}${dashvariant}
130 if [ -e "/boot/System.map-${verrel}${variant}" ]; then
131     /sbin/depmod -aeF "/boot/System.map-${verrel}${variant}" "${verrel}${variant}" > /dev/null || :
132 fi
133 EOF
134     
135     if [ ! -z "$kmp" ]; then
136         cat <<EOF
137
138 #modules=( \$(rpm -ql kmod-${kmod_name}${dashvariant} | grep '\.ko$') )
139 modules=( \$(find /lib/modules/${verrel}${variant}/extra/${kmod_name} \
140           | grep '\.ko$') )
141 if [ -x "/sbin/weak-modules" ]; then
142     printf '%s\n' "\${modules[@]}" \
143     | /sbin/weak-modules --add-modules
144 fi
145 %preun         -n kmod-${kmod_name}${dashvariant}
146 rpm -ql kmod-${kmod_name}${dashvariant} | grep '\.ko$' \
147     > /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
148 EOF
149         
150     fi
151     
152     cat <<EOF
153 %postun        -n kmod-${kmod_name}${dashvariant}
154 /sbin/depmod -aF /boot/System.map-${verrel}${variant} ${verrel}${variant} &> /dev/null || :
155 EOF
156     
157     if [ ! -z "$kmp" ]; then
158         cat <<EOF
159 modules=( \$(cat /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules) )
160 #rm /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
161 if [ -x "/sbin/weak-modules" ]; then
162     printf '%s\n' "\${modules[@]}" \
163     | /sbin/weak-modules --remove-modules
164 fi
165 EOF
166     fi
167
168 echo "%files         -n kmod-${kmod_name}${dashvariant}"
169
170 if [ "" == "$kmp_override_filelist" ];
171 then
172     echo "%defattr(644,root,root,755)"
173     echo "/lib/modules/${verrel}${variant}/"
174     echo "%config /etc/depmod.d/kmod-${kmod_name}.conf"
175     #BZ252188 - I've commented this out for the moment since RHEL5 doesn't
176     #           really support external firmware e.g. at install time. If
177     #           you really want it, use an override filelist solution.
178     #echo "/lib/firmware/"
179 else
180     cat "$kmp_override_filelist"
181 fi
182 }
183
184 print_rpmtemplate ()
185 {
186   kmod_name="${1}"
187   shift
188   kver="${1}"
189   get_verrel "${1}"
190   shift
191   if [ -z "${kmod_name}" ] ; then
192     echo "Please provide the kmodule-name as first parameter." >&2
193     exit 2
194   elif [ -z "${kver}" ] ; then
195     echo "Please provide the kver as second parameter." >&2
196     exit 2
197   elif [ -z "${verrel}" ] ; then
198     echo "Couldn't find out the verrel." >&2
199     exit 2
200   fi
201   
202   for variant in "$@" ; do
203       if [ "default" == "$variant" ];
204       then
205             get_rpmtemplate ""
206       else
207             get_rpmtemplate "${variant}"
208       fi
209   done
210 }
211
212 usage ()
213 {
214   cat <<EOF
215 You called: ${invocation}
216
217 Usage: ${myprog} <command> <option>+
218  Commands:
219   verrel <uname>                               
220     - Get "base" version-release.
221   variant <uname>                               
222     - Get variant from uname.
223   rpmtemplate <mainpgkname> <uname> <variants> 
224     - Return a template for use in a source RPM
225   rpmtemplate_kmp <mainpgkname> <uname> <variants>
226     - Return a template for use in a source RPM with KMP dependencies
227   version  
228     - Output version number and exit.
229 EOF
230 }
231
232 invocation="$(basename ${0}) $@"
233 while [ "${1}" ] ; do
234   case "${1}" in
235     verrel)
236       shift
237       print_verrel $@
238       exit $?
239       ;;
240     variant)
241       shift
242       print_variant $@
243       exit $?
244       ;;
245     rpmtemplate)
246       shift
247       print_rpmtemplate "$@"
248       exit $?
249       ;;
250     rpmtemplate_kmp)
251       shift
252       kmp=1
253       print_rpmtemplate "$@"
254       exit $?
255       ;;
256     version)
257       echo "${myprog} ${myver}"
258       exit 0
259       ;;
260     *)
261       echo "Error: Unknown option '${1}'." >&2
262       usage >&2
263       exit 2
264       ;;
265   esac
266 done
267
268 # Local variables:
269 # mode: sh
270 # sh-indentation: 2
271 # indent-tabs-mode: nil
272 # End:
273 # ex: ts=2 sw=2 et