maitri01 commited on
Commit
c334927
·
verified ·
1 Parent(s): 07bc07f

Update hackathon_setup.sh

Browse files
Files changed (1) hide show
  1. hackathon_setup.sh +257 -1
hackathon_setup.sh CHANGED
@@ -1,3 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  _log "Step 6/6 - Downloading datasets and creating per-task environments..."
2
 
3
  if [[ -n "$HF_TOKEN" ]]; then
@@ -111,4 +367,4 @@ echo " source $TEAM_DIR/<dataset-name>/.venv/bin/activate"
111
  echo ""
112
  echo " Submit a job: sbatch job.sh"
113
  echo "============================================="
114
- 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'
32
+ GREEN='\033[0;32m'
33
+ YELLOW='\033[1;33m'
34
+ BLUE='\033[0;34m'
35
+ NC='\033[0m'
36
+
37
+ _log() { echo -e "${BLUE}[INFO]${NC} $1"; }
38
+ _ok() { echo -e "${GREEN}[OK]${NC} $1"; }
39
+ _warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
40
+ _error() { echo -e "${RED}[ERROR]${NC} $1"; }
41
+
42
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
43
+ _error "This script must be sourced: source hackathon_setup.sh"
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")
73
+ done
74
+
75
+ if [[ "${#TEAMMATES[@]}" -eq 0 ]]; then
76
+ _error "No teammates specified. Add at least one."
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 ""
97
+
98
+ # -------------------------------------------------------------
99
+ # STEP 1: Check cluster
100
+ # -------------------------------------------------------------
101
+ _log "Step 1/6 - Checking cluster environment..."
102
+
103
+ if ! command -v jutil &> /dev/null; then
104
+ _error "jutil not found. Are you on JURECA?"
105
+ echo " SSH in: ssh <username>@jureca.fz-juelich.de"
106
+ return 1
107
+ fi
108
+ _ok "jutil found - on JURECA."
109
+
110
+ # -------------------------------------------------------------
111
+ # STEP 2: Activate project
112
+ # -------------------------------------------------------------
113
+ _log "Step 2/6 - Activating project $PROJECT_NAME..."
114
+
115
+ if ! jutil env activate -p "$PROJECT_NAME"; then
116
+ _error "Could not activate project $PROJECT_NAME."
117
+ return 1
118
+ fi
119
+
120
+ if [[ -z "$PROJECT" ]]; then
121
+ _error '\$PROJECT empty after activation.'
122
+ echo " Try manually: jutil env activate -p $PROJECT_NAME"
123
+ return 1
124
+ fi
125
+ _ok "Project activated. \$PROJECT = $PROJECT"
126
+
127
+ # -------------------------------------------------------------
128
+ # STEP 3: Create folders
129
+ # -------------------------------------------------------------
130
+ _log "Step 3/6 - Creating folders in scratch..."
131
+
132
+ cd "$SCRATCH_BASE" || { _error "Cannot cd to $SCRATCH_BASE"; return 1; }
133
+
134
+ if [[ -d "$TEAM_LEAD_DIR" ]]; then
135
+ _warn "Team lead folder $TEAM_LEAD already exists. Skipping mkdir."
136
+ else
137
+ mkdir "$TEAM_LEAD_DIR" || { _error "Could not create $TEAM_LEAD_DIR"; return 1; }
138
+ _ok "Created $TEAM_LEAD_DIR"
139
+ fi
140
+
141
+ if [[ -d "$TEAM_DIR" ]]; then
142
+ _warn "Team folder $TEAM_FOLDER already exists. Skipping mkdir."
143
+ else
144
+ mkdir "$TEAM_DIR" || { _error "Could not create $TEAM_DIR"; return 1; }
145
+ _ok "Created $TEAM_FOLDER inside $TEAM_LEAD."
146
+ fi
147
+
148
+ chmod g+s "$TEAM_LEAD_DIR" || { _error "Could not set directory group inheritance."; return 1; }
149
+
150
+ # -------------------------------------------------------------
151
+ # STEP 4: Set ACLs - team lead + teammates get full access
152
+ # -------------------------------------------------------------
153
+ _log "Step 4/6 - Setting ACLs on $TEAM_LEAD_DIR ..."
154
+
155
+ _lock_down_tree() {
156
+ local dir="$1"
157
+
158
+ # Restrict the top-level directory itself and all existing contents
159
+ setfacl -m g::--- "$dir" || return 1
160
+ setfacl -m o::--- "$dir" || return 1
161
+ setfacl -R -m g::--- "$dir" || return 1
162
+ setfacl -R -m o::--- "$dir" || return 1
163
+
164
+ # Restrict default access on existing and future subdirectories
165
+ find "$dir" -type d -exec setfacl -d -m g::--- {} + || return 1
166
+ find "$dir" -type d -exec setfacl -d -m o::--- {} + || return 1
167
+ }
168
+
169
+ _grant_user_access() {
170
+ local uname="$1"
171
+ local dir="$2"
172
+
173
+ # Existing directory tree
174
+ setfacl -R -m "u:$uname:rwx" "$dir" || return 1
175
+
176
+ # Default ACLs for new files and subdirectories
177
+ find "$dir" -type d -exec setfacl -d -m "u:$uname:rwx" {} + || return 1
178
+ }
179
+
180
+ if ! _lock_down_tree "$TEAM_LEAD_DIR"; then
181
+ _error "Could not restrict the team lead directory."
182
+ return 1
183
+ fi
184
+
185
+ for uname in "$TEAM_LEAD" "${TEAMMATES[@]}"; do
186
+ _log " Granting access to: $uname"
187
+ if ! _grant_user_access "$uname" "$TEAM_LEAD_DIR"; then
188
+ _error "Could not grant ACL permissions to $uname."
189
+ return 1
190
+ fi
191
+ _ok " ACL set for $uname"
192
+ done
193
+
194
+ # Ensure ACL named-user entries have an effective rwx mask.
195
+ setfacl -R -m m:rwx "$TEAM_LEAD_DIR" || return 1
196
+ find "$TEAM_LEAD_DIR" -type d -exec setfacl -d -m m:rwx {} + || return 1
197
+
198
+ _log "Final ACL for team lead folder:"
199
+ getfacl "$TEAM_LEAD_DIR"
200
+
201
+ _log "Final ACL for team folder:"
202
+ getfacl "$TEAM_DIR"
203
+
204
+ # -------------------------------------------------------------
205
+ # STEP 5: Install uv + configure shared cache
206
+ # -------------------------------------------------------------
207
+ _log "Step 5/6 - Installing uv and configuring shared cache..."
208
+
209
+ if command -v uv &> /dev/null; then
210
+ _warn "uv already installed. Skipping."
211
+ else
212
+ if ! curl -LsSf https://astral.sh/uv/install.sh | sh; then
213
+ _error "uv installation failed."
214
+ return 1
215
+ fi
216
+ if [[ -f "$HOME/.local/bin/env" ]]; then
217
+ source "$HOME/.local/bin/env"
218
+ fi
219
+ export PATH="$HOME/.local/bin:$PATH"
220
+ if ! command -v uv &> /dev/null; then
221
+ _error "uv is still unavailable after installation."
222
+ return 1
223
+ fi
224
+ _ok "uv installed."
225
+ fi
226
+
227
+ UV_BASE="$TEAM_DIR/.uv"
228
+ HF_CACHE="$TEAM_DIR/.cache"
229
+ mkdir -p "$UV_BASE" "$HF_CACHE" || return 1
230
+
231
+ # The marker makes the configuration check exact and repeat-safe.
232
+ if grep -Fq "TEAM SHARED UV/HF CONFIG: $TEAM_DIR" "$HOME/.bashrc" 2>/dev/null; then
233
+ _warn "uv/HF cache config already in ~/.bashrc. Skipping."
234
+ else
235
+ cat <<EOF >> "$HOME/.bashrc"
236
+
237
+ # TEAM SHARED UV/HF CONFIG: $TEAM_DIR
238
+ export PATH="\$HOME/.local/bin:\$PATH"
239
+ export UV_CACHE_DIR="$UV_BASE/cache"
240
+ export UV_TOOL_DIR="$UV_BASE/tools"
241
+ export UV_PYTHON_INSTALL_DIR="$UV_BASE/python"
242
+ export HF_HOME="$HF_CACHE"
243
+ export HUGGINGFACE_HUB_CACHE="$HF_CACHE/hub"
244
+ EOF
245
+ _ok "uv + HF cache paths written to ~/.bashrc"
246
+ fi
247
+
248
+ export UV_CACHE_DIR="$UV_BASE/cache"
249
+ export UV_TOOL_DIR="$UV_BASE/tools"
250
+ export UV_PYTHON_INSTALL_DIR="$UV_BASE/python"
251
+ export HF_HOME="$HF_CACHE"
252
+ export HUGGINGFACE_HUB_CACHE="$HF_CACHE/hub"
253
+
254
+ # -------------------------------------------------------------
255
+ # STEP 6: Download each dataset then create its per-task uv env
256
+ # -------------------------------------------------------------
257
  _log "Step 6/6 - Downloading datasets and creating per-task environments..."
258
 
259
  if [[ -n "$HF_TOKEN" ]]; then
 
367
  echo ""
368
  echo " Submit a job: sbatch job.sh"
369
  echo "============================================="
370
+ echo ""