Files
minecraft_server_zombie/sync_instance_with_server.sh

68 lines
1.7 KiB
Bash

#!/bin/bash
# Configuration
REPO_URL="https://github.com/Teddy-1024/minecraft_server_zombie.git"
SYNC_FOLDERS="mods config kubejs defaultconfigs scripts resources patchouli_books pfm modernfix"
# Clear screen and show header
clear
echo "Minecraft Server Sync Tool"
echo "========================"
echo
# Check if git is installed
if ! command -v git &> /dev/null; then
echo "Git is not installed."
echo "Please install Git using your distribution's package manager"
echo "For example: sudo apt install git"
read -p "Press Enter to exit..."
exit 1
fi
# Create a temporary directory for the git operations
TEMP_GIT_DIR="/tmp/mc_git_sync"
rm -rf "$TEMP_GIT_DIR"
mkdir -p "$TEMP_GIT_DIR"
cd "$TEMP_GIT_DIR"
# Initialize git repo
git init
git remote add origin "$REPO_URL"
git config core.sparseCheckout true
# Set up sparse checkout for selected folders
rm -f .git/info/sparse-checkout
for folder in $SYNC_FOLDERS; do
echo "$folder/" >> .git/info/sparse-checkout
done
# Fetch latest content
git fetch --depth 1 origin main
git checkout main
# Copy contents to instance folders
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
for folder in $SYNC_FOLDERS; do
if [ -d "$TEMP_GIT_DIR/$folder" ]; then
echo "Syncing $folder..."
# Create target directory if it doesn't exist
mkdir -p "$SCRIPT_DIR/$folder"
# Copy contents, updating only newer files
rsync -u -r "$TEMP_GIT_DIR/$folder/" "$SCRIPT_DIR/$folder/"
fi
done
# Clean up
cd "$SCRIPT_DIR"
rm -rf "$TEMP_GIT_DIR"
echo
echo "Sync completed successfully!"
echo
echo "This sync has:"
echo "- Updated all tracked files from the repository"
echo "- Preserved your local untracked files"
echo
read -p "Press Enter to exit..."