-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
86 lines (72 loc) · 2.58 KB
/
setup.sh
File metadata and controls
86 lines (72 loc) · 2.58 KB
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
#!/usr/bin/env bash
action() {
# set python path in current directory
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PYTHONPATH="${this_dir}:${PYTHONPATH}"
export LAW_HOME="${this_dir}/.law"
export LAW_CONFIG_FILE="${this_dir}/law.cfg"
# set input and output directories
CONFIG_FILE="${this_dir}/.config"
# Function to read the output directory from the config file
read_config() {
if [[ -f $CONFIG_FILE ]]; then
source $CONFIG_FILE
else
export OUTPUT_DIR=""
export DATA_DIR=""
fi
}
# Function to write the input and output directory to the config file
write_config() {
echo "export OUTPUT_DIR=\"$OUTPUT_DIR\"" > $CONFIG_FILE
echo "export DATA_DIR=\"$DATA_DIR\"" >> $CONFIG_FILE
echo "Configuration saved to $CONFIG_FILE"
}
# Prompt user for input if OUTPUT_DIR and DATA_DIR are not set
prompt_user() {
echo -n "Enter the output directory: "
read user_input1
echo -n "Enter the input directory: "
read user_input2
if [[ -n $user_input1 && -n $user_input2 ]]; then
export OUTPUT_DIR="$user_input1"
export DATA_DIR="$user_input2"
else
echo "Invalid directories. Please try again."
prompt_user
fi
write_config
}
read_config
if [[ -z $OUTPUT_DIR ]]; then
echo "No output directory configured."
prompt_user
fi
# If no conda available, activate it
if ! command -v conda >/dev/null 2>&1; then
if [[ $(hostname) == "KK63XC4R3C" ]]; then
eval "$(/Users/nollde/miniforge3/bin/conda shell.bash hook)"
elif [[ -d "/opt/homebrew/Caskroom/mambaforge/base/bin/conda" ]]; then
eval "$(/opt/homebrew/Caskroom/mambaforge/base/bin/conda shell.bash hook)"
elif [[$NERSC_HOST == "perlmutter"]]; then
module load python
fi
fi
# If conda env "gbi_ranode" does not exist create it
if ! conda env list | grep -q '^gbi_ranode'; then
yes | conda create --name gbi_ranode
yes | conda env update -n gbi_ranode --file environment_mac.yml
fi
# Source conda env
conda activate gbi_ranode
# Enable autocompletion for law
source "$( law completion )" ""
echo ""
echo "✓ GBI environment activated!"
echo " Python: $(python --version)"
echo " Environment: ${CONDA_PREFIX}"
echo " Working directory: ${this_dir}"
echo " Output directory: ${OUTPUT_DIR}"
echo " Data directory: ${DATA_DIR}"
}
action