diff --git a/purpur b/purpur index 15ff3c346..45ec54bd3 100755 --- a/purpur +++ b/purpur @@ -3,131 +3,136 @@ # 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 )" + 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#./}") +SOURCE=$([[ "$SOURCE" == /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") basedir=$(dirname "$SOURCE") -. $basedir/scripts/init.sh +. "$basedir"/scripts/init.sh purpurstash() { STASHED=$(git stash) } purpurunstash() { - if [[ "$STASHED" != "No local changes to save" ]] ; then + if [[ "$STASHED" != "No local changes to save" ]]; then git stash pop fi } case "$1" in - "a" | "am" | "amend") +"am" | "amend") ( - cd $basedir/Purpur-API/ + cd "$basedir"/Purpur-API/ git add . git commit --amend --no-edit - cd $basedir/Purpur-Server/ + cd "$basedir"/Purpur-Server/ git add . git commit --amend --no-edit - cd $basedir + cd "$basedir" scripts/rebuildpatches.sh "$basedir" ) ;; - "rb" | "rbp" | "rebuild") +"rb" | "rbp" | "rebuild") ( set -e cd "$basedir" scripts/rebuildpatches.sh "$basedir" ) ;; - "p" | "patch" | "apply") +"p" | "patch" | "apply") ( set -e cd "$basedir" scripts/apply.sh "$basedir" ) ;; - "b" | "bu" | "build") +"b" | "bu" | "build") ( basedir mvn -N install - cd ${FORK_NAME}-API - mvn -e clean install && cd ../${FORK_NAME}-Server && mvn -e clean install + cd Purpur-API + mvn -e clean install + cd ../Purpur-Server + mvn -e clean install ) ;; - "jar" | "purpurclip") +"jar" | "purpurclip") ( - basedir - cd "$basedir" - if [ "$2" != "fast" ]; then - scripts/upstream.sh - fi - ./scripts/apply.sh "$basedir" - ./scripts/purpurclip.sh + basedir + cd "$basedir" + if [ "$2" != "fast" ]; then + scripts/upstream.sh + fi + ./scripts/apply.sh "$basedir" + ./scripts/purpurclip.sh ) ;; - "d" | "de" | "deploy") +"d" | "de" | "deploy") ( basedir mvn -N install - cd ${FORK_NAME}-API - mvn clean deploy && cd ../${FORK_NAME}-Server && mvn clean install + cd Purpur-API + mvn clean deploy + cd ../Purpur-Server + mvn clean install ) ;; - "up" | "upstream") +"up" | "upstream") ( cd "$basedir" scripts/upstream.sh "$2" ) ;; - "r" | "root") - cd "$basedir" +"r" | "root") + cd "$basedir" ;; - "a" | "api") - cd "$basedir/Purpur-API" +"a" | "api") + cd "$basedir/Purpur-API" ;; - "s" | "server") - cd "$basedir/Purpur-Server" +"s" | "server") + cd "$basedir/Purpur-Server" ;; - "setup") - if [[ -f ~/.bashrc ]] ; then - NAME="purpur" - if [[ ! -z "${2+x}" ]] ; then - NAME="$2" - fi - (grep "alias $NAME=" ~/.bashrc > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" ~/.bashrc) || (echo "alias $NAME='. $SOURCE'" >> ~/.bashrc) - alias "$NAME=. $SOURCE" - echo "You can now just type '$NAME' at any time to access the purpur tool." +"setup") + if [[ -f ~/.bashrc ]]; then + NAME="purpur" + if [[ -n "${2+x}" ]]; then + NAME="$2" fi + (grep "alias $NAME=" ~/.bashrc >/dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" ~/.bashrc) || (echo "alias $NAME='. $SOURCE'" >>~/.bashrc) + alias "$NAME=. $SOURCE" + echo "You can now just type '$NAME' at any time to access the purpur tool." + fi ;; - *) - echo "Purpur build tool command. This provides a variety of commands to build and manage the Purpur build" - echo "environment. For all of the functionality of this command to be available, you must first run the" - echo "'setup' command. View below for details. For essential building and patching, you do not need to do the setup." - echo "" - echo " Normal commands:" - echo " * rb, rebuild | Rebuild patches, can be called from anywhere." - echo " * p, patch | Apply all patches to top of Paper without building it. Can be run from anywhere." - echo " * up, upstream | Build Paper upstream, pass arg up to update paper. Can be run from anywhere." - echo " * b, build | Build API and Server but no deploy. Can be ran anywhere." - echo " * d, deploy | Build and Deploy API jar and build Server. Can be ran anywhere." - echo "" - echo " These commands require the setup command before use:" - echo " * r, root | Change directory to the root of the project." - echo " * a. api | Move to the Purpur-API directory." - echo " * s, server | Move to the Purpur-Server directory." - echo " * e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\"" - echo " | respectively to edit the correct project. Use the argument \"continue\" after" - echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere." - echo "" - echo " * setup | Add an alias to .bashrc to allow full functionality of this script. Run as:" - echo " | . ./purpur setup" - echo " | After you run this command you'll be able to just run 'purpur' from anywhere." - echo " | The default name for the resulting alias is 'purpur', you can give an argument to override" - echo " | this default, such as:" - echo " | . ./purpur setup example" - echo " | Which will allow you to run 'example' instead." +*) + echo "Purpur build tool command. This provides a variety of commands to build and manage the Purpur build" + echo "environment. For all of the functionality of this command to be available, you must first run the" + echo "'setup' command. View below for details. For essential building and patching, you do not need to do the setup." + echo "" + echo " Normal commands:" + echo " * am, amend | Amend current edits to last patches" + echo " * rb, rebuild | Rebuild patches, can be called from anywhere." + echo " * p, patch | Apply all patches to top of Paper without building it. Can be run from anywhere." + echo " * up, upstream | Build Paper upstream, pass arg up to update paper. Can be run from anywhere." + echo " * b, build | Build API and Server but no deploy. Can be ran anywhere." + echo " * d, deploy | Build and Deploy API jar and build Server. Can be ran anywhere." + echo "" + echo " These commands require the setup command before use:" + echo " * r, root | Change directory to the root of the project." + echo " * a. api | Move to the Purpur-API directory." + echo " * s, server | Move to the Purpur-Server directory." + echo " * e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\"" + echo " | respectively to edit the correct project. Use the argument \"continue\" after" + echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere." + echo "" + echo " * setup | Add an alias to .bashrc to allow full functionality of this script. Run as:" + echo " | . ./purpur setup" + echo " | After you run this command you'll be able to just run 'purpur' from anywhere." + echo " | The default name for the resulting alias is 'purpur', you can give an argument to override" + echo " | this default, such as:" + echo " | . ./purpur setup example" + echo " | Which will allow you to run 'example' instead." ;; esac diff --git a/scripts/apply.sh b/scripts/apply.sh index 504da627e..21dd3c167 100755 --- a/scripts/apply.sh +++ b/scripts/apply.sh @@ -22,69 +22,69 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli 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 -. $(dirname $SOURCE)/init.sh +. "$(dirname "$SOURCE")/init.sh" PS1="$" paperVer=$(cat current-paper) gpgsign="$(git config commit.gpgsign || echo "false")" echo "Rebuilding Forked projects.... " function applyPatch { - what=$1 - what_name=$(basename $what) - target=$2 - branch=$3 - patch_folder=$4 + what=$1 + what_name=$(basename "$what") + target=$2 + branch=$3 + patch_folder=$4 - cd "$basedir/$what" - git fetch --all - git branch -f upstream "$branch" >/dev/null + cd "$basedir/$what" || exit + git fetch --all + git branch -f upstream "$branch" >/dev/null - cd "$basedir" - if [ ! -d "$basedir/$target" ]; then - mkdir "$basedir/$target" - cd "$basedir/$target" - git init - git remote add origin $5 - cd "$basedir" - fi - cd "$basedir/$target" + cd "$basedir" || exit + if [ ! -d "$basedir/$target" ]; then + mkdir "$basedir/$target" + cd "$basedir/$target" || exit + git init + git remote add origin "$5" + cd "$basedir" || exit + fi + cd "$basedir/$target" || exit - # Disable GPG signing before AM, slows things down and doesn't play nicely. - # There is also zero rational or logical reason to do so for these sub-repo AMs. - # Calm down kids, it's re-enabled (if needed) immediately after, pass or fail. - git config commit.gpgsign false + # Disable GPG signing before AM, slows things down and doesn't play nicely. + # There is also zero rational or logical reason to do so for these sub-repo AMs. + # Calm down kids, it's re-enabled (if needed) immediately after, pass or fail. + git config commit.gpgsign false - 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 - 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 + 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 + 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 } function enableCommitSigningIfNeeded { - if [[ "$gpgsign" == "true" ]]; then - git config commit.gpgsign true - fi + if [[ "$gpgsign" == "true" ]]; then + git config commit.gpgsign true + fi } ( - (applyPatch Paper/Paper-API ${FORK_NAME}-API HEAD api $API_REPO && - applyPatch Paper/Paper-Server ${FORK_NAME}-Server HEAD server $SERVER_REPO) || exit 1 - enableCommitSigningIfNeeded + (applyPatch Paper/Paper-API Purpur-API HEAD api "$API_REPO" && + applyPatch Paper/Paper-Server Purpur-Server HEAD server "$SERVER_REPO") || exit 1 + enableCommitSigningIfNeeded ) || ( - echo "Failed to apply patches" - enableCommitSigningIfNeeded - exit 1 + echo "Failed to apply patches" + enableCommitSigningIfNeeded + exit 1 ) || exit 1 diff --git a/scripts/generatesources.sh b/scripts/generatesources.sh index 7c3bc5b60..17a199349 100755 --- a/scripts/generatesources.sh +++ b/scripts/generatesources.sh @@ -2,39 +2,36 @@ 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 + 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 -. $(dirname $SOURCE)/init.sh +. "$(dirname "$SOURCE")/init.sh" - -cd $basedir +cd "$basedir" || exit paperVer=$(cat current-paper) -minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +minecraftversion=$(< "$basedir"/Paper/work/BuildData/info.json grep minecraftVersion | cut -d '"' -f 4) decompile="Paper/work/Minecraft/$minecraftversion/spigot" mkdir -p mc-dev/src/net/minecraft/server -cd mc-dev +cd mc-dev || exit if [ ! -d ".git" ]; then - git init + git init fi rm src/net/minecraft/server/*.java -cp $basedir/$decompile/net/minecraft/server/*.java src/net/minecraft/server +cp "$basedir"/"$decompile"/net/minecraft/server/*.java src/net/minecraft/server base="$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server" -cd $basedir/mc-dev/src/net/minecraft/server/ -for file in $(/bin/ls $base) -do - if [ -f "$file" ]; then - rm -f "$file" - fi +cd "$basedir"/mc-dev/src/net/minecraft/server/ || exit +for file in $(/bin/ls "$base"); do + if [ -f "$file" ]; then + rm -f "$file" + fi done -cd $basedir/mc-dev +cd "$basedir"/mc-dev || exit git add . -A git commit . -m "mc-dev" git tag -a "$paperVer" -m "$paperVer" 2>/dev/null -pushRepo . $MCDEV_REPO $paperVer diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh index 9eb201f33..8f7976821 100755 --- a/scripts/importmcdev.sh +++ b/scripts/importmcdev.sh @@ -2,72 +2,71 @@ 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 + 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 -. $(dirname $SOURCE)/init.sh +. "$(dirname "$SOURCE")/init.sh" workdir=$basedir/Paper/work -minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +minecraftversion=$(< "$basedir"/Paper/work/BuildData/info.json grep minecraftVersion | cut -d '"' -f 4) decompiledir=$workdir/Minecraft/$minecraftversion/spigot nms="net/minecraft/server" export MODLOG="" -cd $basedir +cd "$basedir" || exit -function containsElement { - local e - for e in "${@:2}"; do - [[ "$e" == "$1" ]] && return 0; - done - return 1 +function containsElement() { + local e + for e in "${@:2}"; do + [[ "$e" == "$1" ]] && return 0 + done + return 1 } export importedmcdev="" -function import { - if [ -f "$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server/$1.java" ]; then - echo "ALREADY IMPORTED $1" - return 0 - fi - export importedmcdev="$importedmcdev $1" - file="${1}.java" - target="$basedir/Paper/Paper-Server/src/main/java/$nms/$file" - base="$decompiledir/$nms/$file" +function import() { + if [ -f "$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server/$1.java" ]; then + echo "ALREADY IMPORTED $1" + return 0 + fi + export importedmcdev="$importedmcdev $1" + file="${1}.java" + target="$basedir/Paper/Paper-Server/src/main/java/$nms/$file" + base="$decompiledir/$nms/$file" - if [[ ! -f "$target" ]]; then - export MODLOG="$MODLOG Imported $file from mc-dev\n"; - echo "$(bashColor 1 32) Copying $(bashColor 1 34)$base $(bashColor 1 32)to$(bashColor 1 34) $target $(bashColorReset)" - cp "$base" "$target" - else - echo "$(bashColor 1 33) UN-NEEDED IMPORT STATEMENT:$(bashColor 1 34) $file $(bashColorReset)" - fi + if [[ ! -f "$target" ]]; then + export MODLOG="$MODLOG Imported $file from mc-dev\n" + echo "$(bashColor 1 32) Copying $(bashColor 1 34)$base $(bashColor 1 32)to$(bashColor 1 34) $target $(bashColorReset)" + cp "$base" "$target" + else + echo "$(bashColor 1 33) UN-NEEDED IMPORT STATEMENT:$(bashColor 1 34) $file $(bashColorReset)" + fi } ( - cd Paper/Paper-Server/ - lastlog=$(git log -1 --oneline) - if [[ "$lastlog" = *"Purpur-Extra mc-dev Imports"* ]]; then - git reset --hard HEAD^ - fi + cd Paper/Paper-Server/ || exit + lastlog=$(git log -1 --oneline) + if [[ "$lastlog" == *"Purpur-Extra mc-dev Imports"* ]]; then + git reset --hard HEAD^ + fi ) - files=$(cat patches/server/* | grep "+++ b/src/main/java/net/minecraft/server/" | sort | uniq | sed 's/\+\+\+ b\/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g') nonnms=$(cat patches/server/* | grep "create mode " | grep -Po "src/main/java/net/minecraft/server/(.*?).java" | sort | uniq | sed 's/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g') for f in $files; do - containsElement "$f" ${nonnms[@]} - if [ "$?" == "1" ]; then - if [ ! -f "$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server/$f.java" ]; then - if [ ! -f "$decompiledir/$nms/$f.java" ]; then - echo "$(bashColor 1 31) ERROR!!! Missing NMS$(bashColor 1 34) $f $(bashColorReset)"; - else - import $f - fi - fi - fi + containsElement "$f" "${nonnms[@]}" + if [ "$?" == "1" ]; then + if [ ! -f "$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server/$f.java" ]; then + if [ ! -f "$decompiledir/$nms/$f.java" ]; then + echo "$(bashColor 1 31) ERROR!!! Missing NMS$(bashColor 1 34) $f $(bashColorReset)" + else + import "$f" + fi + fi + fi done ############################################################################################### @@ -80,10 +79,8 @@ done ################ ( - cd Paper/Paper-Server/ - rm -rf nms-patches - git add src -A - echo -e "Purpur-Extra mc-dev Imports\n\n$MODLOG" | git commit src -F - + cd Paper/Paper-Server/ || exit + rm -rf nms-patches + git add src -A + echo -e "Purpur-Extra mc-dev Imports\n\n$MODLOG" | git commit src -F - ) - - diff --git a/scripts/init.sh b/scripts/init.sh index 25ab21ffd..6085a7129 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,65 +1,45 @@ #!/usr/bin/env bash -# BEGIN config -FORK_NAME="Purpur" -API_REPO="" -SERVER_REPO="" -PAPER_API_REPO="" -PAPER_SERVER_REPO="" -MCDEV_REPO="" -# END config -sourceBase=$(dirname $SOURCE)/../ -cd ${basedir:-$sourceBase} +sourceBase=$(dirname "$SOURCE")/../ +cd "${basedir:-$sourceBase}" || exit basedir=$(pwd -P) -cd - +cd - || exit - -function bashColor { -if [ $2 ]; then - echo -e "\e[$1;$2m" -else - echo -e "\e[$1m" -fi +function bashColor() { + if [ "$2" ]; then + echo -e "\e[$1;$2m" + else + echo -e "\e[$1m" + fi } -function bashColorReset { - echo -e "\e[m" +function bashColorReset() { + echo -e "\e[m" } -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\: )") +function cleanupPatches() { + cd "$1" || exit + 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 + 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 + if [ "x$diffs" == "x" ]; then + git reset HEAD "$patch" >/dev/null + git checkout -- "$patch" >/dev/null + fi + done } -function pushRepo { - if [ "$(git config minecraft.push-${FORK_NAME})" == "1" ]; then - echo "Pushing - $1 ($3) to $2" - ( - cd "$1" - git remote rm emc-push > /dev/null 2>&1 - git remote add emc-push $2 >/dev/null 2>&1 - git push emc-push $3 -f - ) - fi +function basedir() { + cd "$basedir" || exit } -function basedir { - cd "$basedir" -} -function gethead { - ( - cd "$1" - git log -1 --oneline - ) +function gethead() { + ( + cd "$1" || exit + git log -1 --oneline + ) } diff --git a/scripts/purpurclip.sh b/scripts/purpurclip.sh index f54d43a81..cf3271fcd 100755 --- a/scripts/purpurclip.sh +++ b/scripts/purpurclip.sh @@ -1,22 +1,21 @@ #!/usr/bin/env bash - ( -set -e -basedir="$(cd "$1" && pwd -P)" -workdir="$basedir/Paper/work" -mcver=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) -purpurjar="$basedir/Purpur-Server/target/purpur-$mcver.jar" -vanillajar="$workdir/Minecraft/$mcver/$mcver.jar" + set -e + basedir="$(cd "$1" && pwd -P)" + workdir="$basedir/Paper/work" + mcver=$(< "$workdir/BuildData/info.json" grep minecraftVersion | cut -d '"' -f 4) + purpurjar="$basedir/Purpur-Server/target/purpur-$mcver.jar" + vanillajar="$workdir/Minecraft/$mcver/$mcver.jar" -( - cd "$basedir/Paperclip" - mvn clean package "-Dmcver=$mcver" "-Dpaperjar=$purpurjar" "-Dvanillajar=$vanillajar" -) -cp "$basedir/Paperclip/assembly/target/paperclip-${mcver}.jar" "$basedir/purpurclip.jar" + ( + cd "$basedir/Paperclip" + mvn clean package "-Dmcver=$mcver" "-Dpaperjar=$purpurjar" "-Dvanillajar=$vanillajar" + ) + cp "$basedir/Paperclip/assembly/target/paperclip-${mcver}.jar" "$basedir/purpurclip.jar" -echo "" -echo "" -echo "" -echo "Build success!" -echo "Copied final jar to $(cd "$basedir" && pwd -P)/purpurclip.jar" + echo "" + echo "" + echo "" + echo "Build success!" + echo "Copied final jar to $(cd "$basedir" && pwd -P)/purpurclip.jar" ) || exit 1 diff --git a/scripts/push.sh b/scripts/push.sh deleted file mode 100755 index ed4bf9f00..000000000 --- a/scripts/push.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/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 -. $(dirname $SOURCE)/init.sh - -minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) - -basedir -pushRepo ${FORK_NAME}-API $API_REPO master:$minecraftversion -pushRepo ${FORK_NAME}-Server $SERVER_REPO master:$minecraftversion diff --git a/scripts/rebuildpatches.sh b/scripts/rebuildpatches.sh index a0d13b969..3fca6c47e 100755 --- a/scripts/rebuildpatches.sh +++ b/scripts/rebuildpatches.sh @@ -2,43 +2,40 @@ # 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 + 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 -. $(dirname $SOURCE)/init.sh +. "$(dirname "$SOURCE")/init.sh" PS1="$" echo "Rebuilding patch files from current fork state..." -function savePatches { - what=$1 - cd $basedir/$what/ +function savePatches() { + what=$1 + cd "$basedir"/"$what"/ || exit - 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") - declare -a files=("$basedir/patches/$2/"*.patch) - for i in $(seq -f "%04g" 1 1 $last) - do - if [ $i -lt $next ]; then - rm "${files[`expr $i - 1`]}" - fi - done - else - rm $basedir/patches/$2/*.patch - fi + 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") + declare -a files=("$basedir/patches/$2/"*.patch) + for i in $(seq -f "%04g" 1 1 "$last"); do + if [ "$i" -lt "$next" ]; then + rm "${files[$(("$i" - 1))]}" + fi + done + else + rm "$basedir"/patches/"$2"/*.patch + fi - git format-patch --quiet -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" + git format-patch --quiet -N -o "$basedir"/patches/"$2" upstream/upstream + cd "$basedir" || exit + git add -A "$basedir"/patches/"$2" + cleanupPatches "$basedir"/patches/"$2"/ + echo " Patches saved for $what to patches/$2" } -savePatches ${FORK_NAME}-API api -savePatches ${FORK_NAME}-Server server - -$basedir/scripts/push.sh +savePatches Purpur-API api +savePatches Purpur-Server server diff --git a/scripts/upstream.sh b/scripts/upstream.sh index 25ec4c8d4..77a078db5 100755 --- a/scripts/upstream.sh +++ b/scripts/upstream.sh @@ -2,61 +2,57 @@ # 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 + 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 -. $(dirname $SOURCE)/init.sh +. "$(dirname "$SOURCE")/init.sh" if [[ "$1" == up* ]]; then - ( - cd "$basedir/Paper/" - git fetch && git reset --hard origin/master - cd ../ - git add Paper - ) + ( + cd "$basedir/Paper/" || exit + git fetch && git reset --hard origin/master + cd ../ + git add Paper + ) fi paperVer=$(gethead Paper) -cd "$basedir/Paper/" +cd "$basedir/Paper/" || exit ./paper patch -cd "Paper-Server" +cd "Paper-Server" || exit 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 -. $basedir/scripts/importmcdev.sh +. "$basedir"/scripts/importmcdev.sh -minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +minecraftversion=$(< "$basedir"/Paper/work/BuildData/info.json grep minecraftVersion | cut -d '"' -f 4) version=$(echo -e "Paper: $paperVer\nmc-dev:$importedmcdev") -tag="${minecraftversion}-${mcVer}-$(echo -e $version | shasum | awk '{print $1}')" -echo "$tag" > $basedir/current-paper +tag="${minecraftversion}-${mcVer}-$(echo -e "$version" | shasum | awk '{print $1}')" +echo "$tag" >"$basedir"/current-paper -$basedir/scripts/generatesources.sh +"$basedir"/scripts/generatesources.sh -cd Paper/ +cd Paper/ || exit -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 -) +function tag() { + ( + cd "$1" || exit + 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 + ) } echo "Tagging as $tag" echo -e "$version" forcetag=0 -if [ "$(cat $basedir/current-paper)" != "$tag" ]; then - forcetag=1 +if [ "$(cat "$basedir"/current-paper)" != "$tag" ]; then + forcetag=1 fi tag Paper-API $forcetag tag Paper-Server $forcetag - -pushRepo Paper-API $PAPER_API_REPO $tag -pushRepo Paper-Server $PAPER_SERVER_REPO $tag - diff --git a/scripts/upstreamCommit.sh b/scripts/upstreamCommit.sh index 841855530..6b9916cbc 100755 --- a/scripts/upstreamCommit.sh +++ b/scripts/upstreamCommit.sh @@ -1,28 +1,28 @@ #!/usr/bin/env bash ( -set -e -PS1="$" + set -e + PS1="$" -function changelog() { - base=$(git ls-tree HEAD $1 | cut -d' ' -f3 | cut -f1) - cd $1 && git log --oneline ${base}...HEAD -} -paper=$(changelog Paper) + function changelog() { + base=$(git ls-tree HEAD "$1" | cut -d' ' -f3 | cut -f1) + cd "$1" && git log --oneline "${base}"...HEAD + } + paper=$(changelog Paper) -updated="" -logsuffix="" -if [ ! -z "$paper" ]; then - logsuffix="$logsuffix\n\nPaper Changes:\n$paper" - if [ -z "$updated" ]; then updated="Paper"; else updated="$updated/Paper"; fi -fi -disclaimer="Upstream has released updates that appears to apply and compile correctly" + updated="" + logsuffix="" + if [ -n "$paper" ]; then + logsuffix="$logsuffix\n\nPaper Changes:\n$paper" + if [ -z "$updated" ]; then updated="Paper"; else updated="$updated/Paper"; fi + fi + disclaimer="Upstream has released updates that appears to apply and compile correctly" -if [ ! -z "$1" ]; then - disclaimer="$@" -fi + if [ -n "$1" ]; then + disclaimer=( "$@" ) + fi -log="${UP_LOG_PREFIX}Updated Upstream ($updated)\n\n${disclaimer}${logsuffix}" + log="${UP_LOG_PREFIX}Updated Upstream ($updated)\n\n${disclaimer[*]}${logsuffix}" -echo -e "$log" | git commit -F - + echo -e "$log" | git commit -F - ) || exit 1