1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
#!/bin/sh
#---------------------------------*- sh -*-------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM 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.
#
# OpenFOAM 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.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# foamConfigurePaths
#
# Description
# hardcode installation directory
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
usage: ${0##*/}
--foamInstall dir specify installation directory (e.g. /opt)
--projectName name specify project name (e.g. openfoam220)
--projectVersion ver specify project version (e.g. 2.2.0)
--archOption arch specify architecture option (only 32 or 64 applicable)
--paraviewInstall dir specify ParaView_DIR (e.g. /opt/paraviewopenfoam3120)
--paraviewVersion ver specify ParaView_VERSION (e.g. 3.12.0)
--scotchArchPath dir specify SCOTCH_ARCH_PATH (e.g. /opt/OpenFOAM-scotch-6.0.0/)
--scotchVersion ver specify SCOTCH_VERSION (e.g. 6.0.0)
* hardcode paths to installation
USAGE
exit 1
}
# Function to do replacement on file. Checks if any replacement has been done.
# _inlineSed <file> <regexp> <replacement> <msg>
_inlineSed()
{
file="$1"
[ -f "$file" ] || {
echo "Missing file: $file"
exit 1
}
regexp="$2"
replacement="$3"
msg="$4"
cmd='/^[^#]/s@'"$regexp"'@'"$replacement"'@'
grep -q "$regexp" "$file" && sed -i -e "$cmd" "$file" || \
(echo "Failed: $msg in $file" && exit 1)
echo "Okay: $msg in $file"
return 0
}
[ -f etc/bashrc ] || usage "Please run from top-level directory of installation"
unset foamInstDir projectName projectVersion archOption
unset paraviewInstall scotchArchPath
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help | --help)
usage
;;
-foamInstall | --foamInstall)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
foamInstDir="$2"
# Replace FOAM_INST_DIR=...
_inlineSed \
etc/bashrc \
'\(.*BASH_SOURCE.*\)' \
'#\1' \
"Removing default FOAM_INST_DIR setting"
_inlineSed \
etc/bashrc \
'^export FOAM_INST_DIR=.*' \
'export FOAM_INST_DIR='"$foamInstDir" \
"Setting FOAM_INST_DIR to '$foamInstDir'"
shift 2
;;
-projectName | --projectName)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
projectName="$2"
# replace WM_PROJECT_DIR=...
_inlineSed \
etc/bashrc \
'WM_PROJECT_DIR=.*' \
'WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/'"$projectName" \
"Replacing WM_PROJECT_DIR setting by $projectName"
shift 2
;;
--projectVersion)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
projectVersion="$2"
# replace WM_PROJECT_VERSION=...
echo "Replacing WM_PROJECT_VERSION setting by $projectVersion"
_inlineSed \
etc/bashrc \
'WM_PROJECT_VERSION=.*' \
'WM_PROJECT_VERSION='"$projectVersion" \
"Replacing WM_PROJECT_VERSION setting by $projectVersion"
shift 2
;;
-archOption | --archOption)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
archOption="$2"
current_archOption=`grep WM_ARCH_OPTION= etc/bashrc | sed "s/export WM_ARCH_OPTION=//"`
if [ "$archOption" != "$current_archOption" ]
then
# replace WM_ARCH_OPTION=...
_inlineSed \
etc/bashrc \
'WM_ARCH_OPTION=.*' \
'WM_ARCH_OPTION='"$archOption" \
"Replacing WM_ARCH_OPTION setting by '$archOption'"
else
echo "WM_ARCH_OPTION already set to $archOption"
fi
shift 2
;;
-paraviewInstall | --paraviewInstall)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
paraviewInstall="$2"
# replace ParaView_DIR=...
_inlineSed \
etc/config.sh/paraview \
'ParaView_DIR=.*' \
'ParaView_DIR='"$paraviewInstall" \
"Replacing ParaView_DIR setting by '$paraviewInstall'"
shift 2
;;
-paraviewVersion | --paraviewVersion)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
paraviewVersion="$2"
# replace ParaView_VERSION=...
_inlineSed \
etc/config.sh/paraview \
'ParaView_VERSION=.*' \
'ParaView_VERSION='"$paraviewVersion" \
"Replacing ParaView_VERSION setting by '$paraviewVersion'"
shift 2
;;
-scotchVersion | --scotchVersion)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
scotchVersion="$2"
_inlineSed \
etc/config.sh/scotch \
'SCOTCH_VERSION=.*' \
'SCOTCH_VERSION='"$scotchVersion" \
"Replacing SCOTCH_VERSION setting by '$scotchVersion'"
shift 2
;;
-scotchArchPath | --scotchArchPath)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
scotchArchPath="$2"
_inlineSed \
etc/config.sh/scotch \
'SCOTCH_ARCH_PATH=.*' \
'SCOTCH_ARCH_PATH='"$scotchArchPath" \
"Replacing SCOTCH_ARCH_PATH setting by '$scotchArchPath'"
shift 2
;;
*)
usage "unknown option/argument: '$*'"
;;
esac
done
[ -n "$foamInstDir" -o -n "$projectName" -o -n "$projectVersion" -o -n "$archOption" \
-o -n "$paraviewInstall" -o -n "$paraviewVersion" \
-o -n "$scotchVersion" -o -n "$scotchArchPath" \
] || usage "Please specify at least one configure option"
#echo "Replacing WM_PROJECT setting by '$projectName'"
#sed -i -e 's@WM_PROJECT=.*@WM_PROJECT='"$projectName@" etc/bashrc
# Set WM_MPLIB=SYSTEMOPENMPI always
_inlineSed \
etc/bashrc \
'export WM_MPLIB=.*' \
'export WM_MPLIB=SYSTEMOPENMPI' \
"Replacing WM_MPLIB setting by 'SYSTEMOPENMPI'"
## set WM_COMPILER_TYPE=system always
#_inlineSed \
# etc/bashrc \
# 'WM_COMPILER_TYPE=.*' \
# 'WM_COMPILER_TYPE=system' \
# "Replacing WM_COMPILER_TYPE setting by 'system'"
#------------------------------------------------------------------------------
|