Add update scripts
This commit is contained in:
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
REPO_URL="https://zerolands.duckdns.org/git/D3SXX/Minecraft-Server-1.21.1-Mods.git"
|
||||
BRANCH="main"
|
||||
|
||||
# ─── Install git if missing ───────────────────────────────────────────────────
|
||||
install_git() {
|
||||
if command -v apt-get &>/dev/null; then
|
||||
sudo apt-get update -qq && sudo apt-get install -y git
|
||||
elif command -v dnf &>/dev/null; then
|
||||
sudo dnf install -y git
|
||||
elif command -v yum &>/dev/null; then
|
||||
sudo yum install -y git
|
||||
elif command -v pacman &>/dev/null; then
|
||||
sudo pacman -Sy --noconfirm git
|
||||
elif command -v zypper &>/dev/null; then
|
||||
sudo zypper install -y git
|
||||
elif command -v apk &>/dev/null; then
|
||||
sudo apk add --no-cache git
|
||||
elif command -v brew &>/dev/null; then
|
||||
brew install git
|
||||
else
|
||||
echo "ERROR: Could not detect a supported package manager. Install git manually."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
if ! command -v git &>/dev/null; then
|
||||
echo "git not found. Attempting to install..."
|
||||
install_git
|
||||
fi
|
||||
|
||||
# ─── Move to the directory containing this script ────────────────────────────
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# ─── Initialise repo if .git is missing ──────────────────────────────────────
|
||||
if [ ! -d ".git" ]; then
|
||||
echo "Initialising git repository..."
|
||||
git init
|
||||
git remote add origin "$REPO_URL"
|
||||
else
|
||||
# Ensure remote URL is correct
|
||||
git remote set-url origin "$REPO_URL" 2>/dev/null || git remote add origin "$REPO_URL"
|
||||
fi
|
||||
|
||||
# ─── Full reset ────────────────────────────────
|
||||
echo "Fetching latest mods from $REPO_URL ..."
|
||||
git fetch --all --prune
|
||||
|
||||
echo "Resetting to origin/$BRANCH ..."
|
||||
git checkout -B "$BRANCH" "origin/$BRANCH" --
|
||||
git reset --hard "origin/$BRANCH"
|
||||
git clean -fd
|
||||
|
||||
echo "Mods updated successfully."
|
||||
Reference in New Issue
Block a user