diff --git a/paper b/paper new file mode 100755 index 000000000..bac5d89e6 --- /dev/null +++ b/paper @@ -0,0 +1,100 @@ +#!/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") + +paperstash() { + STASHED=$(git stash) +} + +paperunstash() { + if [[ "$STASHED" != "No local changes to save" ]] ; then + git stash pop + fi +} + +case "$1" in + "rbp" | "rebuild") + ( + cd "$basedir" + scripts/rebuildPatches.sh "$basedir" + ) + ;; + "a" | "apply") + ( + cd "$basedir" + scripts/build.sh "$basedir" + ) + ;; + "j" | "jar") + ( + cd "$basedir" + scripts/build.sh "$basedir" "--jar" + ) + ;; + "r" | "root") + cd "$basedir" + ;; + "api") + cd "$basedir/Paper-API" + ;; + "serv" | "server") + cd "$basedir" + ;; + "e" | "edit") + if [[ "$2" = "server" ]] ; then + cd "$basedir/Paper-Server" + export LAST_EDIT=$(pwd) + + paperstash + git rebase -i upstream/upstream + paperunstash + elif [[ "$2" = "api" ]] ; then + cd "$basedir/Paper-API" + export LAST_EDIT=$(pwd) + + paperstash + git rebase -i upstream/upstream + paperunstash + elif [[ "$2" = "continue" ]] ; then + cd "$LAST_EDIT" + git add . + git rebase --continue + unset LAST_EDIT + scripts/rebuildPatches.sh "$basedir" + else + echo "You must edit either the api or server." + fi + ;; + "setup") + if [[ -f ~/.bashrc ]] ; then + (grep "alias paper=" ~/.bashrc > /dev/null) && (sed -i "s|alias paper=.*|alias paper='. $SOURCE'|g" ~/.bashrc) || (echo "alias paper='. $SOURCE'" >> ~/.bashrc) + alias paper=". $SOURCE" + echo "You can now just type 'paper' at any time to access the paper tool." + fi + ;; + *) + echo "rbp, rebuild | Rebuild patches, can be called from anywhere." + echo "p, patch | Apply all patches to the project without building it. Can be run from anywhere." + echo "j, jar | Apply all patches and build the project, paperclip.jar will be output. Can be run from anywhere." + echo "r, root | Change directory to the root of the project." + echo "api | Move to the Paper-API directory." + echo "serv, server | Move to the Paper-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 "setup | Add an alias to .bashrc to allow full functionality of this script. Run as:" + echo " | . ./paper setup" + echo " | After you run this command you'll be able to just run 'paper' from anywhere." + ;; +esac + +unset -f paperstash +unset -f paperunstash diff --git a/scripts/envSetup.sh b/scripts/envSetup.sh deleted file mode 100644 index b2cd3d61c..000000000 --- a/scripts/envSetup.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env bash - -# Set root project directory -CWD=$(pwd) - -rbp() { - NEW_CWD=$(pwd) - cd "$CWD" - scripts/rebuildPatches.sh "$CWD" - cd "$NEW_CWD" -} - -rebuildPatches() { - rbp -} - -lunch() { - NEW_CWD=$(pwd) - cd "$CWD" - - if [[ "$1" = "jar" ]] || [[ "$1" = "--jar" ]] ; then - ARG="--jar" - fi - - scripts/build.sh "$CWD" "$ARG" - ARG="" - - cd "$NEW_CWD" -} - -root() { - cd "$CWD" -} - -LAST_EDIT="" - -edit() { - if [[ "$1" = "server" ]] ; then - cd "$CWD/Paper-Server" - LAST_EDIT=$(pwd) - - stash - git rebase -i upstream/upstream - unstash - elif [[ "$1" = "api" ]] ; then - cd "$CWD/Paper-API" - LAST_EDIT=$(pwd) - - stash - git rebase -i upstream/upstream - unstash - elif [[ "$1" = "continue" ]] ; then - cd "$LAST_EDIT" - git add . - git commit --amend - git rebase --continue - else - echo "You must edit either the api or server." - fi -} - -stash() { - STASHED=$(git stash) -} - -unstash() { - if [[ "$STASHED" != "No local changes to save" ]] ; then - git stash pop - fi -} \ No newline at end of file diff --git a/scripts/paperclip.sh b/scripts/paperclip.sh index 9840f3c94..4be65ac26 100755 --- a/scripts/paperclip.sh +++ b/scripts/paperclip.sh @@ -6,7 +6,7 @@ paperjar="../../Paper-Server/target/paper-$mcver.jar" vanillajar="../$mcver/$mcver.jar" cd "$workdir/Paperclip" -mvn clean package "-Dmcver=$mcver" "-Dpaperjar=$paperjar" "-Dvanillajar=$vanillajar" +mvn clean package "-Dmcver=$mcver" "-Dpaperjar=$paperjar" "-Dvanillajar=$vanillajar" || exit 1 cd .. cp "$workdir/Paperclip/target/paperclip-${mcver}.jar" "$basedir/paperclip.jar"