v5/Build.rhel
2020-05-16 19:40:06 -04:00

90 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Updated: 16 May 2020
# MailScanner Team <https://www.mailscanner.info>
#
# This helper script will build the latest RPM install
# make sure this is run from the base directory
if [ ! -d 'rhel' ]; then
echo 'This script must be executed from the base directory.';
echo './rhel was not found, Exiting ...';
echo;
exit 192
fi
if [ -z $(which rpmbuild) ]; then
echo 'Required rpmbuild package is missing';
echo 'install rpmbuild before continuing, Exiting ...';
echo;
exit 192
fi
VERSION=$(sed -e 's/\n//' VERSION)
MSVERSION=$(echo $VERSION | sed -e 's/-.*$//')
MSBUILD=$(echo $VERSION | sed -e 's/^.*-//')
if [[ -z $MSVERSION || -z $MSBUILD ]]; then
echo "Could not determine MailScanner version."
echo "Unable read VERSION file"
echo;
exit 192
fi
# directory we are in
THISCURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
if [ -z "$RPMOUT" ]; then
RPMOUT="$HOME/msbuilds";
fi
# setup rpm development dirs
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
# create build output base dir
mkdir -p $RPMOUT
# the work directory
WORK="/tmp/MailScanner-$MSVERSION";
# delete work tmp if already exists
if [ -d $WORK ]; then
rm -rf $WORK
fi
# make working dir and subs
mkdir -p $WORK
# copy everything
cp -fr $THISCURDIR/* $WORK/
# remove svn and git and mac stuff
find $WORK -name '.svn' -exec rm -rf {} \;
find $WORK -name '.git' -exec rm -rf {} \;
find $WORK -name '*.DS_Store' -exec rm -rf {} \;
find $WORK -depth -name '__MACOSX' -exec rm -rf {} \;
# Build the src tarball for RPM construction
cd $WORK
cd ..
tar czf ~/rpmbuild/SOURCES/MailScanner-${MSVERSION}.tar.gz MailScanner-${MSVERSION}
# return to where i started
cd $THISCURDIR
# Build the RPM and SRPMS
cp -f $THISCURDIR/rhel/mailscanner.spec ~/rpmbuild/SPECS/mailscanner.spec
perl -pi -e 's/__Version__/'$MSVERSION'/;' ~/rpmbuild/SPECS/mailscanner.spec
perl -pi -e 's/__Release__/'$MSBUILD'/;' ~/rpmbuild/SPECS/mailscanner.spec
rpmbuild -ba ~/rpmbuild/SPECS/mailscanner.spec
# Cleanup
mv ~/rpmbuild/RPMS/noarch/MailScanner-${VERSION}.rhel.noarch.rpm $RPMOUT
rm -rf $WORK
# Be mindful that rpmbuild may be present for other things...
rm -f ~/rpmbuild/SOURCES/MailScanner-${MSVERSION}.tar.gz
rm -f ~/rpmbuild/SPECS/mailscanner.spec
echo;
echo "Completed: $RPMOUT/MailScanner-${VERSION}.rhel.noarch.rpm";