Files
AkarinMC/akarin
2020-04-13 05:11:54 +07:00

176 lines
5.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status
set -e
source "./scripts/functions.sh"
chmod -R -f 777 /scripts # For Github Action
function updateAndPatch {
basedir
if [ "$1" != "skipPaper" ]; then
$scriptdir/updateUpstream.sh "$basedir" || exit 1
fi
$scriptdir/applyPatches.sh "$basedir" || exit 1
}
failed=0
case "$1" in
"r" | "rb" | "rbp" | "rebuild")
(
set -e
basedir
$scriptdir/rebuildPatches.sh "$basedir" || exit 1
) || failed=1
;;
"a" | "p" | "patch" | "apply")
(
set -e
updateAndPatch $2
) || failed=1
;;
"b" | "bu" | "build")
(
set -e
updateAndPatch $2
basedir
mvn -N install || exit 1
cd ${FORK_NAME}-API
mvn -e clean install && cd ../${FORK_NAME}-Server && mvn -e clean install || exit 1
) || failed=1
;;
"jar" | "paperclip")
(
updateAndPatch $2
basedir
mvn -N install
cd ${FORK_NAME}-API
mvn -e clean install && cd ../${FORK_NAME}-Server && mvn -e clean install
basedir
$scriptdir/paperclip.sh
)
;;
"d" | "de" | "deploy")
(
basedir
mvn -N install
cd ${FORK_NAME}-API
mvn clean deploy && cd ../${FORK_NAME}-Server && mvn clean install
)
;;
"u" | "up" | "upstream" | "update")
(
basedir
$scriptdir/updateUpstream.sh "$basedir" $2
)
;;
"r" | "root")
basedir
;;
"a" | "api")
cd "$basedir/Akarin-API"
;;
"s" | "server")
cd "$basedir/Akarin-Server"
;;
"c" | "clean")
rm -rf Akarin-API
rm -rf Akarin-Server
rm -rf Paper
echo "Cleaned build files"
;;
"e" | "edit")
case "$2" in
"s" | "server")
export AKARIN_LAST_EDIT="$basedir/Akarin-Server"
cd "$basedir/Akarin-Server"
(
set -e
gitstash
$gitcmd rebase -i upstream/upstream
gitunstash
)
;;
"a" | "api")
export AKARIN_LAST_EDIT="$basedir/Akarin-API"
cd "$basedir/Akarin-API"
(
set -e
gitstash
$gitcmd rebase -i upstream/upstream
gitunstash
)
;;
"c" | "continue")
cd "$AKARIN_LAST_EDIT"
unset AKARIN_LAST_EDIT
(
set -e
$gitcmd add .
$gitcmd commit --amend
$gitcmd rebase --continue
basedir
$scriptdir/rebuildPatches.sh "$basedir"
)
;;
*)
echo "You must edit either the api or server."
;;
esac
;;
"setup")
if [[ -f ~/.bashrc ]] ; then
NAME="akarin"
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 akarin tool."
fi
;;
*)
echo "Akarin build tool command. This provides a variety of commands to build and manage the Akarin 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 " * r, 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 " * u, upstream | Build Paper upstream, pass arg up to update paper. Can be run from anywhere."
echo " * b, build | Build the API and the server project without deploying. Can be ran anywhere."
echo " * d, deploy | Build and deploy jars of the API and the server project. 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 Akarin-API directory."
echo " * s, server | Move to the Akarin-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 " | . ./akarin setup"
echo " | After you run this command you'll be able to just run 'akarin' from anywhere."
echo " | The default name for the resulting alias is 'akarin', you can give an argument to override"
echo " | this default, such as:"
echo " | . ./akarin setup example"
echo " | Which will allow you to run 'example' instead."
;;
esac
unset RCPATH
unset SOURCE
unset basedir
unset -f color
unset -f colorend
unset -f gitstash
unset -f gitunstash
if [[ "$failed" == "1" ]]; then
unset failed
false
else
unset failed
true
fi