From 3db356d228533b397cb234a03d93ed437988ac7e Mon Sep 17 00:00:00 2001 From: virtualWinter Date: Fri, 21 Jul 2023 04:52:21 +0300 Subject: [PATCH] Initial commit + scripts from sportpaper --- .gitignore | 7 +++ .gitmodules | 7 +++ README.md | 3 ++ base/.upstream-state | 1 + base/Paper | 1 + builddata | 1 + mspigot | 80 ++++++++++++++++++++++++++++++++++ patches/api/.gitkeep | 0 patches/server/.gitkeep | 0 pom.xml | 33 ++++++++++++++ scripts/apply.sh | 62 ++++++++++++++++++++++++++ scripts/basedecompile.sh | 39 +++++++++++++++++ scripts/baseinit.sh | 44 +++++++++++++++++++ scripts/basenewApplyPatches.sh | 57 ++++++++++++++++++++++++ scripts/baseremap.sh | 79 +++++++++++++++++++++++++++++++++ scripts/generatesources.sh | 45 +++++++++++++++++++ scripts/importmcdev.sh | 68 +++++++++++++++++++++++++++++ scripts/init.sh | 46 +++++++++++++++++++ scripts/rebuildpatches.sh | 52 ++++++++++++++++++++++ scripts/upstream.sh | 71 ++++++++++++++++++++++++++++++ 20 files changed, 696 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 README.md create mode 100644 base/.upstream-state create mode 160000 base/Paper create mode 160000 builddata create mode 100644 mspigot create mode 100644 patches/api/.gitkeep create mode 100644 patches/server/.gitkeep create mode 100644 pom.xml create mode 100644 scripts/apply.sh create mode 100644 scripts/basedecompile.sh create mode 100644 scripts/baseinit.sh create mode 100644 scripts/basenewApplyPatches.sh create mode 100644 scripts/baseremap.sh create mode 100644 scripts/generatesources.sh create mode 100644 scripts/importmcdev.sh create mode 100644 scripts/init.sh create mode 100644 scripts/rebuildpatches.sh create mode 100644 scripts/upstream.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0006d19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/.idea/ +/.vscode/ +/base/mc-dev/ +/mSpigot-API/ +/mSpigot-Server/ +*.iml +*.DS_Store diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ab6b879 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,7 @@ +[submodule "base/Paper"] + path = base/Paper + url = https://git.sigmagaming.net/CatMC-Network/PaperSpigot-Parent.git + branch = ver/1.8.8 +[submodule "builddata"] + path = builddata + url = https://hub.spigotmc.org/stash/scm/spigot/builddata.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..9ab9e1d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# mSpigot + +mSpigot but 1.8.8 \ No newline at end of file diff --git a/base/.upstream-state b/base/.upstream-state new file mode 100644 index 0000000..bdbf577 --- /dev/null +++ b/base/.upstream-state @@ -0,0 +1 @@ +1.8.8--0af73b26380e0d6aab8b18e9f740e8a33ecec98b diff --git a/base/Paper b/base/Paper new file mode 160000 index 0000000..2894af0 --- /dev/null +++ b/base/Paper @@ -0,0 +1 @@ +Subproject commit 2894af04dc378d6a61e55e37a8c0b1a478c09c3d diff --git a/builddata b/builddata new file mode 160000 index 0000000..faff587 --- /dev/null +++ b/builddata @@ -0,0 +1 @@ +Subproject commit faff587dcbe915bc565bf01f2d54c6af86039414 diff --git a/mspigot b/mspigot new file mode 100644 index 0000000..6a6834d --- /dev/null +++ b/mspigot @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") +basedir=$(dirname "$SOURCE") + +. "$basedir/scripts/init.sh" + +paperstash() { + STASHED=$(git stash) +} + +paperunstash() { + if [[ "$STASHED" != "No local changes to save" ]] ; then + git stash pop + fi +} + +buildpaperclipjar() { + cp -f scripts/basepaperclip.sh base/Paper/paperclip.sh + cd base/Paper + ./paperclip.sh + cd "$basedir" +} + +case "$1" in + "setup") + cd "$basedir" + scripts/upstream.sh + ;; + "build") + log_info "Preparing to build mSpigot" + cd "$basedir" + scripts/upstream.sh + scripts/apply.sh "$basedir" + mvn --batch-mode clean install + # buildpaperclipjar + ;; + "rb" | "rbp" | "rebuild") + ( + set -e + cd "$basedir" + scripts/rebuildpatches.sh "$basedir" + ) + ;; + "p" | "patch" | "apply") + ( + set -e + cd "$basedir" + scripts/apply.sh "$basedir" + log_info " Run './mspigot jar' to create a runnable JAR." + ) + ;; + "j" | "jar") + ( + set -e + mvn --batch-mode clean install + # buildpaperclipjar + ) + ;; + *) + echo "mSpigot build tool." + echo "" + echo " Commands:" + echo " * setup | Setup the build environment" + echo " * build | Setup the build environment, apply patches, and create a runnable JAR" + echo " * p, patch | Apply patches" + echo " * rb, rebuild | Rebuild patches" + echo " * j, jar | Create a runnable JAR" + ;; +esac + +unset -f paperstash +unset -f paperunstash diff --git a/patches/api/.gitkeep b/patches/api/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/patches/server/.gitkeep b/patches/server/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fc397f2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + net.hylist + spigot-parent + dev-SNAPSHOT + pom + Production version of Spigot for Hylist servers. Ported to 1.8.8 + + + + sonatype-repo + https://oss.sonatype.org/content/groups/public + + + spigotmc-public + https://hub.spigotmc.org/nexus/content/groups/public + + + md_5-releases + http://repo.md-5.net/content/repositories/releases/ + + + + + UTF-8 + + + + mSpigot-API + mSpigot-Server + + diff --git a/scripts/apply.sh b/scripts/apply.sh new file mode 100644 index 0000000..e1a2359 --- /dev/null +++ b/scripts/apply.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +initScript=$(dirname "$SOURCE")/init.sh +. "$initScript" +PS1="$" + +paperVer=$(cat base/.upstream-state) +log_info "Applying mSpigot patches" +function applyPatch { + what=$1 + what_name=$(dirname "$what") + target=$2 + branch=$3 + patch_folder=$4 + + cd "$basedir/$what" + git fetch --all + git branch -f upstream "$branch" >/dev/null 2>&1 + + cd "$basedir" + if [ ! -d "$basedir/$target" ]; then + mkdir "$basedir/$target" + cd "$basedir/$target" + git init + cd "$basedir" + fi + cd "$basedir/$target" + echo "Resetting $target to $what_name..." + git remote rm upstream > /dev/null 2>&1 + git remote add upstream "$basedir/$what" >/dev/null 2>&1 + git checkout master 2>/dev/null || git checkout -b master + git fetch upstream >/dev/null 2>&1 + git reset --hard upstream/upstream + echo " Applying patches to $target..." + git am --abort >/dev/null 2>&1 + for patchFile in "$basedir/patches/$patch_folder/"*.patch + do + git am --3way --ignore-whitespace "$patchFile" + done + #git am --3way --ignore-whitespace "$basedir/patches/$patch_folder/*.patch" + if [ "$?" != "0" ]; then + echo " Something did not apply cleanly to $target." + echo " Please review above details and finish the apply then" + echo " save the changes with rebuildPatches.sh" + exit 1 + else + echo " Patches applied cleanly to $target" + fi +} + +log_info "Applying mSpigot API patches" +applyPatch base/Paper/PaperSpigot-API mSpigot-API HEAD api +log_info "Applying mSpigot server patches" +applyPatch base/Paper/PaperSpigot-Server mSpigot-Server HEAD server + +log_info "Patches successfully applied." diff --git a/scripts/basedecompile.sh b/scripts/basedecompile.sh new file mode 100644 index 0000000..07978f0 --- /dev/null +++ b/scripts/basedecompile.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") +basedir=$(dirname "$SOURCE") + +PS1="$" +workdir="$basedir/work" +minecraftversion="$(cat BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4)" +decompiledir="$workdir/$minecraftversion" +classdir="$decompiledir/classes" + +echo "Extracting NMS classes..." +if [ ! -d "$classdir" ]; then + mkdir -p "$classdir" + cd "$classdir" + jar xf "$decompiledir/$minecraftversion-mapped.jar" net/minecraft/server + if [ "$?" != "0" ]; then + cd "$basedir" + echo "Failed to extract NMS classes." + exit 1 + fi +fi + +echo "Decompiling classes..." +if [ ! -d "$decompiledir/net/minecraft/server" ]; then + cd "$basedir" + java -jar BuildData/bin/fernflower.jar -dgs=1 -hdc=0 -rbr=0 -asc=1 -udv=0 "$classdir" "$decompiledir" + if [ "$?" != "0" ]; then + echo "Failed to decompile classes." + exit 1 + fi +fi diff --git a/scripts/baseinit.sh b/scripts/baseinit.sh new file mode 100644 index 0000000..f492eae --- /dev/null +++ b/scripts/baseinit.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") +basedir=$(dirname "$SOURCE") + +PS1="$" +workdir="$basedir/work" +minecraftversion="$(cat BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4)" +decompiledir="$workdir/$minecraftversion" +nms="$decompiledir/net/minecraft/server" +cb=src/main/java/net/minecraft/server + +patch="$(which patch 2>/dev/null)" +if [ "x$patch" == "x" ]; then + patch="$basedir/hctap.exe" +fi + +echo "Applying CraftBukkit patches to NMS..." +cd "$basedir/CraftBukkit" +git checkout -B patched HEAD >/dev/null 2>&1 +rm -rf "$cb" +mkdir -p "$cb" +for file in $(ls nms-patches) +do + patchFile="nms-patches/$file" + file="$(echo $file | cut -d. -f1).java" + + echo "Patching $file < $patchFile" + sed -i'' -e 's/\r//' "$nms/$file" > /dev/null + + cp "$nms/$file" "$cb/$file" + "$patch" -s -d src/main/java/ "net/minecraft/server/$file" < "$patchFile" +done + +git add src >/dev/null 2>&1 +git commit -m "CraftBukkit $ $(date)" >/dev/null 2>&1 +git checkout -f HEAD^ >/dev/null 2>&1 diff --git a/scripts/basenewApplyPatches.sh b/scripts/basenewApplyPatches.sh new file mode 100644 index 0000000..116853b --- /dev/null +++ b/scripts/basenewApplyPatches.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") +basedir=$(dirname "$SOURCE") + +PS1="$" +applycmd="git am --3way --ignore-whitespace" +# Windows detection to workaround ARG_MAX limitation +windows="$([[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]] && echo "true" || echo "false")" +echo "Rebuilding Forked projects.... " + +function applyPatch { + what="$1" + target="$2" + branch="$3" + cd "$basedir/$what" + git fetch + git branch -f upstream "$branch" >/dev/null + + cd "$basedir" + if [ ! -d "$basedir/$target" ]; then + git clone "$what" "$target" + fi + cd "$basedir/$target" + echo "Resetting $target to $what..." + git remote add -f upstream ../$what >/dev/null 2>&1 + git checkout master >/dev/null 2>&1 + git fetch upstream >/dev/null 2>&1 + git reset --hard upstream/upstream + echo " Applying patches to $target..." + git am --abort >/dev/null 2>&1 + # Special case Windows handling because of ARG_MAX constraint + if [[ $windows == "true" ]]; then + echo " Using workaround for Windows ARG_MAX constraint" + find "$basedir/${what}-Patches/"*.patch -print0 | xargs -0 $applycmd + else + $applycmd "$basedir/${what}-Patches/"*.patch + fi + if [ "$?" != "0" ]; then + echo " Something did not apply cleanly to $target." + echo " Please review above details and finish the apply then" + echo " save the changes with rebuildPatches.sh" + exit 1 + else + echo " Patches applied cleanly to $target" + fi +} + +applyPatch Bukkit Spigot-API HEAD && applyPatch CraftBukkit Spigot-Server patched +applyPatch Spigot-API PaperSpigot-API HEAD && applyPatch Spigot-Server PaperSpigot-Server HEAD \ No newline at end of file diff --git a/scripts/baseremap.sh b/scripts/baseremap.sh new file mode 100644 index 0000000..9060098 --- /dev/null +++ b/scripts/baseremap.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") +basedir=$(dirname "$SOURCE") + +PS1="$" +workdir="$basedir/work" +minecraftversion="$(cat BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4)" +minecrafthash="$(cat BuildData/info.json | grep minecraftHash | cut -d '"' -f 4)" +accesstransforms="BuildData/mappings/$(cat BuildData/info.json | grep accessTransforms | cut -d '"' -f 4)" +classmappings="BuildData/mappings/$(cat BuildData/info.json | grep classMappings | cut -d '"' -f 4)" +membermappings="BuildData/mappings/$(cat BuildData/info.json | grep memberMappings | cut -d '"' -f 4)" +packagemappings="BuildData/mappings/$(cat BuildData/info.json | grep packageMappings | cut -d '"' -f 4)" +jarpath="$workdir/$minecraftversion/$minecraftversion" + +echo "Downloading unmapped vanilla jar..." +if [ ! -f "$jarpath.jar" ]; then + mkdir -p "$workdir/$minecraftversion" + curl -s -o "$jarpath.jar" "https://launcher.mojang.com/v1/objects/5fafba3f58c40dc51b5c3ca72a98f62dfdae1db7/server.jar" + if [ "$?" != "0" ]; then + echo "Failed to download the vanilla server jar. Check connectivity or try again later." + exit 1 + fi +fi + +# OS X doesn't have md5sum, just md5 -r +if [[ "$OSTYPE" == "darwin"* ]]; then + shopt -s expand_aliases + alias md5sum='md5 -r' + echo "Using an alias for md5sum on OS X" +fi + +checksum="$(md5sum "$jarpath.jar" | cut -d ' ' -f 1)" +if [ "$checksum" != "$minecrafthash" ]; then + echo "The MD5 checksum of the downloaded server jar does not match the BuildData hash." + exit 1 +fi + +echo "Applying class mappings..." +if [ ! -f "$jarpath-cl.jar" ]; then + java -jar BuildData/bin/SpecialSource-2.jar map -i "$jarpath.jar" -m "$classmappings" -o "$jarpath-cl.jar" 1>/dev/null + if [ "$?" != "0" ]; then + echo "Failed to apply class mappings." + exit 1 + fi +fi + +echo "Applying member mappings..." +if [ ! -f "$jarpath-m.jar" ]; then + java -jar BuildData/bin/SpecialSource-2.jar map -i "$jarpath-cl.jar" -m "$membermappings" -o "$jarpath-m.jar" 1>/dev/null + if [ "$?" != "0" ]; then + echo "Failed to apply member mappings." + exit 1 + fi +fi + +echo "Creating remapped jar..." +if [ ! -f "$jarpath-mapped.jar" ]; then + java -jar BuildData/bin/SpecialSource.jar --kill-lvt -i "$jarpath-m.jar" --access-transformer "$accesstransforms" -m "$packagemappings" -o "$jarpath-mapped.jar" 1>/dev/null + if [ "$?" != "0" ]; then + echo "Failed to create remapped jar." + exit 1 + fi +fi + +echo "Installing remapped jar..." +cd CraftBukkit # Need to be in a directory with a valid POM at the time of install. +mvn --batch-mode install:install-file -q -Dfile="$jarpath-mapped.jar" -Dpackaging=jar -DgroupId=org.spigotmc -DartifactId=minecraft-server -Dversion="$minecraftversion-SNAPSHOT" +if [ "$?" != "0" ]; then + echo "Failed to install remapped jar." + exit 1 +fi diff --git a/scripts/generatesources.sh b/scripts/generatesources.sh new file mode 100644 index 0000000..79b1874 --- /dev/null +++ b/scripts/generatesources.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +initScript=$(dirname "$SOURCE")/init.sh +. "$initScript" + + +cd "$basedir" +paperVer=$(cat base/.upstream-state) + +minecraftversion=$(cat "$basedir/base/Paper/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) +decompile="base/Paper/work/$minecraftversion/" + +mkdir -p base/mc-dev/src/net/minecraft/server + +cd base/mc-dev +if [ ! -d ".git" ]; then + git init +fi + +#cp $(sed 's/ /\\ /g' <<< $basedir)/$decompile/net/minecraft/server/*.java src/net/minecraft/server + +for nmsFile in "$basedir/$decompile/net/minecraft/server/"*.java +do + cp "$nmsFile" "src/net/minecraft/server" +done + + +base="$basedir/base/Paper/PaperSpigot-Server/src/main/java/net/minecraft/server" +cd "$basedir/base/mc-dev/src/net/minecraft/server/" +for file in $(/bin/ls "$base") +do + if [ -f "$file" ]; then + rm -f "$file" + fi +done +cd "$basedir/base/mc-dev" +git add . -A +git commit . -m "mc-dev" +git tag -a "$paperVer" -m "$paperVer" 2>/dev/null diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh new file mode 100644 index 0000000..db17458 --- /dev/null +++ b/scripts/importmcdev.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +( +set -e +nms="net/minecraft/server" +export MODLOG="" +PS1="$" +basedir="$(cd "$1" && pwd -P)" + +workdir="$basedir/base/Paper/work" +minecraftversion=$(cat "$basedir/base/Paper/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) +decompiledir="$workdir/$minecraftversion" + +export importedmcdev="" +function import { + export importedmcdev="$importedmcdev $1" + file="${1}.java" + target="$basedir/base/Paper/PaperSpigot-Server/src/main/java/$nms/$file" + base="$decompiledir/$nms/$file" + + if [[ ! -f "$target" ]]; then + export MODLOG="$MODLOG Imported $file from mc-dev\n"; + echo "Copying $base to $target" + cp "$base" "$target" + else + echo "UN-NEEDED IMPORT: $file" + fi +} + +( + cd "$basedir/base/Paper/PaperSpigot-Server/" + lastlog=$(git log -1 --oneline) + if [[ "$lastlog" = *"mc-dev Imports"* ]]; then + git reset --hard HEAD^ + fi +) + +import BlockBeacon +import ChunkCache +import ChunkCoordIntPair +import EntityTypes +import ItemFireworks +import PacketPlayInUseEntity +import PacketPlayOutEntityMetadata +import PacketPlayOutPlayerInfo +import PacketPlayOutScoreboardTeam +import PacketPlayOutNamedEntitySpawn +import PacketPlayOutSpawnEntityLiving +import PacketPlayOutAttachEntity +import PersistentScoreboard +import SlotResult +import StatisticList +import PacketPlayOutSpawnEntity +import ItemGoldenApple +import ItemPotion +import ServerPing +import WorldGenCaves +import WorldSettings +import BlockCarpet +import MerchantRecipeList +import ServerNBTManager +import IChunkLoader + +cd "$basedir/base/Paper/PaperSpigot-Server/" +rm -rf nms-patches applyPatches.sh makePatches.sh >/dev/null 2>&1 +git add . -A >/dev/null 2>&1 +echo -e "mc-dev Imports\n\n$MODLOG" | git commit . -F - +) diff --git a/scripts/init.sh b/scripts/init.sh new file mode 100644 index 0000000..c06c845 --- /dev/null +++ b/scripts/init.sh @@ -0,0 +1,46 @@ +#!/bin/bash +sourceBase=$(dirname "$SOURCE")/../ +cd "${basedir:-$sourceBase}" + +basedir="$(pwd -P)" + +log_info() { + echo -e "\033[32m-------\033[0m $1" +} + +log_warning() { + echo -e "\033[33m!!!!!!!\033[0m $1" +} + +log_error() { + echo -e "\033[31m#######\033[0m $1" +} + +function cleanupPatches { + cd "$1" + for patch in *.patch; do + gitver=$(tail -n 2 $patch | grep -ve "^$" | tail -n 1) + diffs=$(git diff --staged $patch | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index|Date\: )") + + testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver") + if [ "x$testver" != "x" ]; then + diffs=$(echo "$diffs" | tail -n +3) + fi + + if [ "x$diffs" == "x" ] ; then + git reset HEAD $patch >/dev/null + git checkout -- $patch >/dev/null + fi + done +} + +function basedir { + cd "$basedir" +} + +function gethead { + ( + cd "$1" + git log -1 --oneline + ) +} diff --git a/scripts/rebuildpatches.sh b/scripts/rebuildpatches.sh new file mode 100644 index 0000000..ce390fd --- /dev/null +++ b/scripts/rebuildpatches.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +initScript=$(dirname "$SOURCE")/init.sh +. "$initScript" + +PS1="$" +log_info "Rebuilding patches from current state..." +function savePatches { + what=$1 + cd "$basedir/$what/" + + mkdir -p "$basedir/patches/$2" + if [ -d ".git/rebase-apply" ]; then + # in middle of a rebase, be smarter + echo "REBASE DETECTED - PARTIAL SAVE" + last=$(cat ".git/rebase-apply/last") + next=$(cat ".git/rebase-apply/next") + for i in $(seq -f "%04g" 1 1 $last) + do + if [ $i -lt $next ]; then + for patchFile in "$basedir/patches/$2/${i}-"*.patch + do + rm "$patchFile" + done + #rm $basedir/patches/$2/${i}-*.patch + fi + done + else + #rm $(sed 's/ /\\ /g' <<< $basedir)/patches/$2/*.patch + for patchFile in "$basedir/patches/$2/"*.patch + do + rm "$patchFile" + done + fi + + git format-patch --quiet --no-stat -N -o "$basedir/patches/$2" upstream/upstream + cd "$basedir" + git add -A "$basedir/patches/$2" + cleanupPatches "$basedir/patches/$2/" + echo " Patches saved for $what to patches/$2" +} + +savePatches mSpigot-API api +savePatches mSpigot-Server server + +log_info "Patches successfully rebuilt" diff --git a/scripts/upstream.sh b/scripts/upstream.sh new file mode 100644 index 0000000..59ec621 --- /dev/null +++ b/scripts/upstream.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +initScript=$(dirname "$SOURCE")/init.sh +. "$initScript" + +if [[ "$1" == up* ]]; then + ( + cd "$basedir/base/Paper/" + git fetch && git reset --hard origin/master + cd ../ + git add Paper + ) +fi +log_info "Setting up build environment" +git submodule update --init --recursive +log_info "Preparing upstream..." +paperVer=$(gethead base/Paper) + +cd "$basedir" +cp -f scripts/baseremap.sh base/Paper/remap.sh +cp -f scripts/basedecompile.sh base/Paper/decompile.sh +cp -f scripts/baseinit.sh base/Paper/init.sh +cp -f scripts/basenewApplyPatches.sh base/Paper/newApplyPatches.sh + +cd "$basedir/base/Paper/" + +git submodule update --init + +./remap.sh && ./decompile.sh && ./init.sh && ./newApplyPatches.sh + +cd "PaperSpigot-Server" +mcVer=$(mvn -o org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=minecraft_version | sed -n -e '/^\[.*\]/ !{ /^[0-9]/ { p; q } }') + +basedir +. scripts/importmcdev.sh +scripts/generatesources.sh +minecraftversion=$(cat "$basedir/base/Paper/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) + +cd base/Paper/ + +version=$(echo -e "Paper: $paperVer\nmc-dev:$importedmcdev") +tag="${minecraftversion}-${mcVer}-$(echo -e $version | shasum | awk '{print $1}')" + +function tag { +( + cd "$1" + if [ "$2" == "1" ]; then + git tag -d "$tag" 2>/dev/null + fi + echo -e "$(date)\n\n$version" | git tag -a "$tag" -F - 2>/dev/null +) +} + +forcetag=0 +upstreamState=$(cat "$basedir/base/.upstream-state") +if [ "$upstreamState" != "$tag" ]; then + forcetag=1 +fi + +tag PaperSpigot-API $forcetag +tag PaperSpigot-Server $forcetag + +echo "$tag" > "$basedir/base/.upstream-state" + +log_info "Build environment prepared. Run './mspigot apply' to apply patches."