Skip to content

Commit 88e15e8

Browse files
committed
Improve robustness
1 parent 2784457 commit 88e15e8

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

juhpc

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export JUHPC_POST_INSTALL_JL="$3"
7979

8080
# Set (derived) general environment variables
8181

82-
export JULIAUP_BINDIR=$JULIAUP_INSTALLDIR/bin # juliaup and julia binaries
82+
export JULIAUP_BINDIR="$JULIAUP_INSTALLDIR/bin" # juliaup and julia binaries
8383

8484
if [ -d "/dev/shm" ]; then
8585
export TMP="/dev/shm/$USER"
@@ -89,7 +89,7 @@ else
8989
error "Neither /dev/shm nor /tmp directories exist. Cannot set TMP environment variable."
9090
fi
9191

92-
export TMP_JULIAUP_ROOTDIR=$TMP/juliaup
92+
export TMP_JULIAUP_ROOTDIR="$TMP/juliaup"
9393

9494

9595
# Start installation
@@ -103,87 +103,87 @@ check_dir "$JUHPC_SETUP_INSTALLDIR"
103103
# Download and install julia in /tmp using juliaup
104104

105105
INFO_MSG="Installing temporary juliaup installation in $TMP_JULIAUP_ROOTDIR"
106-
info_start $INFO_MSG
106+
info_start "$INFO_MSG"
107107

108-
export TMP_JULIAUP_BINDIR=$TMP_JULIAUP_ROOTDIR/bin # juliaup and julia binaries
109-
export JULIAUP_DEPOT_PATH=$TMP_JULIAUP_ROOTDIR/depot
110-
export JULIA_DEPOT_PATH=$TMP_JULIAUP_ROOTDIR/depot
111-
export JULIA_PROJECT=$JULIA_DEPOT_PATH/environments/latest
108+
export TMP_JULIAUP_BINDIR="$TMP_JULIAUP_ROOTDIR/bin" # juliaup and julia binaries
109+
export JULIAUP_DEPOT_PATH="$TMP_JULIAUP_ROOTDIR/depot"
110+
export JULIA_DEPOT_PATH="$TMP_JULIAUP_ROOTDIR/depot"
111+
export JULIA_PROJECT="$JULIA_DEPOT_PATH/environments/latest"
112112
export PATH=$(echo $PATH | perl -pe "s|[^:]*julia(?:up)?[^:]*:?||g") # Remove all juliaup paths from PATH
113113
export PATH=$TMP_JULIAUP_BINDIR:$PATH
114114

115115
check_dir "$TMP_JULIAUP_ROOTDIR"
116-
curl -fsSL https://install.julialang.org | sh -s -- --add-to-path=no --yes --path=$TMP_JULIAUP_ROOTDIR --background-selfupdate 0 --startup-selfupdate 0 || { error "failed to install Juliaup (and Julia) in $TMP_JULIAUP_ROOTDIR."; }
116+
curl -fsSL https://install.julialang.org | sh -s -- --add-to-path=no --yes --path="$TMP_JULIAUP_ROOTDIR" --background-selfupdate 0 --startup-selfupdate 0 || { error "failed to install Juliaup (and Julia) in $TMP_JULIAUP_ROOTDIR."; }
117117

118118
if [ ! -f "$TMP_JULIAUP_BINDIR/juliaup" ]; then error "temporary juliaup installation failed."; fi
119119

120-
info_end $INFO_MSG
120+
info_end "$INFO_MSG"
121121

122122

123123
# Create preferences for HPC key packages that require system libraries (MPI.jl, CUDA.jl, AMDGPU.jl, HDF5.jl, ADIOS2.jl, ...)
124124

125125
INFO_MSG="Creating preferences for HPC key packages"
126-
info_start $INFO_MSG
126+
info_start "$INFO_MSG"
127127

128-
export JULIA_PREFDIR=$JUHPC_SETUP_INSTALLDIR/julia_preferences
129-
export JULIA_PREF_PROJECT=$JULIA_PREFDIR/Project.toml
128+
export JULIA_PREFDIR="$JUHPC_SETUP_INSTALLDIR/julia_preferences"
129+
export JULIA_PREF_PROJECT="$JULIA_PREFDIR/Project.toml"
130130
mkdir -p "$JULIA_PREFDIR" || { error "failed to create directory: $JULIA_PREFDIR"; }
131131

132132
if [[ -n "${JUHPC_CUDA_HOME}" || -n "${JUHPC_ROCM_HOME}" ]]; then
133-
julia --project=$JULIA_PREFDIR -e 'using Pkg; Pkg.add("Preferences")'
134-
echo "[extras]" >> $JULIA_PREF_PROJECT
133+
julia --project="$JULIA_PREFDIR" -e 'using Pkg; Pkg.add("Preferences")'
134+
echo "[extras]" >> "$JULIA_PREF_PROJECT"
135135
fi
136136

137137
if [ -n "${JUHPC_CUDA_HOME}" ]; then # Set preference for using the local CUDA runtime before any installation of CUDA.jl to avoid downloading of artifacts
138-
echo 'CUDA_Runtime_jll = "76a88914-d11a-5bdc-97e0-2f5a05c973a2"' >> $JULIA_PREF_PROJECT
138+
echo 'CUDA_Runtime_jll = "76a88914-d11a-5bdc-97e0-2f5a05c973a2"' >> "$JULIA_PREF_PROJECT"
139139

140-
julia --project=$JULIA_PREFDIR -e 'using Preferences; set_preferences!("CUDA_Runtime_jll", "local"=>true)'
140+
julia --project="$JULIA_PREFDIR" -e 'using Preferences; set_preferences!("CUDA_Runtime_jll", "local"=>true)'
141141
if [ -n "${JUHPC_CUDA_RUNTIME_VERSION}" ]; then
142-
julia --project=$JULIA_PREFDIR -e 'using Preferences; set_preferences!("CUDA_Runtime_jll", "version"=>join(split(ENV["JUHPC_CUDA_RUNTIME_VERSION"],".")[1:2],"."))'
142+
julia --project="$JULIA_PREFDIR" -e 'using Preferences; set_preferences!("CUDA_Runtime_jll", "version"=>join(split(ENV["JUHPC_CUDA_RUNTIME_VERSION"],".")[1:2],"."))'
143143
fi
144144
fi
145145

146146
if [ -n "${JUHPC_ROCM_HOME}" ]; then # Set preference for using the local ROCm runtime before any installation of AMDGPU.jl to avoid downloading of artifacts
147-
echo 'AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"' >> $JULIA_PREF_PROJECT
147+
echo 'AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"' >> "$JULIA_PREF_PROJECT"
148148

149-
julia --project=$JULIA_PREFDIR -e 'using Preferences; set_preferences!("AMDGPU", "use_artifacts"=>false, "eager_gc"=>false)'
149+
julia --project="$JULIA_PREFDIR" -e 'using Preferences; set_preferences!("AMDGPU", "use_artifacts"=>false, "eager_gc"=>false)'
150150
fi
151151

152-
if [ -n "${JUHPC_CUDA_HOME}" ]; then export CUDA_HOME=$JUHPC_CUDA_HOME; fi
153-
if [ -n "${JUHPC_ROCM_HOME}" ]; then export ROCM_PATH=$JUHPC_ROCM_HOME; fi
152+
if [ -n "${JUHPC_CUDA_HOME}" ]; then export CUDA_HOME="$JUHPC_CUDA_HOME"; fi
153+
if [ -n "${JUHPC_ROCM_HOME}" ]; then export ROCM_PATH="$JUHPC_ROCM_HOME"; fi
154154

155-
julia --project=$JULIA_PREFDIR -e 'using Pkg; Pkg.add([p for (p,l) in [("MPIPreferences", "JUHPC_MPI_VENDOR"), ("MPIPreferences", "JUHPC_MPI_HOME"), ("CUDA", "JUHPC_CUDA_HOME"), ("AMDGPU", "JUHPC_ROCM_HOME"), ("HDF5", "JUHPC_HDF5_HOME")] if haskey(ENV,l) && ENV[l]!=""])'
155+
julia --project="$JULIA_PREFDIR" -e 'using Pkg; Pkg.add([p for (p,l) in [("MPIPreferences", "JUHPC_MPI_VENDOR"), ("MPIPreferences", "JUHPC_MPI_HOME"), ("CUDA", "JUHPC_CUDA_HOME"), ("AMDGPU", "JUHPC_ROCM_HOME"), ("HDF5", "JUHPC_HDF5_HOME")] if haskey(ENV,l) && ENV[l]!=""])'
156156

157157
if [ -n "${JUHPC_CUDA_HOME}" ]; then # Set preference for using the local CUDA runtime in a more stable way (in case the previous would not be valid anymore)
158-
julia --project=$JULIA_PREFDIR -e 'using CUDA; CUDA.set_runtime_version!((VersionNumber(join(split(ENV[key],".")[1:2],".")) for key in ["JUHPC_CUDA_RUNTIME_VERSION"] if haskey(ENV,key) && ENV[key]!=="")...; local_toolkit=true)'
158+
julia --project="$JULIA_PREFDIR" -e 'using CUDA; CUDA.set_runtime_version!((VersionNumber(join(split(ENV[key],".")[1:2],".")) for key in ["JUHPC_CUDA_RUNTIME_VERSION"] if haskey(ENV,key) && ENV[key]!=="")...; local_toolkit=true)'
159159
fi
160160

161161
if [ -n "${JUHPC_ROCM_HOME}" ]; then # Set preference for using the local ROCm runtime in a more stable way (in case the previous would not be valid anymore)
162-
julia --project=$JULIA_PREFDIR -e 'using AMDGPU; AMDGPU.ROCmDiscovery.use_artifacts!(false)'
162+
julia --project="$JULIA_PREFDIR" -e 'using AMDGPU; AMDGPU.ROCmDiscovery.use_artifacts!(false)'
163163
fi
164164

165165
if [ -n "${JUHPC_MPI_VENDOR}" ]; then
166166
check_var "JUHPC_MPI_EXEC"
167-
julia --project=$JULIA_PREFDIR -e 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), vendor=ENV["JUHPC_MPI_VENDOR"])'
167+
julia --project="$JULIA_PREFDIR" -e 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), vendor=ENV["JUHPC_MPI_VENDOR"])'
168168
elif [ -n "${JUHPC_MPI_HOME}" ]; then
169169
check_var "JUHPC_MPI_EXEC"
170-
julia --project=$JULIA_PREFDIR -e 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), extra_paths=["$(ENV["JUHPC_MPI_HOME"])/lib"])'
170+
julia --project="$JULIA_PREFDIR" -e 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), extra_paths=["$(ENV["JUHPC_MPI_HOME"])/lib"])'
171171
fi
172172

173173
if [ -n "${JUHPC_HDF5_HOME}" ]; then
174-
julia --project=$JULIA_PREFDIR -e 'using HDF5; HDF5.API.set_libraries!("$(ENV["JUHPC_HDF5_HOME"])/lib/libhdf5.so", "$(ENV["JUHPC_HDF5_HOME"])/lib/libhdf5_hl.so")'
174+
julia --project="$JULIA_PREFDIR" -e 'using HDF5; HDF5.API.set_libraries!("$(ENV["JUHPC_HDF5_HOME"])/lib/libhdf5.so", "$(ENV["JUHPC_HDF5_HOME"])/lib/libhdf5_hl.so")'
175175
fi
176176

177-
info_end $INFO_MSG
177+
info_end "$INFO_MSG"
178178

179179

180180
# Create a wrapper for juliaup that installs juliaup (and latest julia) on scratch if it is not already installed
181181

182182
INFO_MSG="Creating wrapper for juliaup"
183-
info_start $INFO_MSG
183+
info_start "$INFO_MSG"
184184

185-
export JULIAUP_WRAPPER_BINDIR=$JUHPC_SETUP_INSTALLDIR/juliaup_wrapper
186-
export JULIAUP_WRAPPER=$JULIAUP_WRAPPER_BINDIR/juliaup
185+
export JULIAUP_WRAPPER_BINDIR="$JUHPC_SETUP_INSTALLDIR/juliaup_wrapper"
186+
export JULIAUP_WRAPPER="$JULIAUP_WRAPPER_BINDIR/juliaup"
187187
mkdir -p "$JULIAUP_WRAPPER_BINDIR" || { error "failed to create directory: $JULIAUP_WRAPPER_BINDIR"; }
188188

189189
julia -e '
@@ -198,83 +198,83 @@ info() {
198198
echo -e "$(ENV["JUHPC"]) \$message" >&2
199199
}
200200
201-
JULIAUP_EXE=$(ENV["JULIAUP_BINDIR"])/juliaup
201+
exportJULIAUP_EXE="$(ENV["JULIAUP_BINDIR"])/juliaup"
202202
203203
if [ ! -f "$JULIAUP_EXE" ]; then
204204
print_logo
205205
info "This is the first call to juliaup; juliaup and the latest julia will now be installed. After that, you can use juliaup and julia normally. Installing in $(ENV["JULIAUP_INSTALLDIR"])..."
206206
sleep 3
207-
PATH_OLD=\$PATH
207+
PATH_OLD="\$PATH"
208208
export PATH=\$(echo \$PATH | perl -pe "s|[^:]*juliaup(?:_wrapper)?[^:]*:?||g") # Remove all juliaup paths from PATH
209-
curl -fsSL https://install.julialang.org | sh -s -- --add-to-path=no --yes --path=$(ENV["JULIAUP_INSTALLDIR"]) --background-selfupdate 0 --startup-selfupdate 0 || { echo "Failed to install Juliaup (and Julia)." >&2; exit 1; }
210-
export PATH=\$PATH_OLD
209+
curl -fsSL https://install.julialang.org | sh -s -- --add-to-path=no --yes --path="$(ENV["JULIAUP_INSTALLDIR"])" --background-selfupdate 0 --startup-selfupdate 0 || { echo "Failed to install Juliaup (and Julia)." >&2; exit 1; }
210+
export PATH="\$PATH_OLD"
211211
if [ ! -f "$JULIAUP_EXE" ]; then error "juliaup installation failed."; fi
212212
info "... done. Installation of juliaup and the latest julia in $(ENV["JULIAUP_INSTALLDIR"]) completed. You can use juliaup and julia normally."
213213
else
214-
$JULIAUP_EXE \$@
214+
"$JULIAUP_EXE" \$@
215215
fi
216216
""")
217-
' > $JULIAUP_WRAPPER
218-
chmod +x $JULIAUP_WRAPPER
217+
' > "$JULIAUP_WRAPPER"
218+
chmod +x "$JULIAUP_WRAPPER"
219219

220-
info_end $INFO_MSG
220+
info_end "$INFO_MSG"
221221

222222

223223
# Create an activation script that sets environment variables for juliaup, julia and HPC key packages
224224

225225
INFO_MSG="Creating activation script"
226-
info_start $INFO_MSG
226+
info_start "$INFO_MSG"
227227

228-
export JULIAUP_DEPOT=$JULIAUP_INSTALLDIR/depot
229-
export JULIA_DEPOT=$JULIAUP_INSTALLDIR/depot
230-
export ACTIVATE_SCRIPT=$JUHPC_SETUP_INSTALLDIR/activate
228+
export JULIAUP_DEPOT="$JULIAUP_INSTALLDIR/depot"
229+
export JULIA_DEPOT="$JULIAUP_INSTALLDIR/depot"
230+
export ACTIVATE_SCRIPT="$JUHPC_SETUP_INSTALLDIR/activate"
231231

232232
julia -e 'println("""
233233
info() {
234234
local message="\$1"
235235
echo -e "$(ENV["JUHPC"]) \$message" >&2
236236
}
237237
info "Activating HPC setup for juliaup, julia and HPC key packages requiring system libraries..."
238-
export PATH=$(ENV["JULIAUP_WRAPPER_BINDIR"]):$(ENV["JULIAUP_BINDIR"]):\$PATH # The wrapper must be before the juliaup bindir
238+
export PATH="$(ENV["JULIAUP_WRAPPER_BINDIR"]):$(ENV["JULIAUP_BINDIR"]):\$PATH" # The wrapper must be before the juliaup bindir
239239
info "PATH: \$PATH"
240-
export JULIAUP_DEPOT_PATH=$(ENV["JULIAUP_DEPOT"])
240+
export JULIAUP_DEPOT_PATH="$(ENV["JULIAUP_DEPOT"])"
241241
info "JULIAUP_DEPOT_PATH: \$JULIAUP_DEPOT_PATH"
242-
export JULIA_DEPOT_PATH=$(ENV["JULIA_DEPOT"])
242+
export JULIA_DEPOT_PATH="$(ENV["JULIA_DEPOT"])"
243243
info "JULIA_DEPOT_PATH: \$JULIA_DEPOT_PATH"
244-
export JULIA_LOAD_PATH=:$(ENV["JULIA_PREFDIR"])
244+
export JULIA_LOAD_PATH=":$(ENV["JULIA_PREFDIR"])"
245245
info "JULIA_LOAD_PATH: \$JULIA_LOAD_PATH"
246246
$(haskey(ENV,"JUHPC_CUDA_HOME") && ENV["JUHPC_CUDA_HOME"] != "" ? """
247-
export CUDA_HOME=$(ENV["JUHPC_CUDA_HOME"])
247+
export CUDA_HOME="$(ENV["JUHPC_CUDA_HOME"])"
248248
info "CUDA_HOME: \$CUDA_HOME"
249249
export JULIA_CUDA_MEMORY_POOL=none
250250
info "JULIA_CUDA_MEMORY_POOL: \$JULIA_CUDA_MEMORY_POOL"
251251
""" : "")
252252
$(haskey(ENV,"JUHPC_ROCM_HOME") && ENV["JUHPC_ROCM_HOME"] != "" ? """
253-
export ROCM_PATH=$(ENV["JUHPC_ROCM_HOME"])
253+
export ROCM_PATH="$(ENV["JUHPC_ROCM_HOME"])"
254254
info "ROCM_PATH: \$ROCM_PATH"
255255
""" : "")
256256
$(haskey(ENV,"JUHPC_ADIOS2_HOME") && ENV["JUHPC_ADIOS2_HOME"] != "" ? """
257-
export JULIA_ADIOS2_PATH=$(ENV["JUHPC_ADIOS2_HOME"])
257+
export JULIA_ADIOS2_PATH="$(ENV["JUHPC_ADIOS2_HOME"])"
258258
info "JULIA_ADIOS2_PATH: \$JULIA_ADIOS2_PATH"
259259
""" : "")
260-
""")' > $ACTIVATE_SCRIPT
260+
""")' > "$ACTIVATE_SCRIPT"
261261

262-
info_end $INFO_MSG
262+
info_end "$INFO_MSG"
263263

264264

265265
# Optionally execute a site-specific post installation julia script (if passed a third argument)
266266

267267
if [ -n "${JUHPC_POST_INSTALL_JL}" ]; then
268268
INFO_MSG="Executing site-specific post installation julia script (using the project where preferences were set)"
269-
info_start $INFO_MSG
270-
julia --project=$JULIA_PREFDIR $JUHPC_POST_INSTALL_JL
271-
info_end $INFO_MSG
269+
info_start "$INFO_MSG"
270+
julia --project="$JULIA_PREFDIR" "$JUHPC_POST_INSTALL_JL"
271+
info_end "$INFO_MSG"
272272
fi
273273

274274

275275
# Remove temporary juliaup installation and Manifest.toml in the preferences directory
276276

277277
cleanup
278-
rm -f $JULIA_PREFDIR/Manifest.toml
278+
rm -f "$JULIA_PREFDIR/Manifest.toml"
279279

280280
info "... Installation of HPC setup for juliaup, julia and HPC key packages requiring system libraries is complete.\n\n"

0 commit comments

Comments
 (0)