maitri01 commited on
Commit
195496c
·
verified ·
1 Parent(s): 06ac404

Update hackathon_setup.sh

Browse files
Files changed (1) hide show
  1. hackathon_setup.sh +43 -300
hackathon_setup.sh CHANGED
@@ -1,32 +1,31 @@
1
  #!/bin/bash
2
  # =============================================================
3
- # Only team lead has to configure and run the setup script.
4
- # This is the Hackathon Full Environment Setup Script.
5
- # This creates shared folders, set permissions, download datasets, and prepare environments.
6
- # Make changes in CONFIGURATION section below before running this script:
7
- # 1) for property OWNER: add your user name from Juelich (as a team lead) and add the user names of your teammates
8
- # 2) create the team folder using the team lead username
9
- # Run with: source hackathon_setup.sh
 
 
 
 
 
 
 
 
 
10
  # =============================================================
11
 
12
  # =============================================================
13
- # CONFIGURATION — edit before running
14
  # =============================================================
15
-
16
- # Your JUDOOR username (folder owner)
17
- OWNER="" # Your Juelich username
18
-
19
- # Teammates (1 to 3, leave unused ones blank "")
20
- TEAMMATE_1="" # Your teammates' Juelich usernames. Leave unused as it is
21
  TEAMMATE_2=""
22
  TEAMMATE_3=""
23
-
24
- # Your personal folder in $SCRATCH (created first, locked to you + team)
25
- YOUR_FOLDER="" # <-- replace with your username
26
-
27
- # Team folder inside your folder (shared with teammates)
28
- TEAM_FOLDER="" # <-- replace with your team_name
29
-
30
  # =============================================================
31
 
32
  RED='\033[0;31m'
@@ -45,21 +44,29 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
45
  exit 1
46
  fi
47
 
 
 
 
 
 
 
 
 
 
48
 
49
- # HuggingFace datasets to download (org/repo format)
50
  HF_DATASETS=(
51
  "SprintML/MGI"
52
  "SprintML/FL_Data_Reconstruction"
53
  "SprintML/watermark_localization"
54
  )
55
 
56
- # =============================================================
57
-
58
- SCRATCH_BASE="/p/scratch/training2625"
59
- YOUR_DIR="$SCRATCH_BASE/$YOUR_FOLDER"
60
- TEAM_DIR="$YOUR_DIR/$TEAM_FOLDER"
61
 
62
- # Build teammates array — skip any blank entries
63
  TEAMMATES=()
64
  for t in "$TEAMMATE_1" "$TEAMMATE_2" "$TEAMMATE_3"; do
65
  [[ -n "$t" ]] && TEAMMATES+=("$t")
@@ -70,284 +77,20 @@ if [[ "${#TEAMMATES[@]}" -eq 0 ]]; then
70
  return 1
71
  fi
72
 
73
- echo ""
74
- echo "============================================="
75
- echo " Hackathon Environment Setup"
76
- echo "============================================="
77
- echo ""
78
- echo " Owner : $OWNER"
79
- echo " Teammates : ${TEAMMATES[*]}"
80
- echo " Your folder: $YOUR_DIR"
81
- echo " Team folder: $TEAM_DIR"
82
- echo ""
83
-
84
- # -------------------------------------------------------------
85
- # STEP 1: Check cluster
86
- # -------------------------------------------------------------
87
- _log "Step 1/6 - Checking cluster environment..."
88
-
89
- if ! command -v jutil &> /dev/null; then
90
- _error "jutil not found. Are you on JURECA?"
91
- echo " SSH in: ssh <username>@jureca.fz-juelich.de"
92
- return 1
93
- fi
94
- _ok "jutil found — on JURECA."
95
-
96
- # -------------------------------------------------------------
97
- # STEP 2: Activate project
98
- # -------------------------------------------------------------
99
- _log "Step 2/6 - Activating project training2625..."
100
-
101
- jutil env activate -p training2625
102
-
103
- if [[ -z "$PROJECT" ]]; then
104
- _error "\$PROJECT empty after activation."
105
- echo " Try manually: jutil env activate -p training2625"
106
- return 1
107
- fi
108
- _ok "Project activated. \$PROJECT = $PROJECT"
109
-
110
- # -------------------------------------------------------------
111
- # STEP 3: Create folders
112
- # -------------------------------------------------------------
113
- _log "Step 3/6 - Creating folders in scratch..."
114
-
115
- cd "$SCRATCH_BASE" || { _error "Cannot cd to $SCRATCH_BASE"; return 1; }
116
-
117
- if [[ -d "$YOUR_FOLDER" ]]; then
118
- _warn "Folder $YOUR_FOLDER already exists. Skipping mkdir."
119
- else
120
- mkdir "$YOUR_FOLDER"
121
- _ok "Created $YOUR_FOLDER"
122
- fi
123
-
124
-
125
- if [[ -d "$TEAM_DIR" ]]; then
126
- _warn "Team folder $TEAM_FOLDER already exists. Skipping mkdir."
127
- else
128
- mkdir "$TEAM_DIR"
129
- _ok "Created $TEAM_FOLDER inside $YOUR_FOLDER."
130
- fi
131
-
132
- chmod g+s "$YOUR_DIR"
133
-
134
- # -------------------------------------------------------------
135
- # STEP 4: Set ACLs — owner + teammates get full access
136
- # -------------------------------------------------------------
137
-
138
- _log "Step 4/6 - Setting ACLs on $YOUR_DIR ..."
139
-
140
- _lock_down_tree() {
141
- local dir="$1"
142
-
143
- # Restrict the top-level directory itself
144
- setfacl -m g::--- "$dir"
145
- setfacl -m o::--- "$dir"
146
- setfacl -m m:rwx "$dir"
147
-
148
- # Restrict everything that already exists inside
149
- setfacl -R -m g::--- "$dir"
150
- setfacl -R -m o::--- "$dir"
151
- setfacl -R -m m:rwx "$dir"
152
-
153
- # Restrictive defaults for all new files/subdirs
154
- setfacl -d -m g::--- "$dir"
155
- setfacl -d -m o::--- "$dir"
156
- setfacl -d -m m:rwx "$dir"
157
-
158
- # Apply default ACLs to all existing subdirectories too
159
- find "$dir" -type d -exec setfacl -d -m g::--- {} \;
160
- find "$dir" -type d -exec setfacl -d -m o::--- {} \;
161
- find "$dir" -type d -exec setfacl -d -m m:rwx {} \;
162
- }
163
-
164
- _grant_user_access() {
165
- local uname="$1"
166
- local dir="$2"
167
-
168
- # Current directory + existing tree
169
- setfacl -m u:"$uname":rwx "$dir"
170
- setfacl -R -m u:"$uname":rwx "$dir"
171
-
172
- # Default ACLs for future files/subdirs
173
- setfacl -d -m u:"$uname":rwx "$dir"
174
- find "$dir" -type d -exec setfacl -d -m u:"$uname":rwx {} \;
175
- }
176
-
177
- _lock_down_tree "$YOUR_DIR"
178
-
179
- for uname in "$OWNER" "${TEAMMATES[@]}"; do
180
- _log " Granting access to: $uname"
181
- _grant_user_access "$uname" "$YOUR_DIR"
182
- _ok " ACL set for $uname"
183
- done
184
-
185
- setfacl -R -m m:rwx "$YOUR_DIR"
186
- setfacl -R -d -m m:rwx "$YOUR_DIR"
187
-
188
- _log "Final ACL for owner folder:"
189
- getfacl "$YOUR_DIR"
190
-
191
- _log "Final ACL for team folder:"
192
- getfacl "$TEAM_DIR"
193
-
194
- # -------------------------------------------------------------
195
- # STEP 5: Install uv + configure shared cache
196
- # -------------------------------------------------------------
197
- _log "Step 5/6 - Installing uv and configuring shared cache..."
198
-
199
- if command -v uv &> /dev/null; then
200
- _warn "uv already installed. Skipping."
201
- else
202
- curl -LsSf https://astral.sh/uv/install.sh | sh
203
- if [[ -f "$HOME/.local/bin/env" ]]; then
204
- source "$HOME/.local/bin/env"
205
- _ok "uv installed."
206
- else
207
- _error "uv install finished but env file not found."
208
  return 1
209
  fi
210
- fi
211
-
212
- UV_BASE="$TEAM_DIR/.uv"
213
- HF_CACHE="$TEAM_DIR/.cache"
214
- mkdir -p "$UV_BASE" "$HF_CACHE"
215
-
216
- if grep -q "UV_CACHE_DIR.*$TEAM_FOLDER" ~/.bashrc; then
217
- _warn "uv/HF cache config already in ~/.bashrc. Skipping."
218
- else
219
- cat << EOF >> ~/.bashrc
220
-
221
- # uv + HF cache config — shared team env (added by hackathon_setup.sh)
222
- export UV_CACHE_DIR=$UV_BASE/cache
223
- export UV_TOOL_DIR=$UV_BASE/tools
224
- export UV_PYTHON_INSTALL_DIR=$UV_BASE/python
225
- export HF_HOME=$HF_CACHE
226
- export HUGGINGFACE_HUB_CACHE=$HF_CACHE/hub
227
- EOF
228
- _ok "uv + HF cache paths written to ~/.bashrc"
229
- fi
230
-
231
- export UV_CACHE_DIR="$UV_BASE/cache"
232
- export UV_TOOL_DIR="$UV_BASE/tools"
233
- export UV_PYTHON_INSTALL_DIR="$UV_BASE/python"
234
- export HF_HOME="$HF_CACHE"
235
- export HUGGINGFACE_HUB_CACHE="$HF_CACHE/hub"
236
-
237
- # -------------------------------------------------------------
238
- # STEP 6: Download each dataset then create its per-task uv env
239
- # -------------------------------------------------------------
240
- _log "Step 6/6 - Downloading datasets and creating per-task environments..."
241
-
242
- if [[ -n "$HF_TOKEN" ]]; then
243
- _ok "HF_TOKEN found — will be used for authentication."
244
- else
245
- _log "No HF_TOKEN set — proceeding without (fine for public datasets)."
246
- fi
247
-
248
- # Bootstrap venv just for downloading — deleted after use
249
- BOOTSTRAP_VENV="$TEAM_DIR/.bootstrap"
250
- if [[ ! -d "$BOOTSTRAP_VENV" ]]; then
251
- _log "Creating bootstrap venv for downloads..."
252
- uv venv -p 3.12 "$BOOTSTRAP_VENV"
253
- VIRTUAL_ENV="$BOOTSTRAP_VENV" uv pip install huggingface_hub
254
- _ok "Bootstrap venv ready."
255
- else
256
- _warn "Bootstrap venv already exists. Skipping."
257
- fi
258
-
259
- BOOTSTRAP_PYTHON="$BOOTSTRAP_VENV/bin/python"
260
-
261
- for dataset in "${HF_DATASETS[@]}"; do
262
- dataset_name="${dataset##*/}"
263
- dest="$TEAM_DIR/$dataset_name"
264
- VENV_DIR="$dest/.venv"
265
- REQ="$dest/requirements.txt"
266
-
267
- echo ""
268
- _log "--- Task: $dataset_name ---"
269
-
270
- # 1. Download dataset
271
- if [[ -d "$dest" ]]; then
272
- _warn " Already downloaded. Skipping."
273
- else
274
- _log " Downloading $dataset..."
275
- "$BOOTSTRAP_PYTHON" - <<PYEOF
276
- import os
277
- from huggingface_hub import snapshot_download
278
- snapshot_download(
279
- repo_id="$dataset",
280
- repo_type="dataset",
281
- local_dir="$dest",
282
- token=os.environ.get("HF_TOKEN"),
283
- )
284
- PYEOF
285
- if [[ $? -ne 0 ]]; then
286
- _error " Download failed — skipping venv setup."
287
- continue
288
- fi
289
- _ok " Downloaded $dataset_name."
290
- fi
291
-
292
- # create output folder safely (always run)
293
- mkdir -p "$dest/output"
294
-
295
- # fix mask so both users can write
296
- setfacl -m m:rwx "$dest/output"
297
- setfacl -d -m m:rwx "$dest/output"
298
-
299
- # 2. Create proper per-task uv project + venv from requirements.txt
300
- if [[ -d "$VENV_DIR" ]]; then
301
- _warn " Venv already exists. Skipping."
302
- continue
303
- fi
304
-
305
- if [[ ! -f "$REQ" ]]; then
306
- _warn " No requirements.txt found in $dataset_name — skipping venv."
307
- continue
308
- fi
309
-
310
- _log " Setting up uv project for $dataset_name..."
311
- cd "$dest" || { _error " Cannot cd into $dest"; continue; }
312
-
313
- # Init uv project — creates pyproject.toml
314
- uv init -p 3.12 --no-workspace
315
-
316
- # Create venv inside task folder
317
- uv venv -p 3.12 "$VENV_DIR"
318
-
319
- # Parse requirements.txt: strip comments and blank lines
320
- DEPS=$(grep -v '^\s*#' "$REQ" | grep -v '^\s*$' | tr '\n' ' ')
321
-
322
- if [[ -z "$DEPS" ]]; then
323
- _warn " requirements.txt is empty — skipping uv add."
324
- else
325
- # uv add writes deps into pyproject.toml and generates uv.lock
326
- VIRTUAL_ENV="$VENV_DIR" uv add $DEPS && \
327
- _ok " Done: pyproject.toml + uv.lock + .venv ready." || \
328
- _error " Failed to install requirements for $dataset_name."
329
- fi
330
-
331
- cd "$TEAM_DIR"
332
  done
333
 
334
- # Clean up bootstrap venv — no trace left
335
- if [[ -d "$BOOTSTRAP_VENV" ]]; then
336
- rm -rf "$BOOTSTRAP_VENV"
337
- _ok "Bootstrap venv removed."
338
- fi
339
-
340
- # =============================================================
341
  echo ""
342
  echo "============================================="
343
- echo -e "${GREEN} Setup complete!${NC}"
344
  echo "============================================="
345
- echo " Team access : $OWNER + ${TEAMMATES[*]}"
346
- echo " uv : $(uv --version 2>&1)"
347
  echo ""
348
- echo " Activate a task env:"
349
- echo " source $TEAM_DIR/<dataset-name>/.venv/bin/activate"
350
- echo ""
351
- echo " Submit a job: sbatch job.sh"
352
- echo "============================================="
353
  echo ""
 
1
  #!/bin/bash
2
  # =============================================================
3
+ # HACKATHON SETUP: STEP 1 OF 2 - TEAM LEAD RUNS FIRST
4
+ # =============================================================
5
+ # EXECUTION ORDER (IMPORTANT):
6
+ # 1. The TEAM LEAD configures and runs THIS script first.
7
+ # Run: source hackathon_setup.sh
8
+ # Wait until it finishes successfully.
9
+ # 2. ONLY AFTER THAT, each remaining team member configures
10
+ # and runs teammate.sh from their own JURECA account.
11
+ # Run: source teammate.sh
12
+ #
13
+ # The team lead runs only this script. Teammates run only
14
+ # teammate.sh. Do not run both scripts from the same account.
15
+ #
16
+ # Before running, set TEAM_LEAD to your Juelich username,
17
+ # TEAMMATE_1 through TEAMMATE_3 to your teammates' Juelich
18
+ # usernames, and TEAM_FOLDER to the agreed team name.
19
  # =============================================================
20
 
21
  # =============================================================
22
+ # CONFIGURATION - TEAM LEAD EDITS THESE VALUES
23
  # =============================================================
24
+ TEAM_LEAD="" # Your Juelich username
25
+ TEAMMATE_1="" # Teammate's Juelich username; leave blank if unused
 
 
 
 
26
  TEAMMATE_2=""
27
  TEAMMATE_3=""
28
+ TEAM_FOLDER="" # Your team name; teammates must use the exact same value
 
 
 
 
 
 
29
  # =============================================================
30
 
31
  RED='\033[0;31m'
 
44
  exit 1
45
  fi
46
 
47
+ if [[ -z "$TEAM_LEAD" || -z "$TEAM_FOLDER" || "$TEAM_LEAD" == */* || "$TEAM_FOLDER" == */* || "$TEAM_FOLDER" == "." || "$TEAM_FOLDER" == ".." ]]; then
48
+ _error "Set valid TEAM_LEAD and TEAM_FOLDER values before running."
49
+ return 1
50
+ fi
51
+
52
+ if [[ "$TEAM_LEAD" != "$(id -un)" ]]; then
53
+ _error "TEAM_LEAD must match the username running this script: $(id -un)"
54
+ return 1
55
+ fi
56
 
57
+ # Hugging Face datasets to download (org/repo format)
58
  HF_DATASETS=(
59
  "SprintML/MGI"
60
  "SprintML/FL_Data_Reconstruction"
61
  "SprintML/watermark_localization"
62
  )
63
 
64
+ PROJECT_NAME="training2625"
65
+ SCRATCH_BASE="/p/scratch/$PROJECT_NAME"
66
+ TEAM_LEAD_DIR="$SCRATCH_BASE/$TEAM_LEAD"
67
+ TEAM_DIR="$TEAM_LEAD_DIR/$TEAM_FOLDER"
 
68
 
69
+ # Build teammates array, skipping blank entries
70
  TEAMMATES=()
71
  for t in "$TEAMMATE_1" "$TEAMMATE_2" "$TEAMMATE_3"; do
72
  [[ -n "$t" ]] && TEAMMATES+=("$t")
 
77
  return 1
78
  fi
79
 
80
+ for t in "${TEAMMATES[@]}"; do
81
+ if [[ "$t" == */* || "$t" == "$TEAM_LEAD" ]]; then
82
+ _error "Invalid teammate username: $t"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  return 1
84
  fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  done
86
 
 
 
 
 
 
 
 
87
  echo ""
88
  echo "============================================="
89
+ echo " Hackathon Setup - Team Lead (Step 1/2)"
90
  echo "============================================="
 
 
91
  echo ""
92
+ echo " Team lead : $TEAM_LEAD"
93
+ echo " Teammates : ${TEAMMATES[*]}"
94
+ echo " Lead folder : $TEAM_LEAD_DIR"
95
+ echo " Team folder : $TEAM_DIR"
 
96
  echo ""