Skip to content

Commit 60e19d2

Browse files
authored
Move scripts to new folder (#14)
1 parent 0d4b3c3 commit 60e19d2

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

.devcontainer/postcreate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ git config devcontainers-theme.show-dirty 1
66
sudo chown -R $(whoami): /home/vscode/.microsoft
77
sudo chown -R $(whoami): /mnt/data/
88

9-
sudo chmod +x .devcontainer/clone-repos.sh
10-
.devcontainer/clone-repos.sh
9+
sudo chmod +x scripts/clone-repos.sh
10+
scripts/clone-repos.sh
1111

1212
dotnet tool install -g Aspire.Cli
1313
dotnet dev-certs https --trust
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
MANIFEST=.devcontainer/repos.json
4+
MANIFEST=scripts/repos.json
55

66
jq -c '.groups[]' $MANIFEST | while read group; do
77
GROUP=$(echo $group | jq -r .name)

scripts/fetch-repos.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ROOT_DIR="/mnt/data/crucible"
6+
MAX_DEPTH=2
7+
FETCH_ARGS=("$@")
8+
9+
if [[ ! -d "$ROOT_DIR" ]]; then
10+
echo "Directory not found: $ROOT_DIR" >&2
11+
exit 1
12+
fi
13+
14+
fetch_repository() {
15+
local dir=$1
16+
if git -C "$dir" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
17+
echo "Fetching updates in $dir"
18+
git -C "$dir" fetch "${FETCH_ARGS[@]}"
19+
return 0
20+
fi
21+
return 1
22+
}
23+
24+
# Traverse directories up to MAX_DEPTH and stop descending once a repo is fetched.
25+
traverse_directory() {
26+
local dir=$1
27+
local depth=$2
28+
29+
if fetch_repository "$dir"; then
30+
return 0
31+
fi
32+
33+
if (( depth >= MAX_DEPTH )); then
34+
echo "Skipping $dir (not a git repository)"
35+
return 1
36+
fi
37+
38+
local repo_found=1
39+
40+
while IFS= read -r -d '' subdir; do
41+
if traverse_directory "$subdir" $((depth + 1)); then
42+
repo_found=0
43+
fi
44+
done < <(
45+
find "$dir" \
46+
-mindepth 1 \
47+
-maxdepth 1 \
48+
-type d \
49+
-not -path '*/.git*' \
50+
-print0
51+
)
52+
53+
if (( repo_found )); then
54+
echo "Skipping $dir (not a git repository)"
55+
return 1
56+
fi
57+
58+
return 0
59+
}
60+
61+
while IFS= read -r -d '' path; do
62+
traverse_directory "$path" 1
63+
done < <(
64+
find "$ROOT_DIR" \
65+
-mindepth 1 \
66+
-maxdepth 1 \
67+
-type d \
68+
-not -path '*/.git*' \
69+
-print0
70+
)

0 commit comments

Comments
 (0)