2016-04-02 05:01:58 +00:00
#!/usr/bin/env bash
2016-04-03 16:58:42 +00:00
# resolve shell-specifics
2017-03-17 23:37:16 +00:00
case "$(echo "$SHELL" | sed -E 's|/usr(/local)?||g')" in
2016-04-04 02:36:19 +00:00
"/bin/zsh")
RCPATH="$HOME/.zshrc"
SOURCE="${BASH_SOURCE[0]:-${(%):-%N}}"
2016-04-03 16:58:42 +00:00
;;
2016-04-04 02:36:19 +00:00
*)
RCPATH="$HOME/.bashrc"
if [[ -f "$HOME/.bash_aliases" ]]; then
RCPATH="$HOME/.bash_aliases"
fi
SOURCE="${BASH_SOURCE[0]}"
2016-04-03 16:58:42 +00:00
;;
esac
2016-04-04 02:36:19 +00:00
2016-04-02 05:01:58 +00:00
# get base dir regardless of execution location
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
2016-04-04 02:36:19 +00:00
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
2016-04-02 05:01:58 +00:00
done
SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}")
basedir=$(dirname "$SOURCE")
2018-05-24 18:41:50 +00:00
gitcmd="git -c commit.gpgsign=false"
2016-04-02 05:01:58 +00:00
2016-11-20 21:58:20 +00:00
source "$basedir/scripts/functions.sh"
2016-04-02 05:01:58 +00:00
2018-07-30 21:37:24 +00:00
failed=0
2016-04-02 05:01:58 +00:00
case "$1" in
2016-04-03 16:58:42 +00:00
"rb" | "rbp" | "rebuild")
2016-04-03 07:23:19 +00:00
(
set -e
2016-04-02 05:01:58 +00:00
cd "$basedir"
2020-04-02 21:07:06 +00:00
scripts/rebuildPatches.sh "$basedir" $2 || exit 1
2018-07-30 21:37:24 +00:00
) || failed=1
2020-05-01 22:03:47 +00:00
;;
"rbf" | "rbfull")
(
set -e
cd "$basedir"
scripts/rebuildPatches.sh "$basedir" "nofilter" || exit 1
) || failed=1
2016-04-02 05:01:58 +00:00
;;
2016-04-03 07:23:19 +00:00
"p" | "patch")
(
set -e
2016-04-02 05:01:58 +00:00
cd "$basedir"
2018-07-30 21:37:24 +00:00
scripts/build.sh "$basedir" || exit 1
) || failed=1
2016-04-02 05:01:58 +00:00
;;
"j" | "jar")
2016-04-03 07:23:19 +00:00
(
set -e
cd "$basedir"
2018-07-30 21:37:24 +00:00
scripts/build.sh "$basedir" "--jar" || exit 1
) || failed=1
2016-04-03 07:23:19 +00:00
;;
2020-04-18 20:02:37 +00:00
"b" | "build")
(
set -e
cd "$basedir"
scripts/build.sh "$basedir" || exit 1
(cd Paper-API ; mvn clean install) || exit 1
(cd Paper-Server ; mvn clean package) || exit 1
echo "Paper jar successfully built"
ls -la Paper-Server/target/paper*.jar
) || failed=1
;;
2016-04-03 07:23:19 +00:00
"make")
(
if [[ "$2" = "bacon" ]] ; then
set -e
cd "$basedir"
scripts/build.sh "$basedir" "--jar"
fi
)
2016-04-02 05:01:58 +00:00
;;
2016-04-04 02:36:19 +00:00
"m" | "mcdev")
(
set -e
cd "$basedir"
scripts/makemcdevsrc.sh "$basedir"
)
;;
2016-04-10 01:33:32 +00:00
"t" | "test" | "testserver")
(
cd "$basedir"
shift
scripts/testServer.sh "$basedir" "$@"
)
;;
"td" | "testdir")
cd "${PAPER_TEST_DIR:-$basedir/work/test-server}"
;;
2016-08-19 21:00:59 +00:00
"u" | "up" | "upstream")
2016-09-08 00:45:47 +00:00
(
cd "$basedir"
2016-08-19 21:00:59 +00:00
scripts/upstreamMerge.sh "$basedir" "$2"
2016-09-08 00:45:47 +00:00
)
2016-08-19 21:00:59 +00:00
;;
2018-09-01 03:53:49 +00:00
"cu" | "commitup" | "commitupstream" | "upc" | "upcommit" | "upstreamcommit")
2018-08-06 01:31:40 +00:00
(
cd "$basedir"
2018-08-07 03:24:38 +00:00
shift
2018-08-06 01:31:40 +00:00
scripts/upstreamCommit.sh "$@"
)
;;
2016-04-02 05:01:58 +00:00
"r" | "root")
cd "$basedir"
;;
2016-04-03 07:23:19 +00:00
"a" | "api")
2016-04-02 05:01:58 +00:00
cd "$basedir/Paper-API"
;;
2016-04-03 07:23:19 +00:00
"s" | "server")
2016-04-03 20:29:39 +00:00
cd "$basedir/Paper-Server"
2016-04-02 05:01:58 +00:00
;;
2017-09-28 22:52:05 +00:00
"c" | "clean")
rm -rf Paper-API
rm -rf Paper-Server
rm -rf work
echo "Cleaned build files"
;;
2016-04-02 05:01:58 +00:00
"e" | "edit")
2016-04-02 23:34:27 +00:00
case "$2" in
2016-04-03 07:23:19 +00:00
"s" | "server")
2020-05-20 02:10:29 +00:00
mkdir -p "$basedir/work/Temp"
echo "$basedir/Paper-Server" > "$basedir/work/Temp/PAPER_LAST_EDIT"
2016-04-03 07:23:19 +00:00
cd "$basedir/Paper-Server"
(
set -e
2016-04-02 05:01:58 +00:00
2016-04-02 23:34:27 +00:00
paperstash
2018-05-24 18:41:50 +00:00
$gitcmd rebase -i upstream/upstream
2016-04-02 23:34:27 +00:00
paperunstash
2016-04-03 07:23:19 +00:00
)
2016-04-02 23:34:27 +00:00
;;
2016-04-03 07:23:19 +00:00
"a" | "api")
2020-05-20 02:10:29 +00:00
mkdir -p "$basedir/work/Temp"
echo "$basedir/Paper-API" > "$basedir/work/Temp/PAPER_LAST_EDIT"
2016-04-03 07:23:19 +00:00
cd "$basedir/Paper-API"
(
set -e
2016-04-02 05:01:58 +00:00
2016-04-02 23:34:27 +00:00
paperstash
2018-05-24 18:41:50 +00:00
$gitcmd rebase -i upstream/upstream
2016-04-02 23:34:27 +00:00
paperunstash
2016-04-03 07:23:19 +00:00
)
2016-04-02 23:34:27 +00:00
;;
2016-04-03 07:23:19 +00:00
"c" | "continue")
2020-05-20 02:10:29 +00:00
cd "$( < "$basedir/work/Temp/PAPER_LAST_EDIT")"
rm -f "$basedir/work/Temp/PAPER_LAST_EDIT"
2016-04-03 07:23:19 +00:00
(
set -e
2018-05-24 18:41:50 +00:00
$gitcmd add .
$gitcmd commit --amend
$gitcmd rebase --continue
2016-04-03 07:23:19 +00:00
cd "$basedir"
scripts/rebuildPatches.sh "$basedir"
)
2016-04-02 23:34:27 +00:00
;;
*)
echo "You must edit either the api or server."
;;
esac
2016-04-02 05:01:58 +00:00
;;
"setup")
2016-04-03 16:58:42 +00:00
if [[ -f "$RCPATH" ]] ; then
2016-04-03 07:23:19 +00:00
NAME="paper"
if [[ ! -z "${2+x}" ]] ; then
NAME="$2"
fi
2016-04-04 02:36:19 +00:00
(grep "alias $NAME=" "$RCPATH" > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" "$RCPATH") || (echo "alias $NAME='. $SOURCE'" >> "$RCPATH")
2016-04-03 07:23:19 +00:00
alias "$NAME=. $SOURCE"
echo "You can now just type '$NAME' at any time to access the paper tool."
2016-04-03 16:58:42 +00:00
else
echo "We were unable to setup the paper build tool alias: $RCPATH is missing"
2016-04-02 05:01:58 +00:00
fi
;;
*)
2016-04-03 07:23:19 +00:00
echo "PaperMC build tool command. This provides a variety of commands to build and manage the PaperMC 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:"
2016-05-12 02:59:07 +00:00
echo " * rb, 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 " * m, mcdev | Setup decompiled sources for non-modified NMS files to be imported into an IDE. Can be run from anywhere."
2016-08-19 21:00:59 +00:00
echo " * u, up, upstream | Updates the submodules used by Paper to their latest upstream versions."
2016-05-12 02:59:07 +00:00
echo " * t, testserver | Run the test server with the set of plugins Paper uses as a basis for server tests."
2016-04-03 07:23:19 +00:00
echo ""
echo " These commands require the setup command before use:"
2016-05-12 02:59:07 +00:00
echo " * r, root | Change directory to the root of the project."
echo " * a. api | Move to the Paper-API directory."
echo " * s, server | Move to the Paper-Server directory."
echo " * td, testdirectory | Move to the test-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."
2016-04-03 07:23:19 +00:00
echo ""
2016-05-12 02:59:07 +00:00
echo " * setup | Add an alias to $RCPATH 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."
echo " | The default name for the resulting alias is 'paper', you can give an argument to override"
echo " | this default, such as:"
echo " | . ./paper setup example"
echo " | Which will allow you to run 'example' instead."
2016-04-02 05:01:58 +00:00
;;
esac
2016-04-03 16:58:42 +00:00
unset RCPATH
unset SOURCE
unset basedir
2016-04-10 01:33:32 +00:00
unset -f color
unset -f colorend
2016-04-02 05:01:58 +00:00
unset -f paperstash
unset -f paperunstash
2018-10-24 16:35:42 +00:00
if [[ "$failed" == "1" ]]; then
2018-07-30 21:37:24 +00:00
unset failed
false
else
unset failed
true
2018-08-06 01:31:40 +00:00
fi