aklog: Avoid misleading AFSCELL message
[openafs.git] / src / packaging / RedHat / openafs-kmodtool
1 #!/bin/bash
2
3 # kmodtool - Helper script for building kernel module RPMs
4 # Copyright (c) 2003-2007 Ville Skyttä <ville.skytta@iki.fi>,
5 #                         Thorsten Leemhuis <fedora@leemhuis.info>
6 #
7 # Modified by Simon Wilkinson for OpenAFS
8
9 # Permission is hereby granted, free of charge, to any person obtaining
10 # a copy of this software and associated documentation files (the
11 # "Software"), to deal in the Software without restriction, including
12 # without limitation the rights to use, copy, modify, merge, publish,
13 # distribute, sublicense, and/or sell copies of the Software, and to
14 # permit persons to whom the Software is furnished to do so, subject to
15 # the following conditions:
16 #
17 # The above copyright notice and this permission notice shall be
18 # included in all copies or substantial portions of the Software.
19 #
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 shopt -s extglob
29
30 myprog="kmodtool"
31 myver="0.10.13"
32 knownvariants=@(BOOT|PAE?(-debug)|@(big|huge)mem|debug|enterprise|kdump|?(large)smp?(-debug)|uml|xen?([0U])?(-PAE))
33 kmod_name=
34 kver=
35 verrel=
36 variant=
37
38 get_verrel ()
39 {
40   verrel=${1:-$(uname -r)}
41   verrel=${verrel%%$knownvariants}
42   case "$verrel" in
43     *.el[6-9].elrepo*)
44                    verrel="`echo ${verrel} | sed -e 's/^\(.*.el[6-9].elrepo[^\.]*\)\.[^\.]\+.\?$/\1/'`" ;;
45     *.el[6-9]*)    verrel="`echo ${verrel} | sed -e 's/^\(.*.el[6-9][^\.]*\)\.[^\.]\+.\?$/\1/'`" ;;
46     *.fc[1-9][0-9]*)
47                    verrel="`echo ${verrel} | sed -e 's/^\(.*.fc[1-9][0-9][^\.]*\)\.[^\.]\+.\?$/\1/'`" ;;
48     *.fc9*)        verrel="`echo ${verrel} | sed -e 's/^\(.*.fc9[^\.]*\)\.[^\.]\+.\?$/\1/'`" ;;
49   esac
50 }
51
52 print_verrel ()
53 {
54   get_verrel $@
55   echo "${verrel}"
56 }
57
58 get_variant ()
59 {
60   get_verrel $@
61   variant=${1:-$(uname -r)}
62   variant=${variant##$verrel}
63   variant=${variant:-'""'}
64 }
65
66 print_variant ()
67 {
68   get_variant $@
69   echo "${variant}"
70 }
71
72
73 get_rpmtemplate ()
74 {
75     local variant="${1}"
76     local dashvariant="${variant:+-${variant}}"
77     case "$verrel" in
78         *.el[6-9]*)
79                kdep="kernel-%{_target_cpu} = ${verrel}${variant}"     ;;
80         *.EL*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
81         *)     kdep="kernel-%{_target_cpu} = ${verrel}${variant}"     ;;
82     esac
83     case "$verrel" in
84         *.el[6-9]*)
85                   kname="${verrel}.%{_target_cpu}${variant:+.${variant}}" ;;
86         *.fc[2-9][0-9]*)
87                   kname="${verrel}.%{_target_cpu}${variant:++${variant}}" ;;
88         *.fc1[0-9]*)
89                   kname="${verrel}.%{_target_cpu}${variant:+.${variant}}" ;;
90         *.fc9*)   kname="${verrel}.%{_target_cpu}${variant:+.${variant}}" ;;
91         *)        kname="${verrel}${variant}"                             ;;
92     esac
93
94     cat <<EOF
95
96 %global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*openafs\.ko.*' -o kmod-debuginfo.list
97
98 %package       -n kmod-${kmod_name}${dashvariant}
99 Summary:          ${kmod_name} kernel module(s)
100 Group:            System Environment/Kernel
101 Provides:         kernel-modules = ${kname}
102 Provides:         ${kmod_name}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
103 Provides:         openafs-kernel = %{version}
104 Requires:         ${kdep}
105 Requires:         ${kmod_name}-kmod-common >= %{?epoch:%{epoch}:}%{version}
106 Requires(post):   ${depmod}
107 Requires(postun): ${depmod}
108 Release:          %{pkgrel}.%(echo ${verrel} | tr - _)
109 BuildRequires:    kernel${dashvariant}-devel-%{_target_cpu} = ${verrel}
110 %if 0%{?rhel} >= 8
111 BuildRequires: elfutils-devel
112 %endif
113 %description   -n kmod-${kmod_name}${dashvariant}
114 This package provides the ${kmod_name} kernel modules built for the Linux
115 kernel ${kname} for the %{_target_cpu} family of processors.
116
117 %package       -n kmod-%{kmod_name}${dashvariant}-debuginfo
118 Summary:          Debug information for %{kmod_name} kernel modules
119 Group:            Development/Debug
120 Release:          %{pkgrel}.%(echo ${verrel} | tr - _)
121 AutoReqProv:      no
122 %description   -n kmod-%{kmod_name}${dashvariant}-debuginfo
123 This package provides debug information for the %{kmod_name} kernel modules
124 built for the Linux kernel ${kname} for the %{_target_cpu} family of processors.
125
126 %post          -n kmod-${kmod_name}${dashvariant}
127 ${depmod} -aeF /boot/System.map-${kname} ${kname} > /dev/null || :
128 %postun        -n kmod-${kmod_name}${dashvariant}
129 ${depmod} -aF /boot/System.map-${kname} ${kname} &> /dev/null || :
130 %files         -n kmod-${kmod_name}${dashvariant}
131 %defattr(644,root,root,755)
132 /lib/modules/${kname}/extra/${kmod_name}/
133
134 %files -f kmod-debuginfo.list -n kmod-%{kmod_name}${dashvariant}-debuginfo
135 %defattr(-,root,root)
136
137 EOF
138 }
139
140 print_rpmtemplate ()
141 {
142   kmod_name="${1}"
143   shift
144   kver="${1}"
145   get_verrel "${1}"
146   shift
147   depmod="${1}"
148   shift
149   if [ -z "${kmod_name}" ] ; then
150     echo "Please provide the kmodule-name as first parameter." >&2
151     exit 2
152   elif [ -z "${kver}" ] ; then
153     echo "Please provide the kver as second parameter." >&2
154     exit 2
155   elif [ -z "${depmod}" ] ; then
156     echo "Please provide the full path to depmod as third parameter." >&2
157     exit 2
158   elif [ -z "${verrel}" ] ; then
159     echo "Couldn't find out the verrel." >&2
160     exit 2
161   fi
162
163   for variant in "$@" ; do
164     get_rpmtemplate "${variant}"
165   done
166 }
167
168 usage ()
169 {
170   cat <<EOF
171 You called: ${invocation}
172
173 Usage: ${myprog} <command> <option>+
174  Commands:
175   verrel <uname>
176     - Get "base" version-release.
177   variant <uname>
178     - Get variant from uname.
179   rpmtemplate <mainpgkname> <uname> </path/to/depmod> <variants>
180     - Return a template for
181   version
182     - Output version number and exit.
183 EOF
184 }
185
186 invocation="$(basename ${0}) $@"
187 while [ "${1}" ] ; do
188   case "${1}" in
189     verrel)
190       shift
191       print_verrel $@
192       exit $?
193       ;;
194     variant)
195       shift
196       print_variant $@
197       exit $?
198       ;;
199     rpmtemplate)
200       shift
201       print_rpmtemplate "$@"
202       exit $?
203       ;;
204     version)
205       echo "${myprog} ${myver}"
206       exit 0
207       ;;
208     *)
209       echo "Error: Unknown option '${1}'." >&2
210       usage >&2
211       exit 2
212       ;;
213   esac
214 done
215
216 # Local variables:
217 # mode: sh
218 # sh-indentation: 2
219 # indent-tabs-mode: nil
220 # End:
221 # ex: ts=2 sw=2 et