macos launchd be more patient
[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     *.el6*)  verrel="`echo ${verrel} | sed -e 's/^\(.*.el6[^\.]*\)\.[^\.]\+.\?$/\1/'`" ;;
44     *.fc9*)  verrel="`echo ${verrel} | sed -e 's/^\(.*.fc9[^\.]*\)\.[^\.]\+.\?$/\1/'`" ;;
45     *.fc1?*) verrel="`echo ${verrel} | sed -e 's/^\(.*.fc1[0-9][^\.]*\)\.[^\.]\+.\?$/\1/'`" ;;
46   esac
47 }
48
49 print_verrel ()
50 {
51   get_verrel $@
52   echo "${verrel}"
53 }
54
55 get_variant ()
56 {
57   get_verrel $@
58   variant=${1:-$(uname -r)}
59   variant=${variant##$verrel}
60   variant=${variant:-'""'}
61 }
62
63 print_variant ()
64 {
65   get_variant $@
66   echo "${variant}"
67 }
68
69
70 get_rpmtemplate ()
71 {
72     local variant="${1}"
73     local dashvariant="${variant:+-${variant}}"
74     case "$verrel" in
75         *.el6*) kdep="kernel-%{_target_cpu} = ${verrel}${variant}"     ;;
76         *.EL*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
77         *)     kdep="kernel-%{_target_cpu} = ${verrel}${variant}"     ;;
78     esac
79     case "$verrel" in
80         *.el6*)   kname="${verrel}.%{_target_cpu}${variant:+.${variant}}" ;;
81         *.fc9*)   kname="${verrel}.%{_target_cpu}${variant:+.${variant}}" ;;
82         *.fc1?*)  kname="${verrel}.%{_target_cpu}${variant:+.${variant}}" ;;
83         *)        kname="${verrel}${variant}"                             ;;
84     esac
85
86     cat <<EOF
87 %package       -n kmod-${kmod_name}${dashvariant}
88 Summary:          ${kmod_name} kernel module(s)
89 Group:            System Environment/Kernel
90 Provides:         kernel-modules = ${kname}
91 Provides:         ${kmod_name}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
92 Provides:         openafs-kernel = %{PACKAGE_VERSION}
93 Requires:         ${kdep}
94 Requires:         ${kmod_name}-kmod-common >= %{?epoch:%{epoch}:}%{version}
95 Requires(post):   /sbin/depmod
96 Requires(postun): /sbin/depmod
97 Release:          %{pkgrel}.%(echo ${verrel} | tr - _)
98 BuildRequires:    kernel${dashvariant}-devel-%{_target_cpu} = ${verrel}
99 %description   -n kmod-${kmod_name}${dashvariant}
100 This package provides the ${kmod_name} kernel modules built for the Linux
101 kernel ${kname} for the %{_target_cpu} family of processors.
102 %post          -n kmod-${kmod_name}${dashvariant}
103 /sbin/depmod -aeF /boot/System.map-${kname} ${kname} > /dev/null || :
104 %postun        -n kmod-${kmod_name}${dashvariant}
105 /sbin/depmod -aF /boot/System.map-${kname} ${kname} &> /dev/null || :
106 %files         -n kmod-${kmod_name}${dashvariant}
107 %defattr(644,root,root,755)
108 /lib/modules/${kname}/extra/${kmod_name}/
109
110 EOF
111 }
112
113 print_rpmtemplate ()
114 {
115   kmod_name="${1}"
116   shift
117   kver="${1}"
118   get_verrel "${1}"
119   shift
120   if [ -z "${kmod_name}" ] ; then
121     echo "Please provide the kmodule-name as first parameter." >&2
122     exit 2
123   elif [ -z "${kver}" ] ; then
124     echo "Please provide the kver as second parameter." >&2
125     exit 2
126   elif [ -z "${verrel}" ] ; then
127     echo "Couldn't find out the verrel." >&2
128     exit 2
129   fi
130
131   for variant in "$@" ; do
132     get_rpmtemplate "${variant}"
133   done
134 }
135
136 usage ()
137 {
138   cat <<EOF
139 You called: ${invocation}
140
141 Usage: ${myprog} <command> <option>+
142  Commands:
143   verrel <uname>                               
144     - Get "base" version-release.
145   variant <uname>                               
146     - Get variant from uname.
147   rpmtemplate <mainpgkname> <uname> <variants> 
148     - Return a template for
149   version  
150     - Output version number and exit.
151 EOF
152 }
153
154 invocation="$(basename ${0}) $@"
155 while [ "${1}" ] ; do
156   case "${1}" in
157     verrel)
158       shift
159       print_verrel $@
160       exit $?
161       ;;
162     variant)
163       shift
164       print_variant $@
165       exit $?
166       ;;
167     rpmtemplate)
168       shift
169       print_rpmtemplate "$@"
170       exit $?
171       ;;
172     version)
173       echo "${myprog} ${myver}"
174       exit 0
175       ;;
176     *)
177       echo "Error: Unknown option '${1}'." >&2
178       usage >&2
179       exit 2
180       ;;
181   esac
182 done
183
184 # Local variables:
185 # mode: sh
186 # sh-indentation: 2
187 # indent-tabs-mode: nil
188 # End:
189 # ex: ts=2 sw=2 et