X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=scripts%2Fkmodtool;fp=scripts%2Fkmodtool;h=2170c4a908ae2b4b9d53a53cd07911c0371749b0;hb=f3757573a677e8662e268f0bb8e5ffe750013088;hp=0000000000000000000000000000000000000000;hpb=9b2af9a097c119b818bd584eb89ca51ba475c7f2;p=zfs.git diff --git a/scripts/kmodtool b/scripts/kmodtool new file mode 100755 index 0000000..2170c4a --- /dev/null +++ b/scripts/kmodtool @@ -0,0 +1,552 @@ +#!/bin/bash + +# kmodtool - Helper script for building kernel module RPMs +# Copyright (c) 2003-2012 Ville Skyttä , +# Thorsten Leemhuis +# Nicolas Chauvet +# +# 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= + +error_out() +{ + local errorlevel=${1} + shift + echo "Error: $@" >&2 + # the next line is not multi-line safe -- not needed *yet* + echo "%global kmodtool_check echo \"kmodtool error: $@\"; exit ${errorlevel};" + exit ${errorlevel} +} + +print_rpmtemplate_header() +{ + echo + echo '%global kmodinstdir_prefix '${prefix}/lib/modules/ + echo '%global kmodinstdir_postfix '/extra/${kmodname}/ + echo '%global kernel_versions '${kernel_versions} + echo +} + +print_akmodtemplate () +{ + echo + cat <= %{?epoch:%{epoch}:}%{version} +Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release} +EOF + + if [[ ${obsolete_name} ]]; then + echo "Provides: akmod-${obsolete_name} = ${obsolete_version}" + echo "Obsoletes: akmod-${obsolete_name} < ${obsolete_version}" + fi + + cat < /dev/null & + +%files -n akmod-${kmodname} +%defattr(-,root,root,-) +%{_usrsrc}/akmods/* + +EOF +} + +print_akmodmeta () +{ + cat <= %{?epoch:%{epoch}:}%{version} +Requires(post): ${prefix}/sbin/depmod +Requires(postun): ${prefix}/sbin/depmod +%{?KmodsRequires:Requires: %{KmodsRequires}-uname-r = ${kernel_uname_r}} +%{?KmodsBuildRequires:BuildRequires: %{KmodsBuildRequires}-uname-r = ${kernel_uname_r}} +%{?KmodsBuildRequires:BuildRequires: %{KmodsBuildRequires}} +EOF + + if [[ ${obsolete_name} ]]; then + echo "Provides: kmod-${obsolete_name}-${kernel_uname_r} = ${obsolete_version}" + echo "Obsoletes: kmod-${obsolete_name}-${kernel_uname_r} < ${obsolete_version}" + fi + + # second part + if [[ ! "${customkernel}" ]]; then + cat < /dev/null || : +%postun -n kmod-${kmodname}-${kernel_uname_r} +${prefix}/sbin/depmod -aF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} &> /dev/null || : + +EOF + else + cat < /dev/null || : +%postun -n kmod-${kmodname}-${kernel_uname_r} +[[ "$(uname -r)" == "${kernel_uname_r}" ]] && ${prefix}/sbin/depmod -a > /dev/null || : + +EOF + fi + + # third part + cat <= %{?epoch:%{epoch}:}%{version}-%{release} +EOF + + if [[ ${obsolete_name} ]]; then + echo "Provides: kmod-${obsolete_name}${kernel_variant} = ${obsolete_version}" + echo "Obsoletes: kmod-${obsolete_name}${kernel_variant} < ${obsolete_version}" + fi + + cat < -- look for our shared files in " + echo " --filterfile -- filter the results with grep --file " + echo " --for-kernels -- created templates only for these kernels" + echo " --kmodname -- name of the kmod (required)" + echo " --devel -- make kmod-devel package" + echo " --noakmod -- no akmod package" + echo " --repo -- use buildsys-build--kerneldevpkgs" + echo " --target -- target-arch (required)" +} + +while [ "${1}" ] ; do + case "${1}" in + --filterfile) + shift + if [[ ! "${1}" ]] ; then + error_out 2 "Please provide path to a filter-file together with --filterfile" >&2 + elif [[ ! -e "${1}" ]]; then + error_out 2 "Filterfile ${1} not found" >&2 + fi + filterfile="${1}" + shift + ;; + --kmodname) + shift + if [[ ! "${1}" ]] ; then + 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 + if [[ ! "${1}" ]] ; then + error_out 2 "Please provide a prefix with --prefix" >&2 + fi + prefix="${1}" + shift + ;; + --repo) + shift + if [[ ! "${1}" ]] ; then + error_out 2 "Please provide the name of the repo together with --repo" >&2 + fi + repo=${1} + shift + ;; + --for-kernels) + shift + if [[ ! "${1}" ]] ; then + 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 + if [[ ! "${1}" ]] ; then + error_out 2 "Please provide the name of the kmod to obsolte together with --obsolete-name" >&2 + fi + obsolete_name="${1}" + shift + ;; + --obsolete-version) + shift + if [[ ! "${1}" ]] ; then + error_out 2 "Please provide the version of the kmod to obsolte together with --obsolete-version" >&2 + 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" + ;; + --help) + myprog_help + exit 0 + ;; + --version) + echo "${myprog} ${myver}" + exit 0 + ;; + *) + echo "Error: Unknown option '${1}'." >&2 + usage >&2 + exit 2 + ;; + esac +done + +if [[ -e ./kmodtool-kernel-variants ]]; then + kernels_known_variants="$(cat ./kmodtool-kernel-variants)" +elif [[ -e /usr/share/kmodtool/kernel-variants ]] ; then + 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 +if [[ ! "${target}" ]]; then + error_out 2 "please pass target arch with --target" +elif [[ ! "${kmodname}" ]]; then + error_out 2 "please pass kmodname with --kmodname" +elif [[ ! "${kernels_known_variants}" ]] ; then + error_out 2 "could not determine known variants" +elif ( [[ "${obsolete_name}" ]] && [[ ! "${obsolete_version}" ]] ) || ( [[ ! "${obsolete_name}" ]] && [[ "${obsolete_version}" ]] ) ; then + error_out 2 "you need to provide both --obsolete-name and --obsolete-version" +fi + +# go +if [[ "${for_kernels}" ]]; then + # this is easy: + print_customrpmtemplate "${for_kernels}" +elif [[ "${build_kernels}" == "akmod" ]]; then + # 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 + if [[ ! "${repo}" ]]; then + error_out 2 "please provide repo name with --repo" + elif ! $(which buildsys-build-${repo}-kerneldevpkgs &> /dev/null) ; then + 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? + if [[ "${filterfile}" ]] ; then + cmdoptions="${cmdoptions} --filterfile ${filterfile}" + fi + + kernel_versions_to_build_for="$(buildsys-build-${repo}-kerneldevpkgs --${build_kernels} ${cmdoptions})" + returncode=$? + if (( ${returncode} != 0 )); then + error_out 2 "buildsys-build-${repo}-kerneldevpkgs failed: $(buildsys-build-${repo}-kerneldevpkgs --${build_kernels} ${cmdoptions})" + fi + + if [[ "${build_kernels}" == "current" ]] && [[ ! "${noakmod}" ]]; then + print_akmodtemplate + fi + + print_rpmtemplate +fi