Skip to content

Commit a810f75

Browse files
committed
introduce keyword arguments
1 parent 6b6ab86 commit a810f75

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

juhpc

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
# - optionally executing a site-specific post installation julia script, using the project where preferences were set (e.g, to modify preferences or to create an uenv view equivalent to the activation script).
99

1010

11-
# Define info, error, cleanup, check functions and julia call for setting preferences
11+
# Define log, info, error, cleanup, check functions and julia call for setting preferences
12+
13+
export JUHPC_SETUP_INSTALLLOG="./hpc_setup_install.log" # must be defined at the very beginning
1214

1315
export JUHPC="\e[1;34m[\e[0m \e[1;35mJ\e[0m\e[1;32mU\e[0m\e[1;31mH\e[0m\e[1;31mP\e[0m\e[1;31mC\e[0m\e[1;34m:\e[0m"
1416

@@ -103,20 +105,35 @@ progress_bar() {
103105
}
104106

105107

106-
# Assign passed arguments to environment variables
108+
# Assign positional arguments and set default values for keyword arguments
107109

108110
export JUHPC_SETUP_INSTALLDIR="$1"
109111
export JULIAUP_INSTALLDIR="$2"
110-
export JUHPC_POST_INSTALL_JL="$3"
112+
export JUHPC_POST_INSTALL_JL=""
113+
export JUHPC_VERBOSE=0
114+
115+
116+
# Check positional arguments
117+
118+
check_var "JUHPC_SETUP_INSTALLDIR" "JULIAUP_INSTALLDIR"
119+
if [[ "$JULIAUP_INSTALLDIR" == "$JUHPC_SETUP_INSTALLDIR" ]]; then
120+
error "JULIAUP_INSTALLDIR and JUHPC_SETUP_INSTALLDIR cannot have the same value."
121+
fi
122+
check_dir "$JUHPC_SETUP_INSTALLDIR"
111123

112124

113-
# Check/set environment variables for logging and defining verbosity of output
125+
# Parse and check the keyword arguments
114126

115-
export JUHPC_SETUP_INSTALLLOG="$JUHPC_SETUP_INSTALLDIR/setup_install.log" # Need to be defined at the very beginning
127+
shift 2
128+
for arg in "$@"; do
129+
case $arg in
130+
postinstall=*) export JUHPC_POST_INSTALL_JL="${arg#*=}" ;;
131+
verbose=*) export JUHPC_VERBOSE="${arg#*=}" ;;
132+
*) error "Unknown argument: $arg" ;;
133+
esac
134+
done
116135

117-
if [[ -z "$JUHPC_VERBOSE" ]]; then
118-
export JUHPC_VERBOSE=0
119-
elif ! [[ "$JUHPC_VERBOSE" =~ ^[0-2]$ ]]; then
136+
if ! [[ "$JUHPC_VERBOSE" =~ ^[0-2]$ ]]; then
120137
error "JUHPC_VERBOSE must be between 0 and 2."
121138
fi
122139

@@ -133,21 +150,16 @@ else
133150
error "Neither /dev/shm nor /tmp directories exist. Cannot set TMP environment variable."
134151
fi
135152

136-
mkdir -p "$TMP" || { error "failed to create directory: $TMP"; }
137153
export TMP_JULIAUP_ROOTDIR="$TMP/juliaup"
138154

139155

140156
# Start installation
141157

142158
print_logo
143159
info "Starting installation of HPC setup for juliaup, julia and HPC key packages requiring system libraries..."
144-
check_var "JULIAUP_INSTALLDIR" "JUHPC_SETUP_INSTALLDIR"
145-
check_dir "$JUHPC_SETUP_INSTALLDIR"
146-
mkdir -p "$JUHPC_SETUP_INSTALLDIR" || { error "failed to create directory: $JUHPC_SETUP_INSTALLDIR"; }
147160

148-
if [[ "$JULIAUP_INSTALLDIR" == "$JUHPC_SETUP_INSTALLDIR" ]]; then
149-
error "JULIAUP_INSTALLDIR and JUHPC_SETUP_INSTALLDIR cannot have the same value."
150-
fi
161+
mkdir -p "$TMP" || { error "failed to create directory: $TMP"; }
162+
mkdir -p "$JUHPC_SETUP_INSTALLDIR" || { error "failed to create directory: $JUHPC_SETUP_INSTALLDIR"; }
151163

152164

153165
# Download and install julia in /tmp using juliaup
@@ -333,9 +345,7 @@ info "... done: activate script created."
333345

334346
if [ -n "${JUHPC_POST_INSTALL_JL}" ]; then
335347
info "Executing site-specific post-installation julia script (using the project where preferences were set)..."
336-
progress_bar 1 # Initialize progress bar.
337-
julia --project="$JULIA_PREFDIR" "$JUHPC_POST_INSTALL_JL"
338-
progress_bar 100 # Finalize progress bar.
348+
julia --project="$JULIA_PREFDIR" "$JUHPC_POST_INSTALL_JL" 2>&1 | tee -a "$JUHPC_SETUP_INSTALLLOG"
339349
info "... done: post-installation script completed."
340350
fi
341351

@@ -344,5 +354,6 @@ fi
344354

345355
cleanup
346356
mv "$JULIA_PREFDIR/Manifest.toml" "$JULIA_PREFDIR/Manifest.toml.bak" || { error "failed to move Manifest.toml in $JULIA_PREFDIR"; }
357+
mv "$JUHPC_SETUP_INSTALLLOG" "$JUHPC_SETUP_INSTALLDIR/" || { error "failed to move $JUHPC_SETUP_INSTALLLOG to $JUHPC_SETUP_INSTALLDIR"; }
347358

348359
info "... The installation of the HPC setup for juliaup, julia and HPC key packages is complete.\n\n"

0 commit comments

Comments
 (0)