From 425236d9960a12ceaf58260f155307cda7011abb Mon Sep 17 00:00:00 2001 From: Vlad Rumiantsev <9647752d@gmail.com> Date: Sat, 9 May 2026 11:16:45 +0000 Subject: [PATCH] Add update scripts --- update_mods.bat | 49 ++++++++++++++++++++++++++++++++++++++++++ update_mods.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 update_mods.bat create mode 100755 update_mods.sh diff --git a/update_mods.bat b/update_mods.bat new file mode 100644 index 0000000..bcf4504 --- /dev/null +++ b/update_mods.bat @@ -0,0 +1,49 @@ +@echo off +setlocal EnableDelayedExpansion + +set "REPO_URL=https://zerolands.duckdns.org/git/D3SXX/Minecraft-Server-1.21.1-Mods.git" +set "BRANCH=main" + +:: ─── Check / install git ───────────────────────────────────────────────────── +where git >nul 2>&1 +if %errorlevel% neq 0 ( + echo git not found. Installing via winget... + winget install --id Git.Git -e --source winget + if %errorlevel% neq 0 ( + echo ERROR: winget failed to install git. Install git manually and re-run. + pause + exit /b 1 + ) + :: Reload PATH so git is available in the same session + for /f "tokens=*" %%i in ('where git 2^>nul') do set "GIT_EXE=%%i" + if "!GIT_EXE!"=="" ( + echo git was installed but is not yet on PATH. Please restart this script. + pause + exit /b 1 + ) +) + +:: ─── Move to the directory containing this script ──────────────────────────── +cd /d "%~dp0" + +:: ─── Initialise repo if .git is missing ────────────────────────────────────── +if not exist ".git\" ( + echo Initialising git repository... + git init + git remote add origin "%REPO_URL%" +) else ( + git remote set-url origin "%REPO_URL%" 2>nul || git remote add origin "%REPO_URL%" +) + +:: ─── 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. +echo Mods updated successfully. +pause diff --git a/update_mods.sh b/update_mods.sh new file mode 100755 index 0000000..14b661d --- /dev/null +++ b/update_mods.sh @@ -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."