2010-11-24 05:49:05 +00:00
|
|
|
#---------------------------------*- sh -*-------------------------------------
|
|
|
|
# ========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
# \\ / F ield | foam-extend: Open Source CFD
|
2010-11-24 05:49:05 +00:00
|
|
|
# \\ / O peration |
|
2013-12-11 16:09:41 +00:00
|
|
|
# \\ / A nd | For copyright notice see file Copyright
|
2010-11-24 05:49:05 +00:00
|
|
|
# \\/ M anipulation |
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# License
|
2013-12-11 16:09:41 +00:00
|
|
|
# This file is part of foam-extend.
|
2010-11-24 05:49:05 +00:00
|
|
|
#
|
2013-12-11 16:09:41 +00:00
|
|
|
# foam-extend is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License as published by the
|
|
|
|
# Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
# option) any later version.
|
2010-11-24 05:49:05 +00:00
|
|
|
#
|
2013-12-11 16:09:41 +00:00
|
|
|
# foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
2010-11-24 05:49:05 +00:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
# along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-24 05:49:05 +00:00
|
|
|
#
|
|
|
|
# File
|
|
|
|
# makeThirdPartyFunctionsForRPM
|
|
|
|
#
|
|
|
|
# Description
|
|
|
|
# Functions for managing the third-party packages with RPM
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# define the build and the system architecture type
|
|
|
|
buildBase=$WM_THIRD_PARTY_DIR/rpmBuild
|
|
|
|
architecture=`rpm --eval "%{_target_cpu}"`
|
|
|
|
|
2013-07-04 14:00:39 +00:00
|
|
|
RPM_CMD='rpm'
|
|
|
|
RPM_CMD_XTRA_OPTIONS=''
|
2011-05-13 14:20:07 +00:00
|
|
|
|
|
|
|
# Adjust the rpm command options on Ubuntu/Debian based systems
|
|
|
|
${RPM_CMD} --force-debian >& /dev/null
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
RETVAL=$?
|
2011-05-13 14:20:07 +00:00
|
|
|
[ $RETVAL -eq 0 ] && RPM_CMD_XTRA_OPTIONS="--force-debian" #Success : Debian system
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
echo ""
|
2011-05-13 14:20:07 +00:00
|
|
|
echo "This system rpm command: ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS}"
|
2010-11-24 05:49:05 +00:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
#
|
|
|
|
# Download/Build/Uninstall/Install a package
|
|
|
|
#
|
|
|
|
rpm_make()
|
|
|
|
{
|
2011-05-11 01:16:29 +00:00
|
|
|
# Avoid word splitting on 'space'
|
|
|
|
IFS=$'\n'
|
2013-07-04 14:00:39 +00:00
|
|
|
|
2011-05-09 02:48:26 +00:00
|
|
|
# sort arguments
|
|
|
|
_PACKAGE=''
|
|
|
|
_SPECFILE=''
|
|
|
|
_PACKAGE_URL=''
|
|
|
|
_ADDITIONALFLAGS=''
|
2013-07-04 14:00:39 +00:00
|
|
|
_RPMFILENAME=''
|
2011-05-09 02:48:26 +00:00
|
|
|
|
2013-04-15 11:59:44 +00:00
|
|
|
while getopts p:s:u:f:n:a: flags
|
2011-05-09 02:48:26 +00:00
|
|
|
do
|
|
|
|
case $flags in
|
|
|
|
p) _PACKAGE=$OPTARG
|
|
|
|
;;
|
|
|
|
u) _PACKAGE_URL=$OPTARG
|
|
|
|
;;
|
|
|
|
s) _SPECFILE=$OPTARG
|
|
|
|
;;
|
2013-04-15 11:59:44 +00:00
|
|
|
f) _ADDITIONALFLAGS=$OPTARG
|
|
|
|
;;
|
|
|
|
n) _RPMFILENAME=$OPTARG
|
|
|
|
;;
|
|
|
|
a) architecture=$OPTARG
|
2011-05-09 02:48:26 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Package name : $_PACKAGE"
|
|
|
|
echo "Package URL : $_PACKAGE_URL"
|
|
|
|
echo "RPM spec file name: $_SPECFILE"
|
2016-09-05 10:17:38 +00:00
|
|
|
echo "RPM file name : $_RPMFILENAME"
|
2011-05-09 02:48:26 +00:00
|
|
|
echo "Additional flags : $_ADDITIONALFLAGS"
|
|
|
|
|
|
|
|
# Shift options
|
|
|
|
shift `expr $OPTIND - 1`
|
2010-12-01 13:07:16 +00:00
|
|
|
|
2013-07-04 14:00:39 +00:00
|
|
|
# Make sure the ThirdParty environment is up-to-date
|
|
|
|
echo "Updating the ThirdParty environment variables before building package $_PACKAGE"
|
|
|
|
. $WM_PROJECT_DIR/etc/settings.sh
|
|
|
|
|
|
|
|
if [ "$_RPMFILENAME" = "" ]; then
|
|
|
|
rpmName=$_PACKAGE-$WM_OPTIONS.$architecture
|
|
|
|
else
|
|
|
|
# Filename for the RPM was overridden from the command line
|
|
|
|
rpmName=$_RPMFILENAME
|
|
|
|
fi
|
|
|
|
|
2010-11-24 05:49:05 +00:00
|
|
|
rpmFile=$buildBase/RPMS/$architecture/$rpmName.rpm
|
|
|
|
|
2013-04-15 11:59:44 +00:00
|
|
|
echo "RPM file name : $rpmFile"
|
|
|
|
|
2010-11-24 05:49:05 +00:00
|
|
|
# We check immediatly if the RPM binary package is available in the local RPMs vault.
|
|
|
|
# If so, we basically uninstall/reinstall the package. This is handy for installation
|
|
|
|
# on machines with no Internet access, so without downloading capabilities. If one wants to
|
|
|
|
# force the recompilation of a given package, just make sure to move the corresponding RPM
|
|
|
|
# binary package away from the local RPM vault.
|
|
|
|
#
|
|
|
|
if [ ! -e "$rpmFile" ]; then
|
|
|
|
#
|
2013-07-04 14:00:39 +00:00
|
|
|
# The package's RPM is absent. We build from the package source tarball
|
2010-11-24 05:49:05 +00:00
|
|
|
#
|
|
|
|
cd $buildBase
|
|
|
|
|
2011-05-09 02:48:26 +00:00
|
|
|
#
|
|
|
|
# Do we need to download the package using the supplied URL
|
2013-07-04 14:00:39 +00:00
|
|
|
if [ -n "$_PACKAGE_URL" ]; then
|
2011-05-09 02:48:26 +00:00
|
|
|
packageTarBall=`basename $_PACKAGE_URL`
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
if [ ! -e "SOURCES/$packageTarBall" ]; then
|
2011-05-09 02:48:26 +00:00
|
|
|
echo "Download $packageTarBall from : $_PACKAGE_URL"
|
|
|
|
( cd SOURCES; wget --no-check-certificate $_PACKAGE_URL )
|
2010-11-24 05:49:05 +00:00
|
|
|
fi
|
2011-05-09 02:48:26 +00:00
|
|
|
fi
|
2010-11-24 05:49:05 +00:00
|
|
|
|
2011-05-09 02:48:26 +00:00
|
|
|
echo "Making package $_PACKAGE using RPM."
|
2011-05-11 01:16:29 +00:00
|
|
|
rpm_build ${_PACKAGE} ${_SPECFILE} ${_ADDITIONALFLAGS} "$@"
|
2015-05-24 20:31:30 +00:00
|
|
|
#rpm_build_install_stage_only ${_PACKAGE} ${_SPECFILE} ${_ADDITIONALFLAGS} "$@"
|
2010-11-24 05:49:05 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Install RPM package if not done already
|
2013-07-04 14:00:39 +00:00
|
|
|
if [ "$architecture" = "noarch" ]; then
|
|
|
|
installDir=$WM_THIRD_PARTY_DIR/packages/$_PACKAGE/platforms/noarch
|
|
|
|
else
|
|
|
|
installDir=$WM_THIRD_PARTY_DIR/packages/$_PACKAGE/platforms/$WM_OPTIONS
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "$installDir" ]; then
|
2011-05-09 02:48:26 +00:00
|
|
|
echo "Installing package: $_PACKAGE"
|
2013-07-04 14:00:39 +00:00
|
|
|
rpm_uninstall $_PACKAGE $rpmName
|
|
|
|
rpm_install $_PACKAGE $rpmName $rpmFile
|
2010-11-24 05:49:05 +00:00
|
|
|
else
|
2011-05-09 02:48:26 +00:00
|
|
|
echo "Package $_PACKAGE is already installed"
|
2010-11-24 05:49:05 +00:00
|
|
|
fi
|
|
|
|
|
2011-05-09 02:48:26 +00:00
|
|
|
unset _PACKAGE
|
|
|
|
unset _SPECFILE
|
|
|
|
unset _PACKAGE_URL
|
|
|
|
unset _ADDITIONALFLAGS
|
2013-07-04 14:00:39 +00:00
|
|
|
unset _RPMFILENAME
|
2011-05-09 02:48:26 +00:00
|
|
|
|
|
|
|
echo "Done installing package $_PACKAGE"
|
2010-11-24 05:49:05 +00:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Build a RPM file using the package SPEC file
|
|
|
|
#
|
|
|
|
rpm_build()
|
|
|
|
{
|
|
|
|
package="$1"
|
2011-05-09 02:48:26 +00:00
|
|
|
specFile="$2"
|
|
|
|
shift 2
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
cd $buildBase
|
|
|
|
|
|
|
|
[ -e ./SPECS/$specFile ] || {
|
2013-07-04 14:00:39 +00:00
|
|
|
echo "rpm_build: Error: missing SPEC file for package $package. Aborting."
|
|
|
|
exit -1
|
2010-11-24 05:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#Build RPM package
|
2011-05-09 02:48:26 +00:00
|
|
|
echo "Building package $package using SPEC file : $specFile. Optional args: $@"
|
2010-12-01 13:07:16 +00:00
|
|
|
#rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --clean -bb ./SPECS/$specFile "$@"
|
|
|
|
#
|
|
|
|
# Let's keep the compilation directory alive for now in order to facilitate postmortems of failed compilations
|
|
|
|
rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB -bb ./SPECS/$specFile "$@"
|
2010-11-24 05:49:05 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 20:31:30 +00:00
|
|
|
#
|
|
|
|
# Build a RPM file using the package SPEC file. This function will only call the "%install" stage.
|
|
|
|
# Useful for debugging the "%install" stage.
|
|
|
|
#
|
|
|
|
rpm_build_install_stage_only()
|
|
|
|
{
|
|
|
|
package="$1"
|
|
|
|
specFile="$2"
|
|
|
|
shift 2
|
|
|
|
|
|
|
|
cd $buildBase
|
|
|
|
|
|
|
|
[ -e ./SPECS/$specFile ] || {
|
|
|
|
echo "rpm_build: Error: missing SPEC file for package $package. Aborting."
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
#Build RPM package
|
|
|
|
echo "Building package $package using SPEC file : $specFile. Optional args: $@"
|
|
|
|
#rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --clean -bb ./SPECS/$specFile "$@"
|
|
|
|
#
|
|
|
|
# Let's keep the compilation directory alive for now in order to facilitate postmortems of failed compilations
|
|
|
|
rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --short-circuit -bi ./SPECS/$specFile "$@"
|
|
|
|
}
|
|
|
|
|
2010-11-24 05:49:05 +00:00
|
|
|
#
|
|
|
|
# Uninstall a package using its RPM
|
|
|
|
#
|
|
|
|
rpm_uninstall()
|
|
|
|
{
|
|
|
|
package="$1"
|
2013-07-04 14:00:39 +00:00
|
|
|
rpmName="$2"
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
cd $buildBase
|
|
|
|
|
|
|
|
echo " Uninstalling $package using RPM: $rpmName"
|
2011-05-13 14:20:07 +00:00
|
|
|
${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -e $rpmName --dbpath $buildBase/rpmDB --norepackage >& /dev/null
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
# Note: rpm will rant when uninstalling packages with an error message
|
|
|
|
# starting with "error: LOOP:"
|
|
|
|
# Googling about this problem shows that this error is benign, and
|
|
|
|
# is related to the list of the files included in the RPM, and the
|
|
|
|
# syntax used in the SPEC file. Need to revisit later... MB
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Install a package using its relocatable RPM
|
|
|
|
#
|
|
|
|
rpm_install()
|
|
|
|
{
|
|
|
|
package="$1";
|
2013-07-04 14:00:39 +00:00
|
|
|
rpmName="$2";
|
|
|
|
rpmFile="$3";
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
echo " Installing $package using RPM file: $rpmFile";
|
2011-05-13 14:20:07 +00:00
|
|
|
${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -ivh \
|
2010-11-24 05:49:05 +00:00
|
|
|
$rpmFile \
|
|
|
|
--dbpath $buildBase/rpmDB --force --nodeps;
|
|
|
|
}
|
|
|
|
|
2013-12-28 16:04:11 +00:00
|
|
|
#
|
|
|
|
# Populate the local RPM vault with comand-line supplied list of RPMs
|
|
|
|
#
|
|
|
|
rpm_makeRPMvault()
|
|
|
|
{
|
|
|
|
rpmVault=$buildBase/RPMS/$architecture
|
|
|
|
|
|
|
|
if [ ! -e $rpmVault ]; then
|
|
|
|
echo ""
|
|
|
|
echo "Making directory for RPM-files $rpmVault"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
mkdir -p $rpmVault
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-11-24 05:49:05 +00:00
|
|
|
#
|
|
|
|
# Populate the local RPM vault with comand-line supplied list of RPMs
|
|
|
|
#
|
|
|
|
rpm_populateRPMvault()
|
|
|
|
{
|
|
|
|
rpmVault=$buildBase/RPMS/$architecture
|
|
|
|
|
|
|
|
echo " Local RPM vault location: $rpmVault"
|
|
|
|
echo ""
|
2013-07-04 14:00:39 +00:00
|
|
|
echo " Moving the following RPMs to the local RPM vault: `echo $@`"
|
2010-11-24 05:49:05 +00:00
|
|
|
|
|
|
|
mv $@ $rpmVault
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo " Current content of the local RPM vault:"
|
|
|
|
ls -axlt $rpmVault
|
|
|
|
echo ""
|
|
|
|
}
|
2014-06-01 08:42:15 +00:00
|
|
|
|
2013-07-04 14:00:39 +00:00
|
|
|
#
|
|
|
|
# Remove an installed package
|
|
|
|
#
|
|
|
|
uninstallPackage()
|
|
|
|
{
|
|
|
|
pkg="$1";
|
2014-05-28 20:27:43 +00:00
|
|
|
|
|
|
|
echo "Removing ${pkg}"
|
|
|
|
[ -f $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm ] && \
|
|
|
|
rm -f $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm || \
|
|
|
|
echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm"
|
|
|
|
[ -f $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz ] && \
|
|
|
|
rm -f $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz || \
|
|
|
|
echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz"
|
|
|
|
[ -f $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz ] && \
|
|
|
|
rm -f $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz || \
|
|
|
|
echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz"
|
|
|
|
[ -d $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}* ] && \
|
|
|
|
rm -rf $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}* || \
|
|
|
|
echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}*"
|
|
|
|
if [ "$2" = "alsoPackage" ]; then
|
|
|
|
[ -d $WM_THIRD_PARTY_DIR/packages/$pkg ] && \
|
|
|
|
rm -rf $WM_THIRD_PARTY_DIR/packages/$pkg || \
|
|
|
|
echo "Not found: $WM_THIRD_PARTY_DIR/packages/$pkg"
|
2013-07-04 14:00:39 +00:00
|
|
|
else
|
2014-06-01 08:42:15 +00:00
|
|
|
echo "Add option alsoPackage to remove the installed files."
|
2013-07-04 14:00:39 +00:00
|
|
|
fi
|
2014-05-28 20:27:43 +00:00
|
|
|
echo
|
2013-07-04 14:00:39 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 05:49:05 +00:00
|
|
|
# ----------------------------------------------------------------- end-of-file
|