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/>.
|
|
|
|
#
|
2023-10-23 20:43:58 +00:00
|
|
|
# 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
|
2023-10-23 20:43:58 +00:00
|
|
|
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"
|
2023-11-05 14:54:21 +00:00
|
|
|
declare CERTDIR="$WORKDIR/.cert"
|
2023-10-23 20:43:58 +00:00
|
|
|
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
|
2023-11-05 14:54:21 +00:00
|
|
|
msg_error "return code:$CODE"
|
2023-10-22 18:30:36 +00:00
|
|
|
else
|
|
|
|
msg_info "End"
|
|
|
|
fi
|
|
|
|
exit $CODE
|
|
|
|
}
|
|
|
|
|
2023-10-23 20:43:58 +00:00
|
|
|
while getopts hdvbo:l:p: flag
|
2023-10-22 18:30:36 +00:00
|
|
|
do
|
|
|
|
case "${flag}" in
|
|
|
|
h) HELP=1;;
|
|
|
|
d) DEBUG=1;;
|
2023-10-23 20:43:58 +00:00
|
|
|
v) VERBOSE=1;;
|
2023-10-22 18:30:36 +00:00
|
|
|
b) BUILD=1;;
|
2023-10-23 20:43:58 +00:00
|
|
|
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
|
2023-10-23 20:43:58 +00:00
|
|
|
-v : Show verbose message
|
2023-10-22 18:30:36 +00:00
|
|
|
-b : (re)build program
|
2023-10-23 20:43:58 +00:00
|
|
|
-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"
|
|
|
|
|
2023-11-05 14:54:21 +00:00
|
|
|
if [[ (! -f $CERTDIR/server-cert.pem) || (! -f $CERTDIR/server-key.pem) ]]
|
|
|
|
then
|
|
|
|
msg_error "Missing certificate"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2023-10-23 20:43:58 +00:00
|
|
|
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
|
2023-10-23 20:43:58 +00:00
|
|
|
cargo build || exit 2
|
2023-10-22 18:30:36 +00:00
|
|
|
else
|
|
|
|
msg_error "Error to load envi rust"
|
|
|
|
exit 2
|
|
|
|
fi
|
2023-10-25 20:29:45 +00:00
|
|
|
msg_info "Build finished"
|
2023-10-22 18:30:36 +00:00
|
|
|
fi
|
|
|
|
|
2023-10-23 20:43:58 +00:00
|
|
|
#echo "OPTIONS:$OPTIONS"
|
2023-11-05 14:54:21 +00:00
|
|
|
$SERVERDIR/target/debug/server $OPTIONS --serverkey $CERTDIR/server-key.pem --servercert $CERTDIR/server-cert.pem
|
2023-10-22 18:30:36 +00:00
|
|
|
|
|
|
|
# END (call function byebye)
|