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

91 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 SUSE install
# make sure this is run from the base directory
if [ ! -d 'suse' ]; then
echo 'This script must be executed from the base directory.';
echo './suse 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 to 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/suse/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}.suse.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}.suse.noarch.rpm";