bash scripts: use /usr/bin/env for bash shebangs
Not all systems / distros have a `/bin/bash`, and these scripts are
more difficult to run at development time.
For example, my system is NixOS which doesn't have a /bin/bash. This
is not a problem for NixOS building ZFS as a package: the build
environment automatically replaces these shebangs with corrected
paths.
The problem is much more annoying at development time: either the
scripts don't run, or I correct them for my local machine and deal with
a perpetually dirty work tree.
Before committing this patch I confirmed there are existing scripts
which use `/usr/bin/env` to locate bash, so I am thinking this is a
safe transformation.
There are a handful of other shebangs in this repository which don't
work on my system. This patch is useful on its own specifically for
`commitcheck.sh`, otherwise I can't validate my commits before
submission.
Here are the remaining shebangs which NixOS systems won't have:
1274 #!/bin/ksh -p
91 #!/bin/ksh
89 #! /bin/ksh -p
2 #!/bin/sed -f
1 #!/usr/bin/perl -w
1 #!/usr/bin/ksh
1 #!/bin/nawk -f
plus this which will create an invalid shebang in
`tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib`:
echo "#!/bin/ksh" > $TEST_BASE_DIR/exitsZero.ksh
I chose to leave those alone for now, and gauge the interest in this
much smaller patch first.
The fixes for these are easy enough by simply using `/usr/bin/env ksh`:
91 #!/bin/ksh
1 #!/usr/bin/ksh
The fix for the other set is much trickier. Quoting the GNU coreutils
manual:
Most operating systems (e.g. GNU/Linux, BSDs) treat all text after
the first space as a single argument. When using env in a script it
is thus not possible to specify multiple arguments.
and not all `env`'s support arguments.
Mine (GNU Coreutils 8.31) does, though this feature is new since
April 2018, GNU Coreutils 8.30:
https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=668306ed86c8c79b0af0db8b9c882654ebb66db2
and worse, requires the -S argument:
-S, --split-string=S process and split S into separate arguments;
used to pass multiple arguments on shebang
lines
Example:
$ seq 1 2 | $(nix-build '<nixpkgs>' -A coreutils)/bin/env "sort -nr"
/nix/[...]-coreutils-8.31/bin/env: ‘sort -nr’: No such file or directory
/nix/[...]-coreutils-8.31/bin/env: use -[v]S to pass options in shebang lines
$ seq 1 2 | $(nix-build '<nixpkgs>' -A coreutils)/bin/env "-S sort -nr"
2
1
GNU Coreutils says FreeBSD's `env` does, though I wonder if FreeBSD's
would be unhappy with the `-S`:
https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#env-invocation
BusyBox v1.30.1 does not, and does not have a `-S`-like option:
$ seq 1 2 | $(nix-build '<nixpkgs>' -A busybox)/bin/env "sort -nr"
env: can't execute 'sort -nr': No such file or directory
Toybox 0.8.1 also does not, and also does not have a `-S` option:
$ seq 1 2 | $(nix-build '<nixpkgs>' -A toybox)/bin/env "sort -nr"
env: exec sort -nr: No such file or directory
---
At any rate, if this patch merges and the remaining ~1,500 are updated,
the much larger patch should probably include a checkstyle-like test
asserting all new shebangs use `/usr/bin/env`. I also don't mind
dealing with NixOS weirdness if the project would prefer that.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Graham Christensen <graham@grahamc.com>
Closes #9893
2020-02-11 00:13:46 +03:00
|
|
|
#!/usr/bin/env bash
|
2021-05-22 00:43:38 +03:00
|
|
|
# shellcheck disable=SC2086
|
2013-02-18 00:10:17 +04:00
|
|
|
|
|
|
|
# kmodtool - Helper script for building kernel module RPMs
|
|
|
|
# Copyright (c) 2003-2012 Ville Skyttä <ville.skytta@iki.fi>,
|
|
|
|
# Thorsten Leemhuis <fedora@leemhuis.info>
|
|
|
|
# Nicolas Chauvet <kwizart@gmail.com>
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
|
|
|
myprog="kmodtool-${repo}"
|
|
|
|
myver="0.12.1"
|
|
|
|
|
|
|
|
kmodname=
|
|
|
|
build_kernels="current"
|
|
|
|
kernels_known_variants=
|
|
|
|
kernel_versions=
|
|
|
|
kernel_versions_to_build_for=
|
|
|
|
prefix=
|
|
|
|
filterfile=
|
|
|
|
target=
|
2013-04-19 00:57:29 +04:00
|
|
|
buildroot=
|
2021-05-22 00:43:38 +03:00
|
|
|
dashvariant=
|
2013-02-18 00:10:17 +04:00
|
|
|
|
|
|
|
error_out()
|
|
|
|
{
|
|
|
|
local errorlevel=${1}
|
|
|
|
shift
|
2021-05-22 00:43:38 +03:00
|
|
|
echo "Error: $*" >&2
|
2013-02-18 00:10:17 +04:00
|
|
|
# the next line is not multi-line safe -- not needed *yet*
|
2021-05-22 00:43:38 +03:00
|
|
|
echo "%global kmodtool_check echo \"kmodtool error: $*\"; exit ${errorlevel};"
|
|
|
|
exit "${errorlevel}"
|
2013-02-18 00:10:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
print_rpmtemplate_header()
|
|
|
|
{
|
|
|
|
echo
|
2022-01-13 21:09:19 +03:00
|
|
|
echo "%global kmodinstdir_prefix ${prefix}/lib/modules/"
|
|
|
|
echo "%global kmodinstdir_postfix /extra/${kmodname}/"
|
|
|
|
echo "%global kernel_versions ${kernel_versions}"
|
2013-02-18 00:10:17 +04:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
print_akmodtemplate ()
|
|
|
|
{
|
|
|
|
echo
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
%global akmod_install mkdir -p \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/; \\\
|
2014-06-10 01:27:09 +04:00
|
|
|
LANG=C rpmbuild --define "_sourcedir %{_sourcedir}" \\\
|
2013-02-18 00:10:17 +04:00
|
|
|
--define "_srcrpmdir \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/" \\\
|
|
|
|
-bs --nodeps %{_specdir}/%{name}.spec ; \\\
|
|
|
|
ln -s \$(ls \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/) \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/${kmodname}-kmod.latest
|
|
|
|
|
|
|
|
%package -n akmod-${kmodname}
|
|
|
|
Summary: Akmod package for ${kmodname} kernel module(s)
|
|
|
|
Group: System Environment/Kernel
|
|
|
|
Requires: kmodtool
|
|
|
|
Requires: akmods
|
|
|
|
%{?AkmodsBuildRequires:Requires: %{AkmodsBuildRequires}}
|
|
|
|
# same requires and provides as a kmods package would have
|
|
|
|
Requires: ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}
|
|
|
|
Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
EOF
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
echo "Provides: akmod-${obsolete_name} = ${obsolete_version}"
|
|
|
|
echo "Obsoletes: akmod-${obsolete_name} < ${obsolete_version}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
%description -n akmod-${kmodname}
|
|
|
|
This package provides the akmod package for the ${kmodname} kernel modules.
|
|
|
|
|
|
|
|
%posttrans -n akmod-${kmodname}
|
|
|
|
nohup ${prefix}/sbin/akmods --from-akmod-posttrans --akmod ${kmodname} &> /dev/null &
|
|
|
|
|
|
|
|
%files -n akmod-${kmodname}
|
|
|
|
%defattr(-,root,root,-)
|
|
|
|
%{_usrsrc}/akmods/*
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
print_akmodmeta ()
|
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
%package -n kmod-${kmodname}
|
|
|
|
Summary: Metapackage which tracks in ${kmodname} kernel module for newest kernel${dashvariant}
|
|
|
|
Group: System Environment/Kernel
|
|
|
|
|
|
|
|
Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
Provides: kmod-${kmodname}-xen = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
Provides: kmod-${kmodname}-smp = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
Provides: kmod-${kmodname}-PAE = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
Requires: akmod-${kmodname} = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
EOF
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
echo "Provides: kmod-${obsolete_name} = ${obsolete_version}"
|
|
|
|
echo "Obsoletes: kmod-${obsolete_name} < ${obsolete_version}"
|
|
|
|
fi
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
%description -n kmod-${kmodname}${dashvariant}
|
|
|
|
This is a meta-package without payload which sole purpose is to require the
|
|
|
|
${kmodname} kernel module(s) for the newest kernel${dashvariant},
|
|
|
|
to make sure you get it together with a new kernel.
|
|
|
|
|
|
|
|
%files -n kmod-${kmodname}${dashvariant}
|
|
|
|
%defattr(644,root,root,755)
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
print_rpmtemplate_per_kmodpkg ()
|
|
|
|
{
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ "${1}" = "--custom" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
shift
|
|
|
|
local customkernel=true
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ "${1}" = "--redhat" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
# this is needed for akmods
|
|
|
|
shift
|
|
|
|
local redhatkernel=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
local kernel_uname_r=${1}
|
|
|
|
local kernel_variant="${2:+-${2}}"
|
|
|
|
|
2019-09-11 21:14:50 +03:00
|
|
|
# Detect depmod install location
|
|
|
|
local depmod_path=/sbin/depmod
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ ! -f "${depmod_path}" ]; then
|
2019-09-11 21:14:50 +03:00
|
|
|
depmod_path=/usr/sbin/depmod
|
|
|
|
fi
|
|
|
|
|
|
|
|
# first part
|
2013-02-18 00:10:17 +04:00
|
|
|
cat <<EOF
|
|
|
|
%package -n kmod-${kmodname}-${kernel_uname_r}
|
|
|
|
Summary: ${kmodname} kernel module(s) for ${kernel_uname_r}
|
|
|
|
Group: System Environment/Kernel
|
|
|
|
Provides: kernel-modules-for-kernel = ${kernel_uname_r}
|
|
|
|
Provides: kmod-${kmodname}-uname-r = ${kernel_uname_r}
|
|
|
|
Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
Requires: ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}
|
2019-09-11 21:14:50 +03:00
|
|
|
|
|
|
|
%if 0%{?rhel} == 6 || 0%{?centos} == 6
|
|
|
|
Requires(post): module-init-tools
|
|
|
|
Requires(postun): module-init-tools
|
|
|
|
%else
|
|
|
|
Requires(post): kmod
|
|
|
|
Requires(postun): kmod
|
|
|
|
%endif
|
2013-02-18 00:10:17 +04:00
|
|
|
EOF
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
echo "Provides: kmod-${obsolete_name}-${kernel_uname_r} = ${obsolete_version}"
|
|
|
|
echo "Obsoletes: kmod-${obsolete_name}-${kernel_uname_r} < ${obsolete_version}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# second part
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${customkernel}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
cat <<EOF
|
|
|
|
Requires: kernel-uname-r = ${kernel_uname_r}
|
|
|
|
BuildRequires: kernel-devel-uname-r = ${kernel_uname_r}
|
2013-07-27 15:42:57 +04:00
|
|
|
%{?KmodsRequires:Requires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
|
|
|
|
%{?KmodsRequires:BuildRequires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
|
2013-02-18 00:10:17 +04:00
|
|
|
%post -n kmod-${kmodname}-${kernel_uname_r}
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -f "/boot/System.map-${kernel_uname_r}" ]; then
|
2021-04-07 20:17:39 +03:00
|
|
|
${prefix}${depmod_path} -aeF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} > /dev/null || :
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ -f "/lib/modules/${kernel_uname_r}/System.map" ]; then
|
2021-04-07 20:17:39 +03:00
|
|
|
${prefix}${depmod_path} -aeF /lib/modules/${kernel_uname_r}/System.map ${kernel_uname_r} > /dev/null || :
|
|
|
|
else
|
|
|
|
${prefix}${depmod_path} -ae ${kernel_uname_r} &> /dev/null || :
|
|
|
|
fi
|
2013-02-18 00:10:17 +04:00
|
|
|
%postun -n kmod-${kmodname}-${kernel_uname_r}
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -f "/boot/System.map-${kernel_uname_r}" ]; then
|
2021-04-07 20:17:39 +03:00
|
|
|
${prefix}${depmod_path} -aF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} &> /dev/null || :
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ -f "/lib/modules/${kernel_uname_r}/System.map" ]; then
|
2021-04-07 20:17:39 +03:00
|
|
|
${prefix}${depmod_path} -aF /lib/modules/${kernel_uname_r}/System.map ${kernel_uname_r} &> /dev/null || :
|
|
|
|
else
|
|
|
|
${prefix}${depmod_path} -a ${kernel_uname_r} &> /dev/null || :
|
|
|
|
fi
|
2013-02-18 00:10:17 +04:00
|
|
|
|
|
|
|
EOF
|
|
|
|
else
|
|
|
|
cat <<EOF
|
|
|
|
%post -n kmod-${kmodname}-${kernel_uname_r}
|
2022-01-13 21:09:19 +03:00
|
|
|
[ "\$(uname -r)" = "${kernel_uname_r}" ] && ${prefix}${depmod_path} -a > /dev/null || :
|
2013-02-18 00:10:17 +04:00
|
|
|
%postun -n kmod-${kmodname}-${kernel_uname_r}
|
2022-01-13 21:09:19 +03:00
|
|
|
[ "\$(uname -r)" = "${kernel_uname_r}" ] && ${prefix}${depmod_path} -a > /dev/null || :
|
2013-02-18 00:10:17 +04:00
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
# third part
|
|
|
|
cat <<EOF
|
|
|
|
%description -n kmod-${kmodname}-${kernel_uname_r}
|
|
|
|
This package provides the ${kmodname} kernel modules built for the Linux
|
|
|
|
kernel ${kernel_uname_r} for the %{_target_cpu} family of processors.
|
|
|
|
%files -n kmod-${kmodname}-${kernel_uname_r}
|
|
|
|
%defattr(644,root,root,755)
|
|
|
|
%dir $prefix/lib/modules/${kernel_uname_r}/extra
|
|
|
|
${prefix}/lib/modules/${kernel_uname_r}/extra/${kmodname}/
|
|
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
print_rpmtemplate_kmoddevelpkg ()
|
|
|
|
{
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ "${1}" = "--custom" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
shift
|
|
|
|
local customkernel=true
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ "${1}" = "--redhat" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
shift
|
|
|
|
local redhatkernel=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
local kernel_uname_r=${1}
|
|
|
|
|
2013-02-18 00:10:17 +04:00
|
|
|
cat <<EOF
|
|
|
|
%package -n kmod-${kmodname}-devel
|
|
|
|
Summary: ${kmodname} kernel module(s) devel common
|
|
|
|
Group: System Environment/Kernel
|
2013-07-27 15:42:57 +04:00
|
|
|
Provides: ${kmodname}-devel-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
EOF
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${customkernel}" ] && [ -z "${redhatkernel}" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
echo "Requires: kmod-${kmodname}-devel-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}"
|
|
|
|
fi
|
2013-02-18 00:10:17 +04:00
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
echo "Provides: kmod-${obsolete_name}-devel = ${obsolete_version}"
|
|
|
|
echo "Obsoletes: kmod-${obsolete_name}-devel < ${obsolete_version}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
2013-02-18 00:10:17 +04:00
|
|
|
%description -n kmod-${kmodname}-devel
|
|
|
|
This package provides the common header files to build kernel modules
|
2013-07-27 15:42:57 +04:00
|
|
|
which depend on the ${kmodname} kernel module. It may optionally require
|
|
|
|
the ${kmodname}-devel-<kernel> objects for the newest kernel.
|
|
|
|
|
2013-02-18 00:10:17 +04:00
|
|
|
%files -n kmod-${kmodname}-devel
|
|
|
|
%defattr(644,root,root,755)
|
|
|
|
%{_usrsrc}/${kmodname}-%{version}
|
|
|
|
EOF
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2018-02-16 04:53:18 +03:00
|
|
|
echo "%{_usrsrc}/${obsolete_name}-%{version}"
|
|
|
|
fi
|
2013-02-18 00:10:17 +04:00
|
|
|
|
|
|
|
for kernel in ${1}; do
|
|
|
|
local kernel_uname_r=${kernel}
|
|
|
|
echo "%exclude %{_usrsrc}/${kmodname}-%{version}/${kernel_uname_r}"
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2018-02-16 04:53:18 +03:00
|
|
|
echo "%exclude %{_usrsrc}/${obsolete_name}-%{version}/${kernel_uname_r}"
|
|
|
|
fi
|
2013-02-18 00:10:17 +04:00
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
print_rpmtemplate_per_kmoddevelpkg ()
|
|
|
|
{
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ "${1}" = "--custom" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
shift
|
|
|
|
local customkernel=true
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ "${1}" = "--redhat" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
# this is needed for akmods
|
|
|
|
shift
|
|
|
|
local redhatkernel=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
local kernel_uname_r=${1}
|
|
|
|
local kernel_variant="${2:+-${2}}"
|
|
|
|
|
2013-07-27 15:42:57 +04:00
|
|
|
# first part
|
2013-02-18 00:10:17 +04:00
|
|
|
cat <<EOF
|
|
|
|
%package -n kmod-${kmodname}-devel-${kernel_uname_r}
|
|
|
|
Summary: ${kmodname} kernel module(s) devel for ${kernel_uname_r}
|
|
|
|
Group: System Environment/Kernel
|
2013-07-27 15:42:57 +04:00
|
|
|
Provides: kernel-objects-for-kernel = ${kernel_uname_r}
|
2013-03-25 22:28:18 +04:00
|
|
|
Provides: ${kmodname}-devel-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
|
2013-07-27 15:42:57 +04:00
|
|
|
Provides: kmod-${kmodname}-devel-uname-r = ${kernel_uname_r}
|
2013-02-18 00:10:17 +04:00
|
|
|
EOF
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
echo "Provides: kmod-${obsolete_name}-devel-${kernel_uname_r} = ${obsolete_version}"
|
|
|
|
echo "Obsoletes: kmod-${obsolete_name}-devel-${kernel_uname_r} < ${obsolete_version}"
|
|
|
|
fi
|
|
|
|
|
2013-02-18 00:10:17 +04:00
|
|
|
# second part
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${customkernel}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
cat <<EOF
|
2013-07-27 15:42:57 +04:00
|
|
|
Requires: kernel-devel-uname-r = ${kernel_uname_r}
|
2013-02-18 00:10:17 +04:00
|
|
|
BuildRequires: kernel-devel-uname-r = ${kernel_uname_r}
|
2013-07-27 15:42:57 +04:00
|
|
|
%{?KmodsDevelRequires:Requires: %{KmodsDevelRequires}-uname-r = ${kernel_uname_r}}
|
|
|
|
%{?KmodsDevelRequires:BuildRequires: %{KmodsDevelRequires}-uname-r = ${kernel_uname_r}}
|
2013-02-18 00:10:17 +04:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2013-07-27 15:42:57 +04:00
|
|
|
# third part
|
2013-02-18 00:10:17 +04:00
|
|
|
cat <<EOF
|
|
|
|
%description -n kmod-${kmodname}-devel-${kernel_uname_r}
|
|
|
|
This package provides objects and symbols required to build kernel modules
|
|
|
|
which depend on the ${kmodname} kernel modules built for the Linux
|
|
|
|
kernel ${kernel_uname_r} for the %{_target_cpu} family of processors.
|
|
|
|
%files -n kmod-${kmodname}-devel-${kernel_uname_r}
|
|
|
|
%defattr(644,root,root,755)
|
|
|
|
%{_usrsrc}/${kmodname}-%{version}/${kernel_uname_r}
|
|
|
|
EOF
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2018-02-16 04:53:18 +03:00
|
|
|
echo "%{_usrsrc}/${obsolete_name}-%{version}/${kernel_uname_r}"
|
|
|
|
fi
|
2013-02-18 00:10:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
print_rpmtemplate_kmodmetapkg ()
|
|
|
|
{
|
|
|
|
local kernel_uname_r=${1}
|
|
|
|
local kernel_variant="${2:+-${2}}"
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
%package -n kmod-${kmodname}${kernel_variant}
|
|
|
|
Summary: Metapackage which tracks in ${kmodname} kernel module for newest kernel${kernel_variant}
|
|
|
|
Group: System Environment/Kernel
|
|
|
|
|
|
|
|
Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
|
|
|
|
Requires: kmod-${kmodname}-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}
|
2013-07-27 15:42:57 +04:00
|
|
|
%{?KmodsMetaRequires:Requires: %{?KmodsMetaRequires}}
|
2013-02-18 00:10:17 +04:00
|
|
|
EOF
|
2013-07-27 15:42:57 +04:00
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${obsolete_name}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
echo "Provides: kmod-${obsolete_name}${kernel_variant} = ${obsolete_version}"
|
|
|
|
echo "Obsoletes: kmod-${obsolete_name}${kernel_variant} < ${obsolete_version}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
%description -n kmod-${kmodname}${kernel_variant}
|
|
|
|
This is a meta-package without payload which sole purpose is to require the
|
|
|
|
${kmodname} kernel module(s) for the newest kernel${kernel_variant}.
|
|
|
|
to make sure you get it together with a new kernel.
|
|
|
|
|
|
|
|
%files -n kmod-${kmodname}${kernel_variant}
|
|
|
|
%defattr(644,root,root,755)
|
|
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
print_customrpmtemplate ()
|
|
|
|
{
|
|
|
|
for kernel in ${1}
|
|
|
|
do
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -e "${buildroot}/usr/src/kernels/${kernel}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
# this looks like a Fedora/RH kernel -- print a normal template (which includes the proper BR) and be happy :)
|
2013-04-19 00:57:29 +04:00
|
|
|
kernel_versions="${kernel_versions}${kernel}___${buildroot}%{_usrsrc}/kernels/${kernel} "
|
2013-02-18 00:10:17 +04:00
|
|
|
|
|
|
|
# parse kernel versions string and print template
|
|
|
|
local kernel_verrelarch=${kernel%%${kernels_known_variants}}
|
|
|
|
print_rpmtemplate_per_kmodpkg --redhat ${kernel} ${kernel##${kernel_verrelarch}}
|
|
|
|
|
|
|
|
# create development package
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${devel}" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
# create devel package including common headers
|
|
|
|
print_rpmtemplate_kmoddevelpkg --redhat ${kernel} ${kernel##${kernel_verrelarch}}
|
|
|
|
|
|
|
|
# create devel package
|
2013-02-18 00:10:17 +04:00
|
|
|
print_rpmtemplate_per_kmoddevelpkg --redhat ${kernel} ${kernel##${kernel_verrelarch}}
|
|
|
|
fi
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ -e "${prefix}/lib/modules/${kernel}/build/Makefile" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
# likely a user-build-kernel with available buildfiles
|
|
|
|
# fixme: we should check if uname from Makefile is the same as ${kernel}
|
|
|
|
|
|
|
|
kernel_versions="${kernel_versions}${kernel}___${prefix}/lib/modules/${kernel}/build/ "
|
|
|
|
print_rpmtemplate_per_kmodpkg --custom "${kernel}"
|
|
|
|
|
|
|
|
# create development package
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${devel}" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
# create devel package including common headers
|
|
|
|
print_rpmtemplate_kmoddevelpkg --custom "${kernel}"
|
|
|
|
|
|
|
|
# create devel package
|
2013-02-18 00:10:17 +04:00
|
|
|
print_rpmtemplate_per_kmoddevelpkg --custom "${kernel}"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
error_out 2 "Don't know how to handle ${kernel} -- ${prefix}/lib/modules/${kernel}/build/Makefile not found"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# well, it's no header anymore, but who cares ;-)
|
|
|
|
print_rpmtemplate_header
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
print_rpmtemplate ()
|
|
|
|
{
|
|
|
|
# create kernel_versions var
|
|
|
|
for kernel_version in ${kernel_versions_to_build_for}
|
|
|
|
do
|
|
|
|
kernel_versions="${kernel_versions}${kernel_version}___%{_usrsrc}/kernels/${kernel_version} "
|
|
|
|
done
|
|
|
|
|
|
|
|
# and print it and some other required stuff as macro
|
|
|
|
print_rpmtemplate_header
|
|
|
|
|
2019-09-03 04:17:39 +03:00
|
|
|
# now print the packages
|
2013-02-18 00:10:17 +04:00
|
|
|
for kernel in ${kernel_versions_to_build_for} ; do
|
|
|
|
|
|
|
|
local kernel_verrelarch=${kernel%%${kernels_known_variants}}
|
|
|
|
|
|
|
|
# create metapackage
|
2022-01-13 21:09:19 +03:00
|
|
|
print_rpmtemplate_kmodmetapkg "${kernel}" "${kernel##${kernel_verrelarch}}"
|
2013-02-18 00:10:17 +04:00
|
|
|
|
|
|
|
# create package
|
2022-01-13 21:09:19 +03:00
|
|
|
print_rpmtemplate_per_kmodpkg "${kernel}" "${kernel##${kernel_verrelarch}}"
|
2013-02-18 00:10:17 +04:00
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${devel}" ]; then
|
2013-07-27 15:42:57 +04:00
|
|
|
# create devel package including common headers
|
2022-01-13 21:09:19 +03:00
|
|
|
print_rpmtemplate_kmoddevelpkg "${kernel}" "${kernel##${kernel_verrelarch}}"
|
2013-07-27 15:42:57 +04:00
|
|
|
|
|
|
|
# create devel package
|
2022-01-13 21:09:19 +03:00
|
|
|
print_rpmtemplate_per_kmoddevelpkg "${kernel}" "${kernel##${kernel_verrelarch}}"
|
2013-02-18 00:10:17 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
myprog_help ()
|
|
|
|
{
|
2021-11-11 23:27:37 +03:00
|
|
|
echo "Usage: ${0##*/} [OPTIONS]"
|
2022-01-13 21:09:19 +03:00
|
|
|
echo
|
|
|
|
echo "Creates a template to be used during kmod building"
|
|
|
|
echo
|
|
|
|
echo "Available options:"
|
2013-02-18 00:10:17 +04:00
|
|
|
echo " --filterfile <file> -- filter the results with grep --file <file>"
|
|
|
|
echo " --for-kernels <list> -- created templates only for these kernels"
|
|
|
|
echo " --kmodname <file> -- name of the kmod (required)"
|
|
|
|
echo " --devel -- make kmod-devel package"
|
|
|
|
echo " --noakmod -- no akmod package"
|
|
|
|
echo " --repo <name> -- use buildsys-build-<name>-kerneldevpkgs"
|
|
|
|
echo " --target <arch> -- target-arch (required)"
|
2013-04-19 00:57:29 +04:00
|
|
|
echo " --buildroot <dir> -- Build root (place to look for build files)"
|
2013-02-18 00:10:17 +04:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
while [ -n "${1}" ] ; do
|
2013-02-18 00:10:17 +04:00
|
|
|
case "${1}" in
|
|
|
|
--filterfile)
|
|
|
|
shift
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${1}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "Please provide path to a filter-file together with --filterfile" >&2
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ ! -e "${1}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "Filterfile ${1} not found" >&2
|
|
|
|
fi
|
|
|
|
filterfile="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--kmodname)
|
|
|
|
shift
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${1}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "Please provide the name of the kmod together with --kmodname" >&2
|
|
|
|
fi
|
|
|
|
# strip pending -kmod
|
|
|
|
kmodname="${1%%-kmod}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--devel)
|
|
|
|
shift
|
|
|
|
devel="true"
|
|
|
|
;;
|
|
|
|
--prefix)
|
|
|
|
shift
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${1}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "Please provide a prefix with --prefix" >&2
|
|
|
|
fi
|
|
|
|
prefix="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--repo)
|
|
|
|
shift
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${1}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "Please provide the name of the repo together with --repo" >&2
|
|
|
|
fi
|
|
|
|
repo=${1}
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--for-kernels)
|
|
|
|
shift
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${1}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "Please provide the name of the kmod together with --kmodname" >&2
|
|
|
|
fi
|
|
|
|
for_kernels="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--noakmod)
|
|
|
|
shift
|
|
|
|
noakmod="true"
|
|
|
|
;;
|
|
|
|
--obsolete-name)
|
|
|
|
shift
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${1}" ] ; then
|
2019-09-03 04:17:39 +03:00
|
|
|
error_out 2 "Please provide the name of the kmod to obsolete together with --obsolete-name" >&2
|
2013-02-18 00:10:17 +04:00
|
|
|
fi
|
|
|
|
obsolete_name="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--obsolete-version)
|
|
|
|
shift
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${1}" ] ; then
|
2019-09-03 04:17:39 +03:00
|
|
|
error_out 2 "Please provide the version of the kmod to obsolete together with --obsolete-version" >&2
|
2013-02-18 00:10:17 +04:00
|
|
|
fi
|
|
|
|
obsolete_version="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--target)
|
|
|
|
shift
|
|
|
|
target="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--akmod)
|
|
|
|
shift
|
|
|
|
build_kernels="akmod"
|
|
|
|
;;
|
|
|
|
--newest)
|
|
|
|
shift
|
|
|
|
build_kernels="newest"
|
|
|
|
;;
|
|
|
|
--current)
|
|
|
|
shift
|
|
|
|
build_kernels="current"
|
|
|
|
;;
|
2013-04-19 00:57:29 +04:00
|
|
|
--buildroot)
|
|
|
|
shift
|
|
|
|
buildroot="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
2013-02-18 00:10:17 +04:00
|
|
|
--help)
|
|
|
|
myprog_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--version)
|
|
|
|
echo "${myprog} ${myver}"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Error: Unknown option '${1}'." >&2
|
|
|
|
usage >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -e ./kmodtool-kernel-variants ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
kernels_known_variants="$(cat ./kmodtool-kernel-variants)"
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ -e /usr/share/kmodtool/kernel-variants ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
kernels_known_variants="$(cat /usr/share/kmodtool/kernel-variants)"
|
|
|
|
else
|
|
|
|
kernels_known_variants="@(smp?(-debug)|PAE?(-debug)|debug|kdump|xen|kirkwood|highbank|imx|omap|tegra)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# general sanity checks
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${target}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "please pass target arch with --target"
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ -z "${kmodname}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "please pass kmodname with --kmodname"
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ -z "${kernels_known_variants}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "could not determine known variants"
|
2022-01-13 21:09:19 +03:00
|
|
|
elif { [ -n "${obsolete_name}" ] && [ -z "${obsolete_version}" ]; } || { [ -z "${obsolete_name}" ] && [ -n "${obsolete_version}" ]; } ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "you need to provide both --obsolete-name and --obsolete-version"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# go
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${for_kernels}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
# this is easy:
|
|
|
|
print_customrpmtemplate "${for_kernels}"
|
2022-01-13 21:09:19 +03:00
|
|
|
elif [ "${build_kernels}" = "akmod" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
# do only a akmod package
|
|
|
|
print_akmodtemplate
|
|
|
|
print_akmodmeta
|
|
|
|
else
|
|
|
|
# seems we are on out own to decide for which kernels to build
|
|
|
|
|
|
|
|
# we need more sanity checks in this case
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -z "${repo}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "please provide repo name with --repo"
|
2022-01-13 21:09:19 +03:00
|
|
|
elif ! command -v "buildsys-build-${repo}-kerneldevpkgs" > /dev/null 2>&1; then
|
2013-02-18 00:10:17 +04:00
|
|
|
error_out 2 "buildsys-build-${repo}-kerneldevpkgs not found"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# call buildsys-build-${repo}-kerneldevpkgs to get the list of kernels
|
|
|
|
cmdoptions="--target ${target}"
|
|
|
|
|
|
|
|
# filterfile to filter list of kernels?
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ -n "${filterfile}" ] ; then
|
2013-02-18 00:10:17 +04:00
|
|
|
cmdoptions="${cmdoptions} --filterfile ${filterfile}"
|
|
|
|
fi
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
kernel_versions_to_build_for=$(buildsys-build-${repo}-kerneldevpkgs "--${build_kernels}" ${cmdoptions})
|
2013-02-18 00:10:17 +04:00
|
|
|
returncode=$?
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ "$returncode" -ne 0 ]; then
|
|
|
|
|
|
|
|
error_out 2 "buildsys-build-${repo}-kerneldevpkgs failed: ${kernel_versions_to_build_for}"
|
2013-02-18 00:10:17 +04:00
|
|
|
fi
|
|
|
|
|
2022-01-13 21:09:19 +03:00
|
|
|
if [ "${build_kernels}" = "current" ] && [ -z "${noakmod}" ]; then
|
2013-02-18 00:10:17 +04:00
|
|
|
print_akmodtemplate
|
|
|
|
fi
|
|
|
|
|
|
|
|
print_rpmtemplate
|
|
|
|
fi
|