mirror of
https://github.com/krislamo/kernmod.git
synced 2024-11-10 00:30:36 +00:00
Compare commits
2 Commits
a92fd87ba2
...
f1192da2cb
Author | SHA1 | Date | |
---|---|---|---|
f1192da2cb | |||
88e33a86bb |
2
Vagrantfile
vendored
2
Vagrantfile
vendored
@ -3,6 +3,8 @@ if !VAGRANT_BOX || VAGRANT_BOX == "debian"
|
|||||||
VAGRANT_BOX = "debian/bullseye64"
|
VAGRANT_BOX = "debian/bullseye64"
|
||||||
elsif VAGRANT_BOX == "rocky"
|
elsif VAGRANT_BOX == "rocky"
|
||||||
VAGRANT_BOX = "rockylinux/8"
|
VAGRANT_BOX = "rockylinux/8"
|
||||||
|
elsif VAGRANT_BOX == "centos"
|
||||||
|
VAGRANT_BOX = "centos/7"
|
||||||
end
|
end
|
||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
|
80
build.sh
80
build.sh
@ -17,11 +17,18 @@ BUILDDIR="$TEMPDIR/${PACKAGE}_$VERSION-$REVISION"
|
|||||||
# 2 = rocky/centos/rhel
|
# 2 = rocky/centos/rhel
|
||||||
function check_distro {
|
function check_distro {
|
||||||
if [ -f /etc/debian_version ]; then echo 1
|
if [ -f /etc/debian_version ]; then echo 1
|
||||||
elif [ -f /etc/rocky-release ] || [ -f /etc/centos-release ]; then echo 2
|
elif [ -f /etc/redhat-release ]; then echo 2
|
||||||
else echo 0
|
else echo 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Install Linux headers for current debian kernel
|
||||||
|
function debian_headers {
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y linux-headers-$(uname -r)
|
||||||
|
}
|
||||||
|
|
||||||
# Build debian package
|
# Build debian package
|
||||||
function build_deb {
|
function build_deb {
|
||||||
[ $INSTALL -eq 1 ] && debian_headers
|
[ $INSTALL -eq 1 ] && debian_headers
|
||||||
@ -35,9 +42,26 @@ function build_deb {
|
|||||||
dpkg-deb --build "${PACKAGE}_$VERSION-$REVISION"
|
dpkg-deb --build "${PACKAGE}_$VERSION-$REVISION"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Install Linux headers for current rhel kernel
|
||||||
|
function rhel_headers {
|
||||||
|
KERNEL_VERSION="$(uname -r | rev | cut -d '.' -f 2- | rev)"
|
||||||
|
yum install -y kernel-headers-"$KERNEL_VERSION" kernel-devel
|
||||||
|
}
|
||||||
|
|
||||||
# Build redhat package
|
# Build redhat package
|
||||||
function build_rpm {
|
function build_rpm {
|
||||||
|
EL_VER="$(uname -r | awk 'match($0,/el[0-9]/) {print substr($0, RSTART, RLENGTH)}')"
|
||||||
[ $INSTALL -eq 1 ] && rhel_headers
|
[ $INSTALL -eq 1 ] && rhel_headers
|
||||||
|
yum install -y rpm-build rpmdevtools rpmlint
|
||||||
|
rpmdev-setuptree
|
||||||
|
mkdir -p "$BUILDDIR/${PACKAGE}-${VERSION}"
|
||||||
|
cp -r $SRCDIR/* "$BUILDDIR/${PACKAGE}-${VERSION}"
|
||||||
|
rm -rf ~/rpmbuild/SOURCES/$PACKAGE-$VERSION.tar.gz
|
||||||
|
(cd $BUILDDIR &&
|
||||||
|
tar -czvf ~/rpmbuild/SOURCES/$PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION)
|
||||||
|
cp $SRCDIR/$PACKAGE.spec ~/rpmbuild/SPECS/
|
||||||
|
rpmlint ~/rpmbuild/SPECS/$PACKAGE.spec &&
|
||||||
|
rpmbuild -bb ~/rpmbuild/SPECS/$PACKAGE.spec
|
||||||
}
|
}
|
||||||
|
|
||||||
# Display details on module
|
# Display details on module
|
||||||
@ -49,53 +73,45 @@ function info_mod {
|
|||||||
cat /var/log/messages | grep "$PACKAGE"
|
cat /var/log/messages | grep "$PACKAGE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install Linux headers for current debian kernel
|
# Build and install (optional)
|
||||||
function debian_headers {
|
function build_install {
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y linux-headers-$(uname -r)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install Linux headers for current rhel kernel
|
|
||||||
function rhel_headers {
|
|
||||||
VERSION="$(uname -r | rev | cut -d '.' -f 2- | rev)"
|
|
||||||
yum install -y kernel-headers-"$VERSION"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find GNU/Linux distribution
|
|
||||||
set -x
|
|
||||||
DISTRO="$(check_distro)"
|
DISTRO="$(check_distro)"
|
||||||
if [ $DISTRO -eq 0 ]; then
|
if [ $DISTRO -eq 0 ]; then
|
||||||
echo "ERROR: GNU/Linux distribution not detected"
|
echo "ERROR: GNU/Linux distribution not detected"
|
||||||
exit -1
|
exit -1
|
||||||
|
elif [ $DISTRO -eq 1 ]; then
|
||||||
|
build_deb
|
||||||
|
[ $INSTALL -eq 1 ] && apt-get install -y "./${PACKAGE}_$VERSION-$REVISION.deb"
|
||||||
|
elif [ $DISTRO -eq 2 ]; then
|
||||||
|
build_rpm
|
||||||
|
if [ $INSTALL -eq 1 ]; then
|
||||||
|
yum install -y epel-release
|
||||||
|
yum install -y dkms
|
||||||
|
rpm -i "~/rpmbuild/RPMS/noarch/$PACKAGE-$VERSION-$REVISION.$EL_VER.noarch.rpm"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
info_mod
|
||||||
|
}
|
||||||
|
|
||||||
# Build and install helloworld module or module(s) in $SCRATCH
|
# Build and install helloworld module or module(s) in $SCRATCH
|
||||||
|
function main_routine {
|
||||||
if [ ! -z "$(ls -Al $SCRATCH | grep -e ^d)" ]; then
|
if [ ! -z "$(ls -Al $SCRATCH | grep -e ^d)" ]; then
|
||||||
cd "$SCRATCH"
|
cd "$SCRATCH"
|
||||||
for d in */ ; do
|
for d in */ ; do
|
||||||
if [ -f "$(basename $d)/override.sh" ]; then
|
if [ -f "$(basename $d)/override.sh" ]; then
|
||||||
SRCDIR="$(pwd)/$(basename $d)"
|
SRCDIR="$(pwd)/$(basename $d)"
|
||||||
. "$(basename $d)/override.sh"
|
. "$(basename $d)/override.sh"
|
||||||
[ $DISTRO -eq 1 ] && build_deb
|
build_install
|
||||||
[ $DISTRO -eq 2 ] && build_rpm
|
|
||||||
if [ $INSTALL -eq 1 ]; then
|
|
||||||
apt-get install -y "./${PACKAGE}_$VERSION-$REVISION.deb"
|
|
||||||
info_mod
|
|
||||||
fi
|
|
||||||
cp "./${PACKAGE}_$VERSION-$REVISION.deb" \
|
|
||||||
"$OUTDIR/${PACKAGE}_$VERSION-$REVISION-$(date +%s).deb"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
INSTALL=1
|
INSTALL=1
|
||||||
if [ $DISTRO -eq 1 ]; then
|
build_install
|
||||||
build_deb
|
|
||||||
apt-get install -y "./${PACKAGE}_$VERSION-$REVISION.deb"
|
|
||||||
elif [ $DISTRO -eq 2 ]; then
|
|
||||||
build_rpm
|
|
||||||
echo "end of debug: exiting..."
|
|
||||||
exit 0
|
|
||||||
yum install -y "./${PACKAGE}_$VERSION-$REVISION.rpm"
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Program starts here unless KERNMOD_MAIN is not 0
|
||||||
|
if [ "${KERNMOD_MAIN:-0}" -eq 0 ]; then
|
||||||
|
set -x
|
||||||
|
main_routine
|
||||||
fi
|
fi
|
||||||
|
37
src/helloworld.spec
Normal file
37
src/helloworld.spec
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
Name: helloworld
|
||||||
|
Version: 0.1
|
||||||
|
Release: 1%{?dist}
|
||||||
|
Summary: hello, world
|
||||||
|
BuildArch: noarch
|
||||||
|
|
||||||
|
License: 0BSD
|
||||||
|
Source0: %{name}-%{version}.tar.gz
|
||||||
|
Requires: dkms
|
||||||
|
|
||||||
|
%description
|
||||||
|
hello, world example
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q
|
||||||
|
%build
|
||||||
|
%install
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
mkdir -p $RPM_BUILD_ROOT/%{_usrsrc}/%{name}-%{version}
|
||||||
|
mkdir -p $RPM_BUILD_ROOT/etc
|
||||||
|
cp -r usr/src/* $RPM_BUILD_ROOT/%{_usrsrc}/%{name}-%{version}
|
||||||
|
cp -r etc/* $RPM_BUILD_ROOT/etc
|
||||||
|
|
||||||
|
%clean
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
|
%files
|
||||||
|
%{_usrsrc}/%{name}-%{version}/dkms.conf
|
||||||
|
%{_usrsrc}/%{name}-%{version}/helloworld.c
|
||||||
|
%{_usrsrc}/%{name}-%{version}/Makefile
|
||||||
|
/etc/modules-load.d/%{name}.conf
|
||||||
|
|
||||||
|
%post
|
||||||
|
dkms add -m %{name} -v %{version}
|
||||||
|
dkms build -m %{name} -v %{version}
|
||||||
|
dkms install -m %{name} -v %{version}
|
||||||
|
modprobe %{name}
|
Loading…
Reference in New Issue
Block a user