Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'dev/build-lynis.sh')
-rwxr-xr-xdev/build-lynis.sh169
1 files changed, 149 insertions, 20 deletions
diff --git a/dev/build-lynis.sh b/dev/build-lynis.sh
index 12e63939..d18baeb9 100755
--- a/dev/build-lynis.sh
+++ b/dev/build-lynis.sh
@@ -14,9 +14,8 @@
#
# Options:
-echo "[*] Activity [V] Succesful [X] Error [=] Result"
-echo ""
-
+ echo "[*] Activity [V] Succesful [X] Error [=] Result"
+ echo ""
# Umask used when creating files/directories
OPTION_UMASK="027"
@@ -27,10 +26,12 @@ echo ""
# Binary to test
OPTION_BINARY_FILE="../lynis"
+ # Check number of parameters
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)
@@ -56,7 +57,7 @@ echo ""
# Clean temporary files up
CleanUp()
{
- if [ ! ${TMPDIR} = "" -a -d ${TMPDIR} ]; then
+ if [ ! "${TMPDIR}" = "" -a -d "${TMPDIR}" ]; then
rm -rf ${TMPDIR}
fi
}
@@ -81,34 +82,127 @@ echo ""
#
#########################################################################
#
+ MYUSER=`whoami`
+ if [ "${MYUSER}" = "" ]; then
+ echo "[X] Could not determine user"
+ fi
+ if [ "${MYUSER}" = "root" ]; then
+ echo "[X] This script should not be executed as root"
+ fi
+
+
+ MYWORKDIR=`pwd | awk -F / '{ for (i=1;i<=NF-2;i++){ printf $i"/" }; printf "\n"}' | sed 's./$..'`
+ if [ ! -d ${MYWORKDIR} ]; then
+ echo "[X] Could not determine workdir (result: ${MYWORKDIR} seems invalid)"
+ ExitFatal
+ else
+ echo "[=] workdir: ${MYWORKDIR}"
+ fi
+
+
+ MYBUILDDIR="/home/${MYUSER}/lynis-build"
+ if [ ! -d ${MYBUILDDIR} ]; then
+ echo "[X] ${MYBUILDDIR} not found"
+ echo " Hint: create it with mkdir ${MYBUILDDIR}"
+ ExitFatal
+ else
+ echo "[=] builddir: ${MYBUILDDIR}"
+ fi
-# Set umask
- echo -n "- Setting umask to ${OPTION_UMASK} "
+ NEEDED_DIRS="debbuild rpmbuild rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SOURCES rpmbuild/SRPMS"
+ for I in ${NEEDED_DIRS}; do
+ if [ ! -d "${MYBUILDDIR}/${I}" ]; then
+ echo "[X] Missing directory: ${MYBUILDDIR}/${I}"
+ echo " Hint: create subdirs with cd ${MYBUILDDIR} && mkdir -p ${NEEDED_DIRS}"
+ ExitFatal
+ fi
+ done
+
+ DEBWORKDIR="${MYBUILDDIR}/debbuild"
+ RPMWORKDIR="${MYBUILDDIR}/rpmbuild"
+ echo "[=] RPM workdir: ${RPMWORKDIR}"
+ #echo "Use: cd ${MYBUILDDIR} && mkdir rpm"
+
+
+ # Check binaries
+
+ BZRBINARY=`which bzr`
+ if [ ! "${BZRBINARY}" = "" ]; then
+ echo "[=] bzr = ${BZRBINARY}"
+ else
+ echo "[X] Can not find bzr binary"
+ echo " Hint: install bzr"
+ ExitFatal
+ fi
+
+ RPMBUILDBINARY=`which rpmbuild`
+ if [ ! "${RPMBUILDBINARY}" = "" ]; then
+ echo "[=] rpmbuild = ${RPMBUILDBINARY}"
+ else
+ echo "[X] Can not find rpmbuild binary"
+ echo " Hint: install rpmbuild"
+ ExitFatal
+ fi
+
+
+ # Set umask
umask ${OPTION_UMASK}
if [ $? -eq 0 ]; then
- echo "OK"
+ echo "[V] Setting umask to ${OPTION_UMASK}"
else
- echo "BAD"
- exit 1
+ echo "[X] Could not set umask"
+ ExitFatal
fi
+ # Check if we are in dev directory
+ if [ -f ../lynis -a -f ./build-lynis.sh ]; then
+ echo "[V] Active in proper directory"
+ else
+ echo "[X] This script should be executed from dev directory itself"
+ ExitFatal
+ fi
+
+
+
+
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Build root
- echo -n "- Creating BUILDROOT "
+ # Create temporary build directory
TMPDIR=`mktemp -d /tmp/lynis-BUILDROOT.XXXXXX`
if [ $? -eq 0 ]; then
- echo "OK"
- echo " BUILDROOT: ${TMPDIR}"
+ echo "[V] Creating temporary build directory"
+ #echo " BUILDROOT: ${TMPDIR}"
else
- echo "BAD"
- exit 1
+ echo "[X] Could not create temporary build directory"
+ ExitFatal
fi
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ echo "[*] Starting with building tarball"
+
+ TARBALL="${MYBUILDDIR}/lynis_${LYNIS_VERSION}.orig.tar.gz"
+ #if [ -f ${TARBALL} ]; then
+ # echo "[X] Tarball already exists "
+ # echo " Hint: remove ${TARBALL}"
+ # ExitFatal
+ #fi
+
+ # Create tarball
+ tar -C ${MYWORKDIR} --exclude=.bzr* --exclude=.git* -c -z -f ${TARBALL} lynis 2> /dev/null
+
+ if [ -f ${TARBALL} ]; then
+ echo "[V] Tarball created"
+ else
+ echo "[X] Tarball ${TARBALL} could not be created"
+ ExitFatal
+ fi
+
+
+ echo "[*] Starting with RPM building process"
+
# RPM creation
- SOURCEFILE_RPM="/root/rpmbuild/SOURCES/lynis-${LYNIS_VERSION}.tar.gz"
+ SOURCEFILE_RPM="${RPMWORKDIR}/SOURCES/lynis-${LYNIS_VERSION}.tar.gz"
if [ -f ${SOURCEFILE_RPM} ]; then
if [ -f lynis.spec ]; then
# adjust version in spec file
@@ -119,26 +213,61 @@ echo ""
ExitFatal
fi
echo "[*] Start RPM building"
- rpmbuild --quiet -ba lynis.spec 2> /dev/null
+ #${RPMBUILDBINARY} --quiet -ba -bl 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"
+ RPMFILE="${RPMWORKDIR}/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})"
+ echo "[X] Could not find source file (${SOURCEFILE_RPM})"
+ echo " Hint: cp <lynis.tar.gz> ${SOURCEFILE_RPM}"
ExitFatal
fi
+ echo "[*] Starting with DEB building process"
+
+ BZRSTATUS=`${BZRBINARY} status . 2>&1 > /dev/null; echo $?`
+ if [ "${BZRSTATUS}" = "0" ]; then
+ echo "[V] bzr has proper directory tree"
+ DEBCHANGELOGFULLVERSION=`head -1 debian/changelog | awk '{ print $2 }' | sed 's/(//' | sed 's/)//'`
+ DEBCHANGELOGVERSION=`echo ${DEBCHANGELOGFULLVERSION} | awk -F- '{ print $1 }'`
+ DEBCHANGELOGVERSIONREV=`echo ${DEBCHANGELOGFULLVERSION} | awk -F- '{ print $2 }'`
+ echo "[=] Version in Debian changelog: ${DEBCHANGELOGVERSION} (revision: ${DEBCHANGELOGVERSIONREV})"
+ if [ "${LYNIS_VERSION}" = "${DEBCHANGELOGVERSION}" ]; then
+ echo "[V] Debian/changelog up-to-date"
+ else
+ echo "[X] Debian/changelog outdated"
+ ExitFatal
+ fi
+ # execute command
+ # bzr builddeb . --build-dir ${DEBWORKDIR}/build-area/ --result-dir ${DEBWORKDIR}
+ elif [ "${BZRSTATUS}" = "3" ]; then
+ echo "[X] Tree is not initialized for BZR"
+ echo " Hint: run bzr init while being in lynis directory (or bzr init ..)"
+ ExitFatal
+ else
+ echo "[X] Unknown error"
+ echo "Output: ${BZRSTATUS}"
+ fi
+
+
+ echo "[V] Done"
+ echo ""
+ echo "---------------------------------------------"
+ echo "Tarball: ${TARBALL}"
+ echo "RPM file: ${RPMFILE}"
+ echo ""
+
+
#=====================================================================