[factions-banking] Updated build script to run both server and client at once properly with no options plugged in
Some checks failed
build / build (21) (push) Has been cancelled

This commit is contained in:
Jkibbels 2024-12-21 02:28:28 -05:00
parent b6b73d96e8
commit a7f8504c2c

51
run.sh
View File

@ -13,8 +13,10 @@ LOG_LEVEL=1
BUILD_PATH="build"
RUN_PATH="run"
RESET_ALL=0
RUN_ALL=1
GRADLEW_PATH=${REPO_TOP}/gradlew
declare SERVER_PID
declare CLIENT_PID
# $1 is text level
# LEVELS:
@ -48,18 +50,40 @@ function help() {
echo -e " -r: Reset everything. This will nuke the previous install area and re-build EVERYTHING from scratch"
echo -e " -b <path>: Specify the build area (default is cur dir $(pwd)/build)"
echo -e " -b2 <path>: Specify the run area (default is cur dir $(pwd)/run)"
echo -e " -a: Run everything at once (default option if nothing specified)"
echo -e " -h: Bring up this help message"
}
function ExitAll() {
TermWrite 1 "Cleaning up..."
if [ ! -z $SERVER_PID ]; then
TermWrite 1 "Killing PID $SERVER_PID"
kill -9 $SERVER_PID
fi
if [ ! -z $CLIENT_PID ]; then
TermWrite 1 "Killing PID $CLIENT_PID"
kill -9 $CLIENT_PID
fi
# Close with exit code 1 because a clean close isn't guarenteed with this
exit 1
}
# Capture CTRL+C event into ExitAll function
trap ExitAll INT
while getopts ":schl:g:r:b:b2:" opt; do
case ${opt} in
s)
TermWrite 2 "SERVER MODE ENABLED"
SERVER_MODE=1
RUN_ALL=0
;;
c)
TermWrite 2 "CLIENT MODE ENABLED"
CLIENT_MODE=1
RUN_ALL=0
;;
h)
help
@ -125,11 +149,13 @@ if [[ $RESET_ALL -eq 1 ]]; then
TermWrite 1 "All completed!"
fi
if [[ $RUN_ALL -eq 0 ]]; then
if [[ $SERVER_MODE -eq 1 ]]; then
TermWrite 1 "Running ./gradlew build"
$BASH_PATH $GRADLEW_PATH build
TermWrite 1 "Running ./gradlew runServer"
$BASH_PATH $GRADLEW_PATH runServer
$BASH_PATH $GRADLEW_PATH runServer &
SERVER_PID=$!
fi
if [[ $CLIENT_MODE -eq 1 ]]; then
@ -137,7 +163,26 @@ if [[ $CLIENT_MODE -eq 1 ]]; then
$BASH_PATH $GRADLEW_PATH build
TermWrite 1 "Running ./gradlew runClient"
$BASH_PATH $GRADLEW_PATH runClient
CLIENT_PID=$!
fi
else
# Run everything
TermWrite 1 "Running both client and server processes..."
$BASH_PATH $GRADLEW_PATH clean
$BASH_PATH $GRADLEW_PATH build
$BASH_PATH $GRADLEW_PATH runClient &
CLIENT_PID=$!
# We do not run the server in the background so the player may run commands in the server terminal
$BASH_PATH $GRADLEW_PATH runServer
SERVER_PID=$!
TermWrite 1 "Server and client processes started"
fi
TermWrite 1 "Finished running gradlew command with exit code $?"
exit 0
# We wait and hang here until BOTH background processes finish (or until CTRL+C event)
wait
# Clean up and leave
ExitAll