mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve foamEtcFile support for alternative naming conventions
- support names like openfoam-<VERSION> (eg, what spack uses). - robustness improvements
This commit is contained in:
@ -50,8 +50,8 @@ usage() {
|
|||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTION] fileName
|
Usage: foamEtcFile [OPTION] fileName
|
||||||
${0##*/} [OPTION] -list
|
foamEtcFile [OPTION] -list
|
||||||
options:
|
options:
|
||||||
-a, -all return all files (otherwise stop after the first match)
|
-a, -all return all files (otherwise stop after the first match)
|
||||||
-l, -list list the directories to be searched
|
-l, -list list the directories to be searched
|
||||||
@ -93,20 +93,24 @@ prefixDir="${projectDir%/*}"
|
|||||||
# The name used for the project directory
|
# The name used for the project directory
|
||||||
projectDirName="${projectDir##*/}"
|
projectDirName="${projectDir##*/}"
|
||||||
|
|
||||||
# versionNum used for debian packaging
|
# The versionNum is used for debian packaging
|
||||||
unset version versionNum
|
unset versionNum
|
||||||
|
|
||||||
#
|
#
|
||||||
# Handle standard and debian naming conventions
|
# Handle standard and debian naming conventions.
|
||||||
# - set version (always) and versionNum (debian only)
|
# - projectDirBase: projectDirName without the version
|
||||||
|
# - version
|
||||||
|
# - versionNum (debian only)
|
||||||
#
|
#
|
||||||
case "$projectDirName" in
|
case "$projectDirName" in
|
||||||
OpenFOAM-*) # standard naming: OpenFOAM-<VERSION>
|
OpenFOAM-* | openfoam-*) # OpenFOAM-<VERSION> or openfoam-<VERSION>
|
||||||
version="${projectDirName##OpenFOAM-}"
|
projectDirBase="${projectDirName%%-*}-"
|
||||||
|
version="${projectDirName#*-}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
openfoam[0-9]* | openfoam-dev) # debian naming: openfoam<VERSION>
|
openfoam[0-9]*) # Debian: openfoam<VERSION>
|
||||||
versionNum="${projectDirName##openfoam}"
|
projectDirBase="openfoam"
|
||||||
|
versionNum="${projectDirName#openfoam}"
|
||||||
case "${#versionNum}" in
|
case "${#versionNum}" in
|
||||||
(2|3|4) # Convert digits version number to decimal delineated
|
(2|3|4) # Convert digits version number to decimal delineated
|
||||||
version=$(echo "$versionNum" | sed -e 's@\([0-9]\)@\1.@g')
|
version=$(echo "$versionNum" | sed -e 's@\([0-9]\)@\1.@g')
|
||||||
@ -120,12 +124,24 @@ openfoam[0-9]* | openfoam-dev) # debian naming: openfoam<VERSION>
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "${0##*/} Error : unknown/unsupported naming convention" 1>&2
|
echo "foamEtcFile error: unknown/unsupported naming convention" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
# Set version and update versionNum, projectDirName accordingly
|
||||||
|
setVersion()
|
||||||
|
{
|
||||||
|
version="$1"
|
||||||
|
|
||||||
|
# Convert x.y.z -> xyz version (if installation looked like debian)
|
||||||
|
[ -n "$versionNum" ] && versionNum=$(echo "$version" | sed -e 's@\.@@g')
|
||||||
|
|
||||||
|
projectDirName="$projectDirBase${versionNum:-${version}}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Default mode is always 'ugo'
|
# Default mode is always 'ugo'
|
||||||
mode=ugo
|
mode=ugo
|
||||||
unset optAll optList optShell
|
unset optAll optList optShell
|
||||||
@ -150,19 +166,14 @@ do
|
|||||||
unset optAll
|
unset optAll
|
||||||
;;
|
;;
|
||||||
-mode=[ugo]*)
|
-mode=[ugo]*)
|
||||||
mode="${1#-mode=}"
|
mode="${1#*=}"
|
||||||
;;
|
;;
|
||||||
-prefix=/*)
|
-prefix=/*)
|
||||||
prefixDir="${1#-prefix=}"
|
prefixDir="${1#*=}"
|
||||||
prefixDir="${prefixDir%/}"
|
prefixDir="${prefixDir%/}"
|
||||||
;;
|
;;
|
||||||
-version=*)
|
-version=*)
|
||||||
version="${1#-version=}"
|
setVersion "${1#*=}"
|
||||||
# convert x.y.z -> xyz version (if installation looked like debian)
|
|
||||||
if [ -n "$versionNum" ]
|
|
||||||
then
|
|
||||||
versionNum=$(echo "$version" | sed -e 's@\.@@g')
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
-m | -mode)
|
-m | -mode)
|
||||||
mode="$2"
|
mode="$2"
|
||||||
@ -189,12 +200,7 @@ do
|
|||||||
;;
|
;;
|
||||||
-v | -version)
|
-v | -version)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||||
version="$2"
|
setVersion "$2"
|
||||||
# convert x.y.z -> xyz version (if installation looked like debian)
|
|
||||||
if [ -n "$versionNum" ]
|
|
||||||
then
|
|
||||||
versionNum=$(echo "$version" | sed -e 's@\.@@g')
|
|
||||||
fi
|
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
@ -212,18 +218,13 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Update projectDir accordingly
|
# Update projectDir accordingly
|
||||||
if [ -n "$versionNum" ]
|
projectDir="$prefixDir/$projectDirName"
|
||||||
then
|
|
||||||
projectDir="$prefixDir/openfoam$versionNum" # debian
|
|
||||||
else
|
|
||||||
projectDir="$prefixDir/${WM_PROJECT:-OpenFOAM}-$version" # standard
|
|
||||||
fi
|
|
||||||
|
|
||||||
# debugging:
|
# Debugging:
|
||||||
# echo "Installed locations:"
|
# echo "Installed locations:" 1>&2
|
||||||
# for i in projectDir prefixDir projectDirName version versionNum
|
# for i in projectDir prefixDir projectDirName version versionNum
|
||||||
# do
|
# do
|
||||||
# eval echo "$i=\$$i"
|
# eval echo "$i=\$$i" 1>&2
|
||||||
# done
|
# done
|
||||||
|
|
||||||
|
|
||||||
@ -234,19 +235,19 @@ fileName="${1#~OpenFOAM/}"
|
|||||||
|
|
||||||
# Define the various places to be searched:
|
# Define the various places to be searched:
|
||||||
unset dirList
|
unset dirList
|
||||||
case "$mode" in (*u*) # user
|
case "$mode" in (*u*) # (U)ser
|
||||||
dir="$HOME/.${WM_PROJECT:-OpenFOAM}"
|
dir="$HOME/.${WM_PROJECT:-OpenFOAM}"
|
||||||
dirList="$dirList $dir/$version $dir"
|
dirList="$dirList $dir/$version $dir"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$mode" in (*g*) # group (site)
|
case "$mode" in (*g*) # (G)roup == site
|
||||||
dir="${WM_PROJECT_SITE:-$prefixDir/site}"
|
dir="${WM_PROJECT_SITE:-$prefixDir/site}"
|
||||||
dirList="$dirList $dir/$version $dir"
|
dirList="$dirList $dir/$version $dir"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$mode" in (*o*) # other (shipped)
|
case "$mode" in (*o*) # (O)ther == shipped
|
||||||
dirList="$dirList $projectDir/etc"
|
dirList="$dirList $projectDir/etc"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -261,10 +262,10 @@ exitCode=0
|
|||||||
if [ "$optList" = true ]
|
if [ "$optList" = true ]
|
||||||
then
|
then
|
||||||
|
|
||||||
# list directories, or potential file locations
|
# List directories, or potential file locations
|
||||||
[ "$nArgs" -le 1 ] || usage
|
[ "$nArgs" -le 1 ] || usage
|
||||||
|
|
||||||
# a silly combination, but -quiet does have precedence
|
# A silly combination, but -quiet does have precedence
|
||||||
[ -n "$optQuiet" ] && exit 0
|
[ -n "$optQuiet" ] && exit 0
|
||||||
|
|
||||||
for dir
|
for dir
|
||||||
@ -281,8 +282,7 @@ else
|
|||||||
|
|
||||||
[ "$nArgs" -eq 1 ] || usage
|
[ "$nArgs" -eq 1 ] || usage
|
||||||
|
|
||||||
# general error, eg file not found
|
exitCode=2 # Fallback to a general error, eg file not found
|
||||||
exitCode=2
|
|
||||||
|
|
||||||
for dir
|
for dir
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user