1 #---------------------------------*- sh -*-------------------------------------
3 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / A nd | For copyright notice see file Copyright
7 #------------------------------------------------------------------------------
9 # This file is part of foam-extend.
11 # foam-extend is free software: you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by the
13 # Free Software Foundation, either version 3 of the License, or (at your
14 # option) any later version.
16 # foam-extend is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # makeThirdPartyFunctionsForRPM
28 # Functions for managing the third-party packages with RPM
30 #------------------------------------------------------------------------------
32 # define the build and the system architecture type
33 buildBase=$WM_THIRD_PARTY_DIR/rpmBuild
34 architecture=`rpm --eval "%{_target_cpu}"`
37 RPM_CMD_XTRA_OPTIONS=''
39 # Adjust the rpm command options on Ubuntu/Debian based systems
40 ${RPM_CMD} --force-debian >& /dev/null
43 [ $RETVAL -eq 0 ] && RPM_CMD_XTRA_OPTIONS="--force-debian" #Success : Debian system
46 echo "This system rpm command: ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS}"
50 # Download/Build/Uninstall/Install a package
54 # Avoid word splitting on 'space'
64 while getopts p:s:u:f:n:a: flags
69 u) _PACKAGE_URL=$OPTARG
73 f) _ADDITIONALFLAGS=$OPTARG
75 n) _RPMFILENAME=$OPTARG
77 a) architecture=$OPTARG
82 echo "Package name : $_PACKAGE"
83 echo "Package URL : $_PACKAGE_URL"
84 echo "RPM spec file name: $_SPECFILE"
85 echo "Additional flags : $_ADDITIONALFLAGS"
88 shift `expr $OPTIND - 1`
90 # Make sure the ThirdParty environment is up-to-date
91 echo "Updating the ThirdParty environment variables before building package $_PACKAGE"
92 . $WM_PROJECT_DIR/etc/settings.sh
94 if [ "$_RPMFILENAME" = "" ]; then
95 rpmName=$_PACKAGE-$WM_OPTIONS.$architecture
97 # Filename for the RPM was overridden from the command line
101 rpmFile=$buildBase/RPMS/$architecture/$rpmName.rpm
103 echo "RPM file name : $rpmFile"
105 # We check immediatly if the RPM binary package is available in the local RPMs vault.
106 # If so, we basically uninstall/reinstall the package. This is handy for installation
107 # on machines with no Internet access, so without downloading capabilities. If one wants to
108 # force the recompilation of a given package, just make sure to move the corresponding RPM
109 # binary package away from the local RPM vault.
111 if [ ! -e "$rpmFile" ]; then
113 # The package's RPM is absent. We build from the package source tarball
118 # Do we need to download the package using the supplied URL
119 if [ -n "$_PACKAGE_URL" ]; then
120 packageTarBall=`basename $_PACKAGE_URL`
122 if [ ! -e "SOURCES/$packageTarBall" ]; then
123 echo "Download $packageTarBall from : $_PACKAGE_URL"
124 ( cd SOURCES; wget --no-check-certificate $_PACKAGE_URL )
128 echo "Making package $_PACKAGE using RPM."
129 rpm_build ${_PACKAGE} ${_SPECFILE} ${_ADDITIONALFLAGS} "$@"
130 #rpm_build_install_stage_only ${_PACKAGE} ${_SPECFILE} ${_ADDITIONALFLAGS} "$@"
133 # Install RPM package if not done already
134 if [ "$architecture" = "noarch" ]; then
135 installDir=$WM_THIRD_PARTY_DIR/packages/$_PACKAGE/platforms/noarch
137 installDir=$WM_THIRD_PARTY_DIR/packages/$_PACKAGE/platforms/$WM_OPTIONS
140 if [ ! -e "$installDir" ]; then
141 echo "Installing package: $_PACKAGE"
142 rpm_uninstall $_PACKAGE $rpmName
143 rpm_install $_PACKAGE $rpmName $rpmFile
145 echo "Package $_PACKAGE is already installed"
151 unset _ADDITIONALFLAGS
154 echo "Done installing package $_PACKAGE"
159 # Build a RPM file using the package SPEC file
169 [ -e ./SPECS/$specFile ] || {
170 echo "rpm_build: Error: missing SPEC file for package $package. Aborting."
175 echo "Building package $package using SPEC file : $specFile. Optional args: $@"
176 #rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --clean -bb ./SPECS/$specFile "$@"
178 # Let's keep the compilation directory alive for now in order to facilitate postmortems of failed compilations
179 rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB -bb ./SPECS/$specFile "$@"
183 # Build a RPM file using the package SPEC file. This function will only call the "%install" stage.
184 # Useful for debugging the "%install" stage.
186 rpm_build_install_stage_only()
194 [ -e ./SPECS/$specFile ] || {
195 echo "rpm_build: Error: missing SPEC file for package $package. Aborting."
200 echo "Building package $package using SPEC file : $specFile. Optional args: $@"
201 #rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --clean -bb ./SPECS/$specFile "$@"
203 # Let's keep the compilation directory alive for now in order to facilitate postmortems of failed compilations
204 rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --short-circuit -bi ./SPECS/$specFile "$@"
208 # Uninstall a package using its RPM
217 echo " Uninstalling $package using RPM: $rpmName"
218 ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -e $rpmName --dbpath $buildBase/rpmDB --norepackage >& /dev/null
220 # Note: rpm will rant when uninstalling packages with an error message
221 # starting with "error: LOOP:"
222 # Googling about this problem shows that this error is benign, and
223 # is related to the list of the files included in the RPM, and the
224 # syntax used in the SPEC file. Need to revisit later... MB
228 # Install a package using its relocatable RPM
236 echo " Installing $package using RPM file: $rpmFile";
237 ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -ivh \
239 --dbpath $buildBase/rpmDB --force --nodeps;
243 # Populate the local RPM vault with comand-line supplied list of RPMs
247 rpmVault=$buildBase/RPMS/$architecture
249 if [ ! -e $rpmVault ]; then
251 echo "Making directory for RPM-files $rpmVault"
259 # Populate the local RPM vault with comand-line supplied list of RPMs
261 rpm_populateRPMvault()
263 rpmVault=$buildBase/RPMS/$architecture
265 echo " Local RPM vault location: $rpmVault"
267 echo " Moving the following RPMs to the local RPM vault: `echo $@`"
272 echo " Current content of the local RPM vault:"
278 # Remove an installed package
284 echo "Removing ${pkg}"
285 [ -f $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm ] && \
286 rm -f $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm || \
287 echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm"
288 [ -f $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz ] && \
289 rm -f $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz || \
290 echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz"
291 [ -f $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz ] && \
292 rm -f $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz || \
293 echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz"
294 [ -d $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}* ] && \
295 rm -rf $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}* || \
296 echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}*"
297 if [ "$2" = "alsoPackage" ]; then
298 [ -d $WM_THIRD_PARTY_DIR/packages/$pkg ] && \
299 rm -rf $WM_THIRD_PARTY_DIR/packages/$pkg || \
300 echo "Not found: $WM_THIRD_PARTY_DIR/packages/$pkg"
302 echo "Add option alsoPackage to remove the installed files."
307 # ----------------------------------------------------------------- end-of-file