#!/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 . # # 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' declare DEBUG=0 declare VERBOSE=0 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="" 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 do case "${flag}" in h) HELP=1;; d) DEBUG=1;; v) VERBOSE=1;; b) BUILD=1;; o) OPTIONS=${OPTARG};; l) LISTEN=${OPTARG};; p) PORT=${OPTARG};; *) 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 -b : (re)build program -o : option send to server (like --help) -l : network listen -p : port listen 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 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 else msg_error "Error to load envi rust" exit 2 fi msg_info "Build finished" fi #echo "OPTIONS:$OPTIONS" $SERVERDIR/target/debug/server $OPTIONS # END (call function byebye)