pathScripts/up

70 lines
1.8 KiB
Text
Raw Normal View History

2024-06-23 22:47:43 +02:00
#!/bin/bash
# Path to the file containing the list of repositories
REPOS_FILE=~/workshop/repos.txt
2024-06-23 22:47:43 +02:00
# Check if the repos file exists
if [ ! -f "$REPOS_FILE" ]; then
echo "Error: $REPOS_FILE does not exist."
exit 1
fi
2024-06-23 22:47:43 +02:00
# Read the repos file and process each directory
while IFS= read -r repo_path || [[ -n "$repo_path" ]]; do
# Trim whitespace
repo_path=$(echo "$repo_path" | xargs)
2024-06-23 22:47:43 +02:00
# Skip empty lines
[ -z "$repo_path" ] && continue
2024-06-23 22:47:43 +02:00
# Expand tilde to home directory
repo_path="${repo_path/#\~/$HOME}"
2024-06-23 22:47:43 +02:00
# Check if the directory exists
if [ ! -d "$repo_path" ]; then
echo "Warning: Directory $repo_path does not exist. Skipping."
continue
fi
echo "Processing repository: $repo_path"
# Navigate to the project directory
cd "$repo_path" || { echo "Error: Unable to change to directory $repo_path"; continue; }
# Check if it's a git repository
if [ ! -d .git ]; then
echo "Warning: $repo_path is not a git repository. Skipping."
continue
fi
# Get the current branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
# Pull the latest changes from the repository
echo "Pulling from $current_branch branch..."
git pull origin "$current_branch"
# Add changes to the Git index (staging area)
echo "Adding all changes..."
git add .
# Check if there are changes to commit
if git diff-index --quiet HEAD --; then
echo "No changes to commit."
else
# Commit changes
echo "Committing changes..."
git commit -m "Auto-update: $(date)"
# Push changes to the remote repository
echo "Pushing all changes..."
git push origin "$current_branch"
fi
echo "Update complete for $repo_path!"
echo "----------------------------------------"
done < "$REPOS_FILE"
echo "All repositories processed."
2024-06-23 22:47:43 +02:00