From a92fd87ba2ee261a0b4b25fbf9ed65f630b9ec3b Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Wed, 20 Apr 2022 01:10:21 -0400 Subject: [PATCH] testing --- Vagrantfile | 9 ++++++- build.sh | 52 +++++++++++++++++++++++++++++++++------- src/RHEL/helloworld.spec | 0 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 src/RHEL/helloworld.spec diff --git a/Vagrantfile b/Vagrantfile index 40ebe0f..bbcea1a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,5 +1,12 @@ +VAGRANT_BOX=ENV["VAGRANT_BOX"] +if !VAGRANT_BOX || VAGRANT_BOX == "debian" + VAGRANT_BOX = "debian/bullseye64" +elsif VAGRANT_BOX == "rocky" + VAGRANT_BOX = "rockylinux/8" +end + Vagrant.configure("2") do |config| - config.vm.box = "debian/bullseye64" + config.vm.box = VAGRANT_BOX config.vm.synced_folder ".", "/vagrant" config.vm.network "private_network", type: "dhcp" config.vm.provision "shell", path: "build.sh" diff --git a/build.sh b/build.sh index ce6a2b4..5edbb24 100755 --- a/build.sh +++ b/build.sh @@ -11,9 +11,20 @@ TEMPDIR="$(mktemp -d)" INSTALL=0 BUILDDIR="$TEMPDIR/${PACKAGE}_$VERSION-$REVISION" +# Test for distribution of GNU/Linux +# 0 = unknown +# 1 = debian +# 2 = rocky/centos/rhel +function check_distro { + if [ -f /etc/debian_version ]; then echo 1 + elif [ -f /etc/rocky-release ] || [ -f /etc/centos-release ]; then echo 2 + else echo 0 + fi +} + # Build debian package function build_deb { - [ $INSTALL -eq 1 ] && install_headers + [ $INSTALL -eq 1 ] && debian_headers mkdir -p "$BUILDDIR/usr/src/${PACKAGE}-$VERSION" mkdir -p "$BUILDDIR/etc" mkdir -p "$BUILDDIR/DEBIAN" @@ -24,6 +35,11 @@ function build_deb { dpkg-deb --build "${PACKAGE}_$VERSION-$REVISION" } +# Build redhat package +function build_rpm { + [ $INSTALL -eq 1 ] && rhel_headers +} + # Display details on module function info_mod { modinfo "$PACKAGE" @@ -33,22 +49,36 @@ function info_mod { cat /var/log/messages | grep "$PACKAGE" } -# Install Linux headers for current kernel -function install_headers { +# 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 and install helloworld module or module(s) in $SCRATCH +# 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)" +if [ $DISTRO -eq 0 ]; then + echo "ERROR: GNU/Linux distribution not detected" + exit -1 +fi + +# Build and install helloworld module or module(s) in $SCRATCH if [ ! -z "$(ls -Al $SCRATCH | grep -e ^d)" ]; then cd "$SCRATCH" for d in */ ; do if [ -f "$(basename $d)/override.sh" ]; then SRCDIR="$(pwd)/$(basename $d)" . "$(basename $d)/override.sh" - build_deb + [ $DISTRO -eq 1 ] && build_deb + [ $DISTRO -eq 2 ] && build_rpm if [ $INSTALL -eq 1 ]; then apt-get install -y "./${PACKAGE}_$VERSION-$REVISION.deb" info_mod @@ -59,7 +89,13 @@ if [ ! -z "$(ls -Al $SCRATCH | grep -e ^d)" ]; then done else INSTALL=1 - build_deb - apt-get install -y "./${PACKAGE}_$VERSION-$REVISION.deb" - info_mod + if [ $DISTRO -eq 1 ]; then + 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 diff --git a/src/RHEL/helloworld.spec b/src/RHEL/helloworld.spec new file mode 100644 index 0000000..e69de29