forked from Exawind/exawind-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-env.sh
executable file
·95 lines (78 loc) · 2.07 KB
/
create-env.sh
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
#!/bin/bash
# Create a script that can be source to initialize an environment
exw_show_help ()
{
cat <<EOF
$(basename ${BASH_SOURCE[0]}) [options] [output_file_name]
By default it will create a file called exawind-env-\$COMPILER.sh
Options:
-h - Show help message and exit
-s <system> - Select system profile (spack, cori, summitdev, etc.)
-c <compiler> - Select compiler type (gcc, clang, intel, etc.)
EOF
}
check_inputs ()
{
local dirname=${EXAWIND_SRCDIR}/$1
local value=$2
local option=$3
local tgt_file=${dirname}/${value}.bash
if [ ! -f ${tgt_file} ] ; then
echo "Invalid value provided for ${option} = ${value}. Valid options are
: "
for fname in $(ls ${dirname}); do
echo " - $(basename -s .bash $fname)"
done
err_stat=1
fi
}
# Get the source directory
EXAWIND_SRCDIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
# Set default options
system=spack
compiler=gcc
# Parse user options
OPTIND=1
while getopts ":s:c:h" opt; do
case "$opt" in
h)
exw_show_help
exit 0
;;
s)
system=$OPTARG
;;
c)
compiler=$OPTARG
;;
\?)
echo "ERROR: Invalid argument provided"
exw_show_help
exit 1
;;
esac
done
shift $((OPTIND-1))
[ "$1" == "--" ] && shift
err_stat=0
check_inputs envs ${system} "system"
if [[ err_stat -ne 0 ]] ; then
echo "Invalid options encountered, exiting now"
exit 1
fi
# Setup bash shebang for OSX
bash_shebang="/bin/bash"
if [ "$(uname)" = "Darwin" ] ; then
bash_shebang='/usr/local/bin/bash'
fi
# Output and template file
output_file=$1
tmpl_file=${EXAWIND_SRCDIR}/etc/env_tmpl.bash
if [ -z "$output_file" ]; then
output_file=exawind-env-${compiler}.sh
fi
sed -e "s#%%SRCDIR%%#${EXAWIND_SRCDIR}#g;s#%%COMPILER%%#${compiler}#g;s#%%SYSTEM%%#${system}#g;s#%%BASH_SHEBANG%%#${bash_shebang}#" $tmpl_file > $output_file
chmod a+x ${output_file}
cat <<EOF
==> Environment script ${output_file} created successfully.
EOF