generic-keyword-finder/10_update-repos.sh
2025-10-02 00:06:20 +02:00

48 lines
No EOL
963 B
Bash
Executable file

#!/bin/bash
set -e
REPO_LIST="./10_git-repos-source-list"
DEST_DIR="./10_repos"
if [ ! -f "$REPO_LIST" ]; then
echo "Error: $REPO_LIST not found"
exit 1
fi
mkdir -p "$DEST_DIR"
while IFS= read -r line; do
line=$(echo "$line" | tr -d '\r\n' | sed 's/[[:space:]]*$//')
if [ -z "$line" ]; then
continue
fi
if [[ ! "$line" =~ ^https?:// ]]; then
echo "Skipping invalid URL: $line"
continue
fi
repo_name=$(basename "$line" .git)
repo_path="$DEST_DIR/$repo_name"
echo "Processing: $line"
if [ -d "$repo_path" ]; then
echo " Updating existing repo: $repo_name"
cd "$repo_path"
git fetch origin
git reset --hard origin/main
cd - > /dev/null
else
echo " Cloning new repo: $repo_name"
git clone "$line" "$repo_path"
fi
echo " Done: $repo_name"
echo ""
done < "$REPO_LIST"
echo "All repositories updated successfully!"