#!/bin/sh #------------------------------------------------------------------------------ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2019-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # # Script # create-tar [OPTION] # # Description # Create a tar-file from OpenFOAM repository # Grab and modify a corresponding .spec file, with rpmlintrc # # Requires # bash curl git tar gzip sed # #------------------------------------------------------------------------------ repoUrl="https://develop.openfoam.com/Development/openfoam" specUrl="$repoUrl/-/wikis/packaging/common" specName="openfoamAPI.spec" specName_old="openfoamVERSION.spec" # Old specName (2021-02-17) branch="master" release=0 #------------------------------------------------------------------------------ printHelp() { cat <&2 ;; *) echo "Unexpected argument (ignore): $1" 1>&2 ;; esac shift done # Shortcuts case "$branch" in main-*) branch="maintenance-${branch#*-}" ;; rel-*) branch="release-${branch#*-}" ;; esac #------------------------------------------------------------------------------- echo "Creating output in $outputDir" echo "branch = ${branch}" if [ "$specFile" = false ] then echo "tar-file only (no spec)" else echo "release = ${release}${distMacro}" fi echo if [ -d "$outputDir/$gitDir" ] then echo "Removing existing directory: $outputDir/$gitDir" rm -rf -- "$outputDir/$gitDir" 2>/dev/null fi mkdir -p "$outputDir" if [ -z "$keepTmpDir" ] then # Remove tmp-dir trap "rm -f $outputDir/$gitDir 2>/dev/null; exit 0" EXIT TERM INT fi [ "$optVerbose" = true ] && set -x git clone -n --depth=1 \ --branch="$branch" \ "${repoUrl}.git" "$outputDir/$gitDir" oldDir="$PWD" if cd "$outputDir/$gitDir" # pushd then # The most current foamPackRelease (from develop branch) curl "${repoUrl}/raw/develop/bin/tools/foamPackRelease" > foamPackRelease # Minimum needed to get api/patch values git checkout HEAD -- bin/foamEtcFile META-INFO # The api and patch api="$(bin/foamEtcFile -show-api)" patch="$(bin/foamEtcFile -show-patch)" if [ "$optTar" = false ] then echo "skip creation of tar-file" else # Need checkout of modules/ for git submodule update to work # except if -no-modules if [ "${optModules#-no}" = "${optModules}" ] then git checkout HEAD -- .gitmodules modules # Older git and without nested submodules # git submodule init && git submodule update --depth=1 # Newer git and with nested submodules git submodule update --init --recursive --depth=1 fi # Fetch tar file, placing into parent dir (out-dir) bash ./foamPackRelease \ $optTar \ $optDebian \ $optCompress \ $optModules \ $optPrefix \ -output=.. HEAD | \ bash fi cd "$oldDir" # popd else echo "Could not change to $outputDir/$gitDir, did git clone fail?" exit 1 fi if [ "$keepTmpDir" = true ] then echo "Retaining $outputDir/$gitDir" echo " ... must be removed manually" else echo "Removing $outputDir/$gitDir" rm -rf -- "$outputDir/$gitDir" fi if [ "$specFile" = false ] then echo "Created tar only, without spec file" exit 0 fi # ----------------------------------------------------------------------------- # Filtering rules # Change foam_api -> foam_api API filterApi='s/^\(%define *foam_api\).*$/\1 '"${api}/" # Change foam_patch -> foam_patch N unset filterPatch if [ "${patch:-0}" != 0 ] then filterPatch='s/^\(%define *foam_patch\).*/\1 '"${patch}/" fi # Special release info handling unset filterRelease case "${release}" in patch) release="${patch:-0}" ;; esac # Modify release info in spec file, # include '%{?dist}' macro (RedHat) if specified if [ "${release:-0}" != 0 ] then filterRelease='s/^\(Release: *\).*/\1'"${release}${distMacro}/" fi # Distribution-specific adjustments to the spec file unset filterDistSpec case "$distType" in (redhat | fedora | rhel | centos) # No Group, BuildRoot # License is not SPDX # Suggests: tag may not be supported (EPEL) filterDistSpec='/^Group:/d;/^BuildRoot:/d;/^Suggests:/d;/^License:/s/GPL-3.*/GPLv3+/' ;; esac # Distribution-specific adjustments to the spec file unset filterCGAL if [ "$without_CGAL" = true ] then filterCGAL='/%bcond_without.*cgal/s/_without/_with/;//,/<\/with-cgal>/d' fi if [ -n "$specFile" ] then # Need fully-qualified filename if [ -f "$specFile" ] then dir="$(cd "$(dirname "$specFile")" && pwd -L)" file="$(basename "$specFile")" specFile="$dir/$file" else echo "Error: no such spec file: $specFile" 1>&2 exit 2 fi getSpec() { cat "${specFile}" } else getSpec() { curl "${specUrl}/${specName}" } fi oldDir="$PWD" if cd "$outputDir" # pushd then # Grab and modify the spec file getSpec | \ sed \ -e "${filterApi};" \ -e "${filterPatch};" \ -e "${filterRelease};" \ -e "${filterDistSpec};" \ -e "${filterCGAL};" \ > "openfoam${api}.spec" # Grab the rmplintrc file curl "${specUrl}/openfoam-rpmlintrc" > "openfoam-rpmlintrc" # List the files ls -al cd "$oldDir" # popd else echo "Could not change to $outputDir, should not happen" exit 1 fi # -----------------------------------------------------------------------------