bazar_alea/start-bazar-server.sh

146 lines
3.1 KiB
Bash
Raw Normal View History

2023-10-22 18:30:36 +00:00
#!/bin/bash
#
# Script to launch server
#
# Copyright (C) 2023 AleaJactaEst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Example : Start server with trace level (more debug message), and listen all network card (0.0.0.0) and port : 9876
# ./start-bazar-server.sh -b -o ' -t -l "0.0.0.0" -p 9876'
2023-10-22 18:30:36 +00:00
declare DEBUG=0
declare VERBOSE=0
2023-10-22 18:30:36 +00:00
declare HELP=0
declare BUILD=0
declare WORKDIR="$(dirname $(readlink -f $0))"
declare RUSTDIR="$WORKDIR/.rust"
declare SERVERDIR="$WORKDIR/server"
declare OPTIONS=""
declare LISTEN=""
declare PORT=""
2023-10-22 18:30:36 +00:00
function msg_debug()
{
if [ $DEBUG -ne 0 ]
then
echo "### DEBUG : $*" >&2
fi
}
function msg_info()
{
echo "--- INFO : $*" >&2
}
function msg_error()
{
echo "*** ERROR : $*" >&2
}
function byebye()
{
local CODE=$?
if [ $CODE -ne 0 ]
then
msg_error "return code:$code"
else
msg_info "End"
fi
exit $CODE
}
while getopts hdvbo:l:p: flag
2023-10-22 18:30:36 +00:00
do
case "${flag}" in
h) HELP=1;;
d) DEBUG=1;;
v) VERBOSE=1;;
2023-10-22 18:30:36 +00:00
b) BUILD=1;;
o) OPTIONS=${OPTARG};;
l) LISTEN=${OPTARG};;
p) PORT=${OPTARG};;
2023-10-22 18:30:36 +00:00
*) HELP=1;;
esac
done
if [[ $HELP -ne 0 ]]
then
cat << EOF
$(basename $0) [Option] : Donwload Launch Godot
Option:
-h : Show help
-d : Show debug message
-v : Show verbose message
2023-10-22 18:30:36 +00:00
-b : (re)build program
-o : option send to server (like --help)
-l : <IP> network listen
-p : <PORT> port listen
2023-10-22 18:30:36 +00:00
EOF
exit 1
fi
trap byebye EXIT
msg_info "Start"
msg_debug "WORKDIR:$WORKDIR"
if [ $DEBUG -ne 0 ]
then
OPTIONS="$OPTIONS -d"
fi
if [ $VERBOSE -ne 0 ]
then
OPTIONS="$OPTIONS -v"
fi
if [ -n "$LISTEN" ]
then
OPTIONS="$OPTIONS -l $LISTEN"
fi
if [ -n "$PORT" ]
then
OPTIONS="$OPTIONS -p $PORT"
fi
2023-10-22 18:30:36 +00:00
if [[ ($BUILD -ne 0) || (! -x $SERVERDIR/target/debug/server) ]]
then
export CARGO_HOME="$RUSTDIR/.cargo"
export RUSTUP_HOME="$RUSTDIR/.rustup"
mkdir -p $RUSTDIR
if [ ! -f $RUSTDIR/install.sh ]
then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > $RUSTDIR/install.sh
fi
if [ ! -f $RUSTDIR/.cargo/env ]
then
sh .rust/install.sh -t $RUSTDIR/.cargo --no-modify-path -y
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -h
fi
if [ -f $RUSTDIR/.cargo/env ]
then
source $RUSTDIR/.cargo/env
cd $SERVERDIR
cargo build || exit 2
2023-10-22 18:30:36 +00:00
else
msg_error "Error to load envi rust"
exit 2
fi
msg_info "Build finished"
2023-10-22 18:30:36 +00:00
fi
#echo "OPTIONS:$OPTIONS"
$SERVERDIR/target/debug/server $OPTIONS
2023-10-22 18:30:36 +00:00
# END (call function byebye)