-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare_spack.sh
executable file
·128 lines (101 loc) · 2.76 KB
/
prepare_spack.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
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
#!/bin/bash
cd `dirname $0`
. ./common.sh
usage="
Prepares spack repository. Does not require root priviledges if git is present.
Usage:
$(basename $0) [--user <username>] [--spack-location <spack_path>] [--spack-mirror <spack_mirror>] [--pre-install <spack_package_name1>] [--pre-install <spack_package_name2>]...
[--help] [--debug] [--log <output file>]
where
--user - Username to install the spack to. Defaults to the current user.
--spack-location - Name of the directory to install spack into. Defaults to ~/tmp/spack
--spack_mirror - Location of local spack mirror
--pre-install - Name of the spack packages that will be installed in sequence
--debug - Flag that sets debugging mode.
--log - Path to the log file that will log all meaningful commands
Example2:
$(basename $0) --debug --spack-mirror /media/adam-minipc/other/spack-mirror
"
if [ -z "$1" ]; then
echo "$usage" >&2
exit 0
fi
set -x
spack_location="auto"
spack_mirror=""
pre_install=()
user="$USER"
while [[ $# > 0 ]]
do
key="$1"
shift
case $key in
--debug)
debug=1
;;
--log)
log=$1
shift
;;
--help)
echo "$usage"
exit 0
;;
--user)
user="$1"
shift
;;
--spack-location)
spack_location="$1"
shift
;;
--spack-mirror)
spack_mirror="$1"
shift
;;
--pre-install)
pre_install+=("$1")
shift
;;
-*)
echo "Error: Unknown option: $1" >&2
echo "$usage" >&2
exit 1
;;
esac
done
install_apt_packages git python
#. Install spack
need_bootstrap=0
if [[ "${spack_location}" == "auto" ]]; then
spack_location=$(get_home_dir ${user})/tmp/spack
fi
if [ ! -f "${spack_location}/share/spack/setup-env.sh" ]; then
need_bootstrap=1
fi
get_git_repo https://github.com/spack/spack $(dirname ${spack_location}) $(basename ${spack_location}) ${user}
tmpscript=$(mktemp --suffix=.sh)
echo "#!/bin/bash" > ${tmpscript}
echo "source \"${spack_location}/share/spack/setup-env.sh\"" >> ${tmpscript}
source "${spack_location}/share/spack/setup-env.sh"
if [ "$spack_mirror" != "" ]; then
if ! spack mirror list | grep ${spack_mirror} >/dev/null; then
if spack mirror list | grep "^custom_mirror " >/dev/null; then
echo "spack mirror remove custom_mirror" >> ${tmpscript}
fi
pattern='^file:/(/.*)$'
if [[ $spack_mirror =~ $pattern ]]; then
spack_mirror="${BASH_REMATCH[1]}"
fi
echo "spack mirror add custom_mirror file://${spack_mirror}" >> ${tmpscript}
fi
fi
spack compiler find
if [ "$need_bootstrap" == "1" ]; then
echo "spack bootstrap" >> ${tmpscript}
echo "source \"${spack_location}/share/spack/setup-env.sh\"" >> ${tmpscript}
fi
for spack_mod in ${pre_install[*]}; do
echo "spack install ${spack_mod}" >> ${tmpscript}
done
sudo -u ${user} bash -x ${tmpscript}