Blame SOURCES/kmodtool

67e50c
#!/bin/bash
67e50c
67e50c
# kmodtool - Helper script for building kernel module RPMs
67e50c
# Copyright (c) 2003-2006 Ville Skyttä <ville.skytta@iki.fi>,
67e50c
#                         Thorsten Leemhuis <fedora@leemhuis.info>
67e50c
#                         Jon Masters <jcm@redhat.com>
67e50c
#
67e50c
# Permission is hereby granted, free of charge, to any person obtaining
67e50c
# a copy of this software and associated documentation files (the
67e50c
# "Software"), to deal in the Software without restriction, including
67e50c
# without limitation the rights to use, copy, modify, merge, publish,
67e50c
# distribute, sublicense, and/or sell copies of the Software, and to
67e50c
# permit persons to whom the Software is furnished to do so, subject to
67e50c
# the following conditions:
67e50c
#
67e50c
# The above copyright notice and this permission notice shall be
67e50c
# included in all copies or substantial portions of the Software.
67e50c
#
67e50c
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
67e50c
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67e50c
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
67e50c
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
67e50c
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
67e50c
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
67e50c
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67e50c
67e50c
shopt -s extglob
67e50c
67e50c
myprog="kmodtool"
67e50c
myver="0.10.10_kmp2"
67e50c
knownvariants=@(BOOT|PAE|@(big|huge)mem|debug|enterprise|kdump|?(large)smp|uml|xen[0U]?(-PAE)|xen)
67e50c
kmod_name=
67e50c
kver=
67e50c
verrel=
67e50c
variant=
67e50c
kmp=
67e50c
67e50c
get_verrel ()
67e50c
{
67e50c
  verrel=${1:-$(uname -r)}
67e50c
  verrel=${verrel%%$knownvariants}
67e50c
}
67e50c
67e50c
print_verrel ()
67e50c
{
67e50c
  get_verrel $@
67e50c
  echo "${verrel}"
67e50c
}
67e50c
67e50c
get_variant ()
67e50c
{
67e50c
  get_verrel $@
67e50c
  variant=${1:-$(uname -r)}
67e50c
  variant=${variant##$verrel}
67e50c
  variant=${variant:-'""'}
67e50c
}
67e50c
67e50c
print_variant ()
67e50c
{
67e50c
  get_variant $@
67e50c
  echo "${variant}"
67e50c
}
67e50c
67e50c
get_rpmtemplate ()
67e50c
{
67e50c
    local variant="${1}"
67e50c
    local dashvariant="${variant:+-${variant}}"
67e50c
    case "$verrel" in
67e50c
        *.el*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
67e50c
        *.EL*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
67e50c
        *)     kdep="kernel-%{_target_cpu} = ${verrel}${variant}"     ;;
67e50c
    esac
67e50c
67e50c
    echo "%package       -n kmod-${kmod_name}${dashvariant}"
67e50c
67e50c
    if [ -z "$kmp_provides_summary" ]; then
67e50c
        echo "Summary:          ${kmod_name} kernel module(s)"
67e50c
    fi
67e50c
67e50c
    if [ -z "$kmp_provides_group" ]; then
67e50c
        echo "Group:            System Environment/Kernel"
67e50c
    fi
67e50c
67e50c
    if [ ! -z "$kmp_version" ]; then
67e50c
        echo "Version: %{kmp_version}"
67e50c
    fi
67e50c
67e50c
    if [ ! -z "$kmp_release" ]; then
67e50c
        echo "Release: %{kmp_release}"
67e50c
    fi
67e50c
67e50c
    if [ ! -z "$kmp" ]; then
67e50c
        echo "%global _use_internal_dependency_generator 0"
67e50c
    fi
67e50c
67e50c
    cat <
67e50c
Provides:         kernel-modules = ${verrel}${variant}
67e50c
Provides:         ${kmod_name}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
67e50c
EOF
67e50c
67e50c
    if [ -z "$kmp" ]; then
67e50c
        echo "Requires:         ${kdep}"
67e50c
    fi
67e50c
67e50c
#
67e50c
# RHEL5 - Remove common package requirement on general kmod packages.
67e50c
# Requires: ${kmod_name}-kmod-common >= %{?epoch:%{epoch}:}%{version}
67e50c
#
67e50c
67e50c
    cat <
67e50c
Requires(post):   /sbin/depmod
67e50c
Requires(postun): /sbin/depmod
67e50c
EOF
67e50c
67e50c
if [ "no" != "$kmp_nobuildreqs" ]
67e50c
then
67e50c
    echo "BuildRequires: kernel${dashvariant}-devel-%{_target_cpu} = ${verrel}"
67e50c
fi
67e50c
67e50c
if [ "" != "$kmp_override_preamble" ]
67e50c
then
67e50c
    cat "$kmp_override_preamble"
67e50c
fi
67e50c
67e50c
cat <
67e50c
%description   -n kmod-${kmod_name}${dashvariant}
67e50c
This package provides the ${kmod_name} kernel modules built for the Linux
67e50c
kernel ${verrel}${variant} for the %{_target_cpu} family of processors.
67e50c
%post          -n kmod-${kmod_name}${dashvariant}
67e50c
if [ -e "/boot/System.map-${verrel}${variant}" ]; then
67e50c
    /sbin/depmod -aeF "/boot/System.map-${verrel}${variant}" "${verrel}${variant}" > /dev/null || :
67e50c
fi
67e50c
EOF
67e50c
67e50c
    if [ ! -z "$kmp" ]; then
67e50c
        cat <
67e50c
67e50c
modules=( \$(find /lib/modules/${verrel}${variant}/extra/${kmod_name}) )
67e50c
if [ -x "/sbin/weak-modules" ]; then
67e50c
    printf '%s\n' "\${modules[@]}" \
67e50c
    | /sbin/weak-modules --add-modules
67e50c
fi
67e50c
%preun         -n kmod-${kmod_name}${dashvariant}
67e50c
rpm -ql kmod-${kmod_name}${dashvariant} | grep '\.ko$' \
67e50c
    > /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
67e50c
EOF
67e50c
67e50c
    fi
67e50c
67e50c
    cat <
67e50c
%postun        -n kmod-${kmod_name}${dashvariant}
67e50c
/sbin/depmod -aF /boot/System.map-${verrel}${variant} ${verrel}${variant} &> /dev/null || :
67e50c
EOF
67e50c
67e50c
    if [ ! -z "$kmp" ]; then
67e50c
        cat <
67e50c
modules=( \$(cat /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules) )
67e50c
#rm /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
67e50c
if [ -x "/sbin/weak-modules" ]; then
67e50c
    printf '%s\n' "\${modules[@]}" \
67e50c
    | /sbin/weak-modules --remove-modules
67e50c
fi
67e50c
EOF
67e50c
    fi
67e50c
67e50c
echo "%files         -n kmod-${kmod_name}${dashvariant}"
67e50c
67e50c
if [ "" == "$kmp_override_filelist" ];
67e50c
then
67e50c
    echo "%defattr(644,root,root,755)"
67e50c
    echo "/lib/modules/${verrel}${variant}/"
67e50c
    echo "/lib/firmware/"
67e50c
else
67e50c
    cat "$kmp_override_filelist"
67e50c
fi
67e50c
}
67e50c
67e50c
print_rpmtemplate ()
67e50c
{
67e50c
  kmod_name="${1}"
67e50c
  shift
67e50c
  kver="${1}"
67e50c
  get_verrel "${1}"
67e50c
  shift
67e50c
  if [ -z "${kmod_name}" ] ; then
67e50c
    echo "Please provide the kmodule-name as first parameter." >&2
67e50c
    exit 2
67e50c
  elif [ -z "${kver}" ] ; then
67e50c
    echo "Please provide the kver as second parameter." >&2
67e50c
    exit 2
67e50c
  elif [ -z "${verrel}" ] ; then
67e50c
    echo "Couldn't find out the verrel." >&2
67e50c
    exit 2
67e50c
  fi
67e50c
67e50c
  for variant in "$@" ; do
67e50c
      if [ "default" == "$variant" ];
67e50c
      then
67e50c
            get_rpmtemplate ""
67e50c
      else
67e50c
            get_rpmtemplate "${variant}"
67e50c
      fi
67e50c
  done
67e50c
}
67e50c
67e50c
usage ()
67e50c
{
67e50c
  cat <
67e50c
You called: ${invocation}
67e50c
67e50c
Usage: ${myprog} <command> <option>+
67e50c
 Commands:
67e50c
  verrel <uname>
67e50c
    - Get "base" version-release.
67e50c
  variant <uname>
67e50c
    - Get variant from uname.
67e50c
  rpmtemplate <mainpgkname> <uname> <variants>
67e50c
    - Return a template for use in a source RPM
67e50c
  rpmtemplate_kmp <mainpgkname> <uname> <variants>
67e50c
    - Return a template for use in a source RPM with KMP dependencies
67e50c
  version
67e50c
    - Output version number and exit.
67e50c
EOF
67e50c
}
67e50c
67e50c
invocation="$(basename ${0}) $@"
67e50c
while [ "${1}" ] ; do
67e50c
  case "${1}" in
67e50c
    verrel)
67e50c
      shift
67e50c
      print_verrel $@
67e50c
      exit $?
67e50c
      ;;
67e50c
    variant)
67e50c
      shift
67e50c
      print_variant $@
67e50c
      exit $?
67e50c
      ;;
67e50c
    rpmtemplate)
67e50c
      shift
67e50c
      print_rpmtemplate "$@"
67e50c
      exit $?
67e50c
      ;;
67e50c
    rpmtemplate_kmp)
67e50c
      shift
67e50c
      kmp=1
67e50c
      print_rpmtemplate "$@"
67e50c
      exit $?
67e50c
      ;;
67e50c
    version)
67e50c
      echo "${myprog} ${myver}"
67e50c
      exit 0
67e50c
      ;;
67e50c
    *)
67e50c
      echo "Error: Unknown option '${1}'." >&2
67e50c
      usage >&2
67e50c
      exit 2
67e50c
      ;;
67e50c
  esac
67e50c
done
67e50c
67e50c
# Local variables:
67e50c
# mode: sh
67e50c
# sh-indentation: 2
67e50c
# indent-tabs-mode: nil
67e50c
# End:
67e50c
# ex: ts=2 sw=2 et