-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathget-code.sh
More file actions
executable file
·47 lines (40 loc) · 1.27 KB
/
get-code.sh
File metadata and controls
executable file
·47 lines (40 loc) · 1.27 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
#!/bin/sh
set -e
clone_or_update_repo() {
owner="$1"
repo="$2"
release="$3"
target_dir="lib/$repo"
if [ -d "$target_dir" ]; then
printf "Updating %s" "$target_dir"
(cd "$target_dir" && git fetch -q origin)
else
printf "Cloning %s (gh:%s/%s)" "$target_dir" "$owner" "$repo"
git clone -q "https://github.com/$owner/$repo" "$target_dir"
(
cd "$target_dir"
git remote add github "git@github.com:$owner/$repo"
)
fi
printf "."
printf " Updating to %s" "$release"
(
cd "$target_dir"
if ! git checkout -q "$release" 2>/dev/null &&
! git checkout -q "origin/$release" 2>/dev/null; then
echo "Failed to checkout $release for $repo. Falling back to master/main."
exit 1
fi
)
echo "."
}
grep 'CPMAddPackage' CMakeLists.txt | while IFS= read -r line; do
parsed=$(echo "$line" | sed -n \
's/.*CPMAddPackage("gh:\([^/]*\)\/\([^#]*\)#\([^"]*\)".*/\1 \2 \3/p')
if [ -n "$parsed" ]; then
owner=$(echo "$parsed" | awk '{print $1}')
repo=$(echo "$parsed" | awk '{print $2}')
release=$(echo "$parsed" | awk '{print $3}')
clone_or_update_repo "$owner" "$repo" "$release"
fi
done