2021-11-10 06:14:16 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-03-18 06:43:41 +00:00
|
|
|
# Initial variables
|
2022-02-01 04:04:50 +00:00
|
|
|
PACKAGE="helloworld"
|
2022-01-14 06:54:13 +00:00
|
|
|
VERSION="0.1"
|
2022-02-01 04:04:50 +00:00
|
|
|
REVISION="1"
|
2022-03-18 06:43:41 +00:00
|
|
|
SRCDIR="/vagrant/src"
|
|
|
|
SCRATCH="/vagrant/scratch"
|
|
|
|
OUTDIR="$SCRATCH"
|
|
|
|
TEMPDIR="$(mktemp -d)"
|
|
|
|
INSTALL=0
|
|
|
|
BUILDDIR="$TEMPDIR/${PACKAGE}_$VERSION-$REVISION"
|
2022-01-14 06:54:13 +00:00
|
|
|
|
2022-04-20 05:10:21 +00:00
|
|
|
# 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
|
2022-04-21 05:23:57 +00:00
|
|
|
elif [ -f /etc/redhat-release ]; then echo 2
|
2022-04-20 05:10:21 +00:00
|
|
|
else echo 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-03-18 06:43:41 +00:00
|
|
|
# Build debian package
|
|
|
|
function build_deb {
|
2022-04-20 05:10:21 +00:00
|
|
|
[ $INSTALL -eq 1 ] && debian_headers
|
2022-03-18 06:43:41 +00:00
|
|
|
mkdir -p "$BUILDDIR/usr/src/${PACKAGE}-$VERSION"
|
|
|
|
mkdir -p "$BUILDDIR/etc"
|
|
|
|
mkdir -p "$BUILDDIR/DEBIAN"
|
|
|
|
cp -r $SRCDIR/usr/src/* "$BUILDDIR/usr/src/${PACKAGE}-$VERSION"
|
|
|
|
cp -r $SRCDIR/etc/* "$BUILDDIR/etc"
|
|
|
|
cp -r $SRCDIR/DEBIAN/* "$BUILDDIR/DEBIAN"
|
|
|
|
cd "$TEMPDIR"
|
|
|
|
dpkg-deb --build "${PACKAGE}_$VERSION-$REVISION"
|
|
|
|
}
|
2022-02-01 04:04:50 +00:00
|
|
|
|
2022-04-20 05:10:21 +00:00
|
|
|
# Build redhat package
|
|
|
|
function build_rpm {
|
2022-04-21 05:23:57 +00:00
|
|
|
EL_VER="$(uname -r | awk 'match($0,/el[0-9]/) {print substr($0, RSTART, RLENGTH)}')"
|
2022-04-20 05:10:21 +00:00
|
|
|
[ $INSTALL -eq 1 ] && rhel_headers
|
2022-04-21 05:23:57 +00:00
|
|
|
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
|
2022-04-20 05:10:21 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 06:43:41 +00:00
|
|
|
# Display details on module
|
|
|
|
function info_mod {
|
|
|
|
modinfo "$PACKAGE"
|
|
|
|
cat /proc/modules | grep "$PACKAGE"
|
|
|
|
rmmod "$PACKAGE"
|
|
|
|
modprobe "$PACKAGE"
|
|
|
|
cat /var/log/messages | grep "$PACKAGE"
|
|
|
|
}
|
2022-01-14 06:54:13 +00:00
|
|
|
|
2022-04-20 05:10:21 +00:00
|
|
|
# Install Linux headers for current debian kernel
|
|
|
|
function debian_headers {
|
2022-03-18 06:43:41 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
apt-get update
|
|
|
|
apt-get install -y linux-headers-$(uname -r)
|
|
|
|
}
|
|
|
|
|
2022-04-20 05:10:21 +00:00
|
|
|
# Install Linux headers for current rhel kernel
|
|
|
|
function rhel_headers {
|
2022-04-21 05:23:57 +00:00
|
|
|
KERNEL_VERSION="$(uname -r | rev | cut -d '.' -f 2- | rev)"
|
|
|
|
yum install -y kernel-headers-"$KERNEL_VERSION" kernel-devel
|
2022-04-20 05:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Find GNU/Linux distribution
|
2022-03-18 06:43:41 +00:00
|
|
|
set -x
|
2022-04-20 05:10:21 +00:00
|
|
|
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
|
2022-03-18 07:13:42 +00:00
|
|
|
if [ ! -z "$(ls -Al $SCRATCH | grep -e ^d)" ]; then
|
2022-03-18 06:43:41 +00:00
|
|
|
cd "$SCRATCH"
|
|
|
|
for d in */ ; do
|
|
|
|
if [ -f "$(basename $d)/override.sh" ]; then
|
|
|
|
SRCDIR="$(pwd)/$(basename $d)"
|
|
|
|
. "$(basename $d)/override.sh"
|
2022-04-20 05:10:21 +00:00
|
|
|
[ $DISTRO -eq 1 ] && build_deb
|
|
|
|
[ $DISTRO -eq 2 ] && build_rpm
|
2022-03-18 06:43:41 +00:00
|
|
|
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
|
|
|
|
done
|
|
|
|
else
|
|
|
|
INSTALL=1
|
2022-04-20 05:10:21 +00:00
|
|
|
if [ $DISTRO -eq 1 ]; then
|
|
|
|
build_deb
|
|
|
|
apt-get install -y "./${PACKAGE}_$VERSION-$REVISION.deb"
|
|
|
|
elif [ $DISTRO -eq 2 ]; then
|
|
|
|
build_rpm
|
2022-04-21 05:23:57 +00:00
|
|
|
yum install -y epel-release
|
|
|
|
yum install -y dkms
|
|
|
|
rpm -i "~/rpmbuild/RPMS/noarch/$PACKAGE-$VERSION-$REVISION.$EL_VER.noarch.rpm"
|
2022-04-20 05:10:21 +00:00
|
|
|
fi
|
2022-04-21 05:23:57 +00:00
|
|
|
info_mod
|
2022-03-18 06:43:41 +00:00
|
|
|
fi
|