-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclone_optional.sh
More file actions
executable file
·54 lines (46 loc) · 1.54 KB
/
clone_optional.sh
File metadata and controls
executable file
·54 lines (46 loc) · 1.54 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
#!/usr/bin/env bash
set -e
if ! command -v yq &> /dev/null; then
echo "Installing yq..."
VERSION="v4.50.1"
PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
armv7l) ARCH="arm" ;;
*) echo "Unsupported arch: $ARCH" >&2; exit 1 ;;
esac
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/yq_${PLATFORM}_${ARCH} -O yq
sudo mv yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
fi
BASE_DIR=$(git rev-parse --show-toplevel)
CONFIG_FILE="$BASE_DIR/optional_repos.yaml"
IGNORE_FILE="$BASE_DIR/.gitignore"
if [ ! -f "$CONFIG_FILE" ]; then
echo "YAML config file not found: $CONFIG_FILE"
exit 1
fi
# iterate over each YAML entry
count=$(yq e 'length' "$CONFIG_FILE")
for i in $(seq 0 $((count - 1))); do
name=$(yq e ".[$i].name" "$CONFIG_FILE")
path=$(yq e ".[$i].path" "$CONFIG_FILE")
url=$(yq e ".[$i].url" "$CONFIG_FILE")
branch=$(yq e ".[$i].branch" "$CONFIG_FILE")
read -p "Clone $name? (y/N): " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
target="$BASE_DIR/$path"
if [ ! -d "$target" ]; then
echo "Cloning $name into $target..."
git clone --branch "$branch" "$url" "$target"
else
echo "$path already exists, skipping."
fi
if ! grep -qxF "${path}/" "$IGNORE_FILE" 2>/dev/null; then
echo "${path}/" >> "$IGNORE_FILE"
echo "Added ${path}/ to .gitignore"
fi
fi
done