Added RPM creation to script

This commit is contained in:
mboelen 2014-09-14 16:40:18 +02:00
parent d095458a11
commit 67dce7ad34
1 changed files with 102 additions and 10 deletions

View File

@ -13,7 +13,11 @@
#########################################################################
#
# Options:
echo "[*] Activity [V] Succesful [X] Error [=] Result"
echo ""
# Umask used when creating files/directories
OPTION_UMASK="027"
@ -21,7 +25,28 @@
OPTION_PACKAGE_DIRNAME="lynis"
# Binary to test
OPTION_BINARY_FILE="../lynis"
OPTION_BINARY_FILE="../lynis"
if [ $# -eq 0 ]; then
echo "[X] This build tool needs at least a version number (--version). Use --help for all parameters."
exit 1
fi
# Check parameters
case $1 in
--help)
echo "Define version:"
echo "--version 1.2.3"
exit 1
;;
--version)
shift
LYNIS_VERSION=$1
;;
*)
echo "[X] Incorrect parameter"
exit 1
;;
esac
#
#########################################################################
@ -36,6 +61,16 @@
fi
}
Exit()
{
CleanUp
exit 0
}
ExitFatal()
{
CleanUp
exit 1
}
#
#########################################################################
#
@ -61,7 +96,7 @@
# Build root
echo -n "- Creating BUILDROOT "
TMPDIR=`mktemp -d /tmp/lynis-BUILDROOT.XXXX`
TMPDIR=`mktemp -d /tmp/lynis-BUILDROOT.XXXXXX`
if [ $? -eq 0 ]; then
echo "OK"
echo " BUILDROOT: ${TMPDIR}"
@ -70,11 +105,65 @@
exit 1
fi
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# RPM creation
SOURCEFILE_RPM="/root/rpmbuild/SOURCES/lynis-${LYNIS_VERSION}.tar.gz"
if [ -f ${SOURCEFILE_RPM} ]; then
if [ -f lynis.spec ]; then
# adjust version in spec file
VERSION_IN_SPECFILE=`cat lynis.spec | grep "^Version:" | sed 's/ //g' | awk -F: '{ print $2 }'`
echo "[=] Found version ${VERSION_IN_SPECFILE}"
if [ ${VERSION_IN_SPECFILE} = "" -o ! "${VERSION_IN_SPECFILE}" = "${LYNIS_VERSION}" ]; then
echo "[X] Version in specfile is outdated"
ExitFatal
fi
echo "[*] Start RPM building"
rpmbuild --quiet -ba lynis.spec 2> /dev/null
else
echo "[X] lynis.spec not found"
ExitFatal
fi
RPMFILE="/root/rpmbuild/RPMS/noarch/lynis-${LYNIS_VERSION}-1.noarch.rpm"
if [ -f ${RPMFILE} ]; then
echo "[V] Building RPM succesful!"
echo " File: ${RPMFILE}"
else
echo "[X] Could not find RPM file, most likely failed"
echo " Expected: ${RPMFILE}"
ExitFatal
fi
else
echo "[X] Could not find source file (${SOURCEFILE})"
ExitFatal
fi
#=====================================================================
# Stop the script at this stage, rest is under development
Exit
#=====================================================================
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Test script for errors
echo -n "- Test Lynis script "
# Is file there?
if [ ! -f ${OPTION_BINARY_FILE} ]; then echo "BAD (can't find ${OPTION_BINARY_FILE})"; exit 1; fi
@ -111,7 +200,7 @@
PACKAGE_LIST_FILES=`cat files.dat | grep "^file:" | cut -d ':' -f3`
for I in ${PACKAGE_LIST_FILES}; do
echo -n "${I} "
#FULLNAME=`cat files.dat | grep ":file:include:
#echo "${FULLNAME}" >> ${OPENBSD_CONTENTS}
@ -123,16 +212,19 @@
done
echo ""
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
echo -n "- Cleaning up... "
# Clean up our mess
CleanUp
echo "DONE"
# Exit cleanly
Exit
echo "DONE"
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# The End!