ferdnyc / rpms / akmods

Forked from rpms/akmods 5 years ago
Clone
2117073
#!/bin/bash -
2117073
############################################################################
2117073
#
2117073
# akmods - Rebuilds and install akmod RPMs
2117073
# Copyright (c) 2007, 2008 Thorsten Leemhuis <fedora@leemhuis.info>
2117073
# Copyright (c) 2018 Nicolas Chauvet <kwizart@gmail.com>
2117073
#
2117073
# Permission is hereby granted, free of charge, to any person obtaining
2117073
# a copy of this software and associated documentation files (the
2117073
# "Software"), to deal in the Software without restriction, including
2117073
# without limitation the rights to use, copy, modify, merge, publish,
2117073
# distribute, sublicense, and/or sell copies of the Software, and to
2117073
# permit persons to whom the Software is furnished to do so, subject to
2117073
# the following conditions:
2117073
#
2117073
# The above copyright notice and this permission notice shall be
2117073
# included in all copies or substantial portions of the Software.
2117073
#
2117073
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2117073
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2117073
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2117073
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2117073
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2117073
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2117073
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2117073
#
2117073
############################################################################
2117073
2117073
myprog="akmods-post"
2117073
tmpdir=
2117073
2117073
# Only do %post builds in ostree
2117073
if ! grep -q OSTREE_VERSION= /etc/os-release && ! test -f /run/ostree-booted; then
2117073
	exit 0
2117073
fi
2117073
2117073
kmodname=$1
2117073
srpm=$2
2117073
2117073
2117073
finally()
2117073
{
2117073
	# remove tmpfiles
2117073
	remove_tmpdir
2117073
2117073
	exit ${1:-128}
2117073
}
2117073
2117073
# Make sure finally() is run regardless of reason for exiting.
2117073
trap "finally" ABRT HUP INT QUIT
2117073
2117073
create_tmpdir()
2117073
{
2117073
	if ! tmpdir="$(mktemp -d -p /tmp ${myprog}.XXXXXXXX)/" ; then
2117073
		echo "ERROR: failed to create tmpdir." >&2
2117073
		finally 1
2117073
	fi
2117073
	if ! mkdir "${tmpdir}"results ; then
2117073
		echo  "ERROR: failed to create result tmpdir." >&2
2117073
		finally 1
2117073
	fi
2117073
}
2117073
2117073
remove_tmpdir()
2117073
{
2117073
	# remove tmpfiles
2117073
	if [[ "${tmpdir}" ]] && [[ -d "${tmpdir}" ]]; then
2117073
		rm -rf "${tmpdir}"
2117073
	fi
2117073
}
2117073
2117073
# This is an ostree build, so do build for all
2117073
# deployed kernels in the %post
2117073
kernels="$(ls /lib/modules)"
2117073
2117073
create_tmpdir
2117073
2117073
for kernel in ${kernels} ; do
2117073
	echo "Building ${srpm} for kernel ${kernel}"
2117073
	# Note: This builds as root, but this is pretty safe because its happening in the ostree %post sandbox.
2117073
	#       In fact, given that /usr is a rofiles-fuse mount no other user can access /usr in this sandbox anyway.
2117073
	akmodsbuild --quiet --kernels ${kernel} --outputdir ${tmpdir}results --logfile "${tmpdir}/akmodsbuild.log" "${srpm}"  2>&1
2117073
	returncode=$?
2117073
	if (( ! ${returncode} == 0 )); then
2117073
		finally 1
2117073
	fi
2117073
done
2117073
2117073
for f in $(find "${tmpdir}results" -type f -name '*.rpm' | grep -v debuginfo) ; do
2117073
	rpm2cpio $f | cpio --quiet  -D / -id
2117073
	returncode=$?
2117073
	if (( ! ${returncode} == 0 )); then
2117073
		echo "Extracting $f failed:" 2>&1
2117073
		finally 1
2117073
	fi
2117073
done
2117073
2117073
for kernel in ${kernels} ; do
2117073
   depmod -v ${kernel} 2>&1
2117073
done
2117073
2117073
finally 0