version 1.1.1.1, 2021/08/31 17:00:08 |
version 1.1.1.2, 2021/08/31 17:01:08 |
|
|
# Purpose: Minetest server Control |
# Purpose: Minetest server Control |
# License: Copyright (C) 2021 by Miniontoby <miniontoby@ircnow.org> |
# License: Copyright (C) 2021 by Miniontoby <miniontoby@ircnow.org> |
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
|
VERSION="1.0" |
|
config=[] |
|
config[0]="no"; config[1]="/usr/local/share/minetest/" |
|
|
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
# Alias |
# Alias |
|
|
mthelp() { |
mthelp() { |
echo -e "usage: mtctl start|stop|restart|status|create worldname\n mtctl list|help|version|check_updates"; exit 1 |
echo -e "usage: mtctl start|stop|restart|status|create worldname\n mtctl list|help|version|check_updates"; exit 1 |
} |
} |
|
if [ "x$1" == "x" ]; then mthelp; exit 1; fi |
|
|
|
|
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
# Variables |
# Setup |
if [ "x$1" == "x" ]; then mthelp; exit 1; fi |
|
ACTION="$1" |
|
EXITDIR=$MTDIR/tmp |
|
if [ "$MTBUILD" == "yes" ]; then SERVEREXE="$MTDIR/bin/minetestserver"; else SERVEREXE="`which minetestserver`"; fi |
|
WORLDBASE=$MTDIR/worlds |
|
LOGDIR=$MTDIR/log |
|
EXITFLAGALL=$EXITDIR/minestop.all |
|
WHOAMI=`whoami` |
|
OK=0 |
|
VERSION="1.0" |
|
|
|
|
if [[ "`id -u`" -eq 0 ]]; then CONFDIR=/etc/mtctl; else CONFDIR=$HOME/.mtctl; fi |
|
if [ \! -d $CONFDIR ]; then mkdir -p $CONFDIR || exit 1; fi |
|
if [ \! -f $CONFDIR/config ]; then |
|
mtinfo "\nNo configfile found!\nCreating it now!\n\n" |
|
echo -n 'Use custom build minetest folder (yes/no): '; read MTBUILD |
|
case $MTBUILD in |
|
YES|yes) MTBUILD='yes' |
|
EXAMPLEDIR="$HOME/minetest" |
|
;; |
|
NO|no) MTBUILD='no' |
|
EXAMPLEDIR="$HOME/.minetest" |
|
;; |
|
*) mtinfo "Error, not a valid option!" |
|
exit 1 |
|
;; |
|
esac |
|
echo -n "Insert the path to the minetest folder(eg. $EXAMPLEDIR): "; read MTLOCATION |
|
|
|
echo -e "builded=$MTBUILD\nlocation=$MTLOCATION" > $CONFDIR/config |
|
unset MTBUILD MTLOCATION EXAMPLEDIR |
|
mtinfo "Configfile created!!\n\n" |
|
fi |
|
|
|
while read line; do |
|
linea="`echo $line | grep -F = 2> /dev/null`" |
|
if [ "x$linea" \!= "x" ]; then |
|
varname=$(echo "$line" | cut -d '=' -f 1) |
|
case $varname in |
|
builded) indexnumber=0 |
|
;; |
|
location) indexnumber=1 |
|
;; |
|
esac |
|
config[$indexnumber]=$(echo "$line" | cut -d '=' -f 2-) |
|
fi |
|
done < $CONFDIR/config |
|
|
|
mtsetup() { |
|
EXITDIR=${config[1]}/tmp |
|
if [ "${config[0]}" == "yes" ]; then SERVEREXE="${config[1]}/bin/minetestserver"; else SERVEREXE="`which minetestserver`"; fi |
|
WORLDBASE=${config[1]}/worlds |
|
LOGDIR=${config[1]}/log |
|
EXITFLAGALL=$EXITDIR/minestop.all |
|
OK=0; cd ${config[1]} || exit 1 |
|
touch temp.test && OK=1; if [ "@$OK" == "@0" ]; then mtinfo "Error: Directory tree should be owned by the MT user:\n${config[1]}"; exit 1; fi |
|
rm temp.test || exit 1 |
|
if [ \! -f $SERVEREXE ]; then mtinfo "Error: Couldn't determine SERVEREXE setting\n$SERVEREXE"; exit 1; fi |
|
|
|
mkdir -p $EXITDIR || exit 1 |
|
mkdir -p $WORLDBASE || exit 1 |
|
mkdir -p $LOGDIR || exit 1 |
|
} |
|
|
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
# Normal Functions |
# Normal Functions |
|
|
|
|
echo -ne "\r$NAME($CHECK)$EXTRA" |
echo -ne "\r$NAME($CHECK)$EXTRA" |
} |
} |
|
|
|
|
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
# Pre start |
|
|
|
if [ "$ACTION" == "version" ]; then mtinfo "Version: $VERSION"; exit 0; fi |
|
if [ "@$WHOAMI" \!= "@$MTUSER" ]; then mtinfo "Please switch to $MTUSER"; exit 0; fi |
|
cd $MTDIR || exit 1 |
|
touch temp.test && OK=1; if [ "@$OK" == "@0" ]; then mtinfo "Error: Directory tree should be owned by the MT user:\n$MTDIR"; exit 1; fi |
|
rm temp.test || exit 1 |
|
if [ \! -f $SERVEREXE ]; then mtinfo "Error: Couldn't determine SERVEREXE setting\n$SERVEREXE"; exit 1; fi |
|
|
|
mkdir -p $EXITDIR || exit 1 |
|
mkdir -p $WORLDBASE || exit 1 |
|
mkdir -p $LOGDIR || exit 1 |
|
|
|
|
|
#--------------------------------------------------------------------- |
|
# Functions for executing the actions |
# Functions for executing the actions |
|
|
startMT() { |
startMT() { |
|
|
fi |
fi |
|
|
EXITFLAGWORLD=$EXITDIR/minestop.$NAME |
EXITFLAGWORLD=$EXITDIR/minestop.$NAME |
MINETEST_SUBGAME_PATH=$MTDIR/games |
MINETEST_SUBGAME_PATH=${config[1]}/games |
# MAYBE Export if linux doesnt work |
# MAYBE Export if linux doesnt work |
|
|
rm -f $EXITFLAGALL $EXITFLAGWORLD |
rm -f $EXITFLAGALL $EXITFLAGWORLD |
|
|
|
|
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
# Handle the actions |
# Handle the actions |
|
ACTION="$1" |
|
|
case $ACTION in |
case $ACTION in |
start) |
start) |
|
mtsetup |
startMT "$2" |
startMT "$2" |
;; |
;; |
stop) |
stop) |
|
mtsetup |
stopMT "$2" |
stopMT "$2" |
;; |
;; |
restart) |
restart) |
|
mtsetup |
restartMT "$2" |
restartMT "$2" |
;; |
;; |
status) |
status) |
|
mtsetup |
statusMT "$2" |
statusMT "$2" |
;; |
;; |
list) |
list) |
|
mtsetup |
listMT |
listMT |
;; |
;; |
create) |
create) |
|
mtsetup |
createMT "$2" |
createMT "$2" |
;; |
;; |
version) |
version) |
|
|
mtinfo "Update avaible!\n\nInstalling update NOW!" |
mtinfo "Update avaible!\n\nInstalling update NOW!" |
curl 'https://cvsweb.planetofnix.com/cgi-bin/cvsweb/~checkout~/mtctl/installer.sh?content-type=text/plain' 2> /dev/null | $SHELL |
curl 'https://cvsweb.planetofnix.com/cgi-bin/cvsweb/~checkout~/mtctl/installer.sh?content-type=text/plain' 2> /dev/null | $SHELL |
fi |
fi |
|
;; |
help) |
help) |
mthelp |
mthelp |
;; |
;; |