v5/Build.rhel

169 lines
4.8 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
#
# Written by:
# Jerry Benton < mailscanner@mailborder.com >
# 13 FEB 2015
# 18 April 2016 - Updated
#
# Shawn Iverson <shawniverson@efa-project.org>
# 22 October 2018
#
# This script will build the latest RPM install
# package and put it in /msbuilds/rpm
# make sure this is run from the base directory
2016-05-01 19:43:25 +08:00
if [ ! -d 'rhel' ]; then
echo 'This script must be executed from the base directory.';
echo './RPM.files was not found. Exiting ...';
echo;
exit 192
fi
# directory we are in
THISCURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# if not set from the "Build.all" script
if [ -z "$RPMOUT" ]; then
RPMOUT="$HOME/msbuilds/rpm";
export RPMOUT;
fi
# check to see if the output directory exists
if [ ! -d "$RPMOUT" ]; then
mkdir -p $RPMOUT
fi
# if not set from the "Build.all" script
if [ -z "$MSVERSION" ]; then
echo "Please tell me the version number (x.xx.x): ";
read MSVERSION
export MSVERSION
fi
# if not set from the "Build.all" script
if [ -z "$MSBUILD" ]; then
echo "And the build number (-x): ";
read MSBUILD
export MSBUILD
fi
# if not set from the "Build.all" script
if [ -z "$FULLMSVER" ]; then
FULLMSVER=$MSVERSION-$MSBUILD
export FULLMSVER
fi
# if not set from the "Build.all" script
if [ -z "$DEVBASEDIR" ]; then
DEVBASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
#echo "You current directory is $THISCURDIR"; echo;
#echo "Enter the parent directory of RPM.files without the trailing slash: ";
#read DEVBASEDIR
export DEVBASEDIR
fi
# create this if missing
#if [ ! -f '/tmp/MailScanner.conf.index.html' ]; then
2016-05-01 19:43:25 +08:00
#sh $DEVBASEDIR/config.index/make.sh
#fi
# the source directory
2016-04-28 18:38:13 +08:00
SRCDIR=$DEVBASEDIR/rhel
# version info
BUILD=$MSBUILD
VERSION=$MSVERSION-$BUILD
export VERSION BUILD
# setup rpm development dirs
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
# create build output base dir
mkdir -p $RPMOUT
# the work directory
2016-05-02 01:36:41 +08:00
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
2016-05-10 07:45:10 +08:00
mkdir -p $WORK/{usr,etc}
2016-04-28 18:38:13 +08:00
# etc
2016-05-01 19:43:25 +08:00
cp -fr $DEVBASEDIR/common/etc/* $WORK/etc/
cp -fr $DEVBASEDIR/rhel/etc/* $WORK/etc/
2016-04-28 18:38:13 +08:00
# usr
2016-05-01 19:43:25 +08:00
cp -fr $DEVBASEDIR/common/usr/* $WORK/usr/
cp -fr $DEVBASEDIR/rhel/usr/* $WORK/usr/
# Insert the version number we are building
2016-04-28 18:38:13 +08:00
perl -pi -e 's/VersionNumberHere/'$MSVERSION'/;' $WORK/etc/MailScanner/MailScanner.conf
perl -pi -e 's/VersionNumberHere/'$MSVERSION'/;' $WORK/usr/sbin/MailScanner
2016-04-28 18:38:13 +08:00
# do the same for mailscanner.spec
cp -f $DEVBASEDIR/rhel/mailscanner.spec ~/rpmbuild/SPECS/mailscanner.spec
perl -pi -e 's/VersionNumberHere/'$MSVERSION'/;' ~/rpmbuild/SPECS/mailscanner.spec
perl -pi -e 's/ReleaseNumberHere/'$MSBUILD'/;' ~/rpmbuild/SPECS/mailscanner.spec
# 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 {} \;
# permissions
2016-05-01 19:43:25 +08:00
cd $WORK
find . -type f -exec chmod 0644 {} \;
find . -type d -exec chmod 0755 {} \;
chmod +x $WORK/usr/sbin/*
2016-05-10 07:45:10 +08:00
chmod +x $WORK/usr/lib/MailScanner/wrapper/*-autoupdate
chmod +x $WORK/usr/lib/MailScanner/wrapper/*-wrapper
chmod +x $WORK/usr/lib/MailScanner/init/*
2016-05-01 19:43:25 +08:00
chmod +x $WORK/etc/cron.daily/*
chmod +x $WORK/etc/cron.hourly/*
2016-04-28 18:38:13 +08:00
# Build the src tarball for RPM construction
cd $WORK
cd ..
2016-05-02 01:35:42 +08:00
tar czf ~/rpmbuild/SOURCES/MailScanner-${MSVERSION}.tgz MailScanner-${MSVERSION}
# return to where i started
cd $THISCURDIR
# create the output dir in $RPMOUT
2016-05-02 01:27:42 +08:00
if [ -d $RPMOUT/MailScanner-$VERSION ]; then
rm -rf $RPMOUT/MailScanner-$VERSION
fi
mkdir -p $RPMOUT/MailScanner-$VERSION
# copy some file we need
cp $SRCDIR/install.sh $RPMOUT/MailScanner-$VERSION/
2016-04-28 18:38:13 +08:00
cp $DEVBASEDIR/README $RPMOUT/MailScanner-$VERSION/
cp $DEVBASEDIR/LICENSE $RPMOUT/MailScanner-$VERSION/
cp $DEVBASEDIR/common/patch/patch.diff $RPMOUT/MailScanner-$VERSION/
2016-05-02 01:27:42 +08:00
find $RPMOUT/MailScanner-$VERSION -name 'install.sh' -exec chmod 755 {} \;
2016-04-28 18:38:13 +08:00
find $RPMOUT/MailScanner-$VERSION -name 'LICENSE' -exec chmod 644 {} \;
find $RPMOUT/MailScanner-$VERSION -name 'README' -exec chmod 644 {} \;
find $RPMOUT/MailScanner-$VERSION -name 'patch.diff' -exec chmod 644 {} \;
# Build the RPM and SRPMS
# extra define statements help make the rpm backwards compatible
2016-05-01 19:43:25 +08:00
#rpmbuild -ba --sign --define "_binary_filedigest_algorithm 1" --define "_binary_payload 1" ~/rpmbuild/SPECS/mailscanner.spec
rpmbuild -ba --define "_binary_filedigest_algorithm 1" --define "_binary_payload 1" ~/rpmbuild/SPECS/mailscanner.spec
# copy the rpm built to the output dir
2016-05-02 01:35:42 +08:00
cp ~/rpmbuild/RPMS/noarch/MailScanner-${VERSION}.noarch.rpm $RPMOUT/MailScanner-$VERSION
cd $RPMOUT
2016-05-03 16:08:38 +08:00
tar czf MailScanner-${VERSION}.rhel.tar.gz MailScanner-$VERSION
rm -rf $RPMOUT/MailScanner-$VERSION
2016-05-02 01:27:42 +08:00
rm -rf $WORK
echo;
2016-05-03 16:08:38 +08:00
echo "Completed: $RPMOUT/MailScanner-${VERSION}.rhel.tar.gz";