Skip to content

Instantly share code, notes, and snippets.

@storca
Last active May 26, 2018 08:27
Show Gist options
  • Save storca/dc64705dbfafc0d9af69c363bed3b9a4 to your computer and use it in GitHub Desktop.
Save storca/dc64705dbfafc0d9af69c363bed3b9a4 to your computer and use it in GitHub Desktop.
An easy way to manage your lgsm servers
#!/bin/bash
#TPUT COLORS
blue='tput setaf 4'
mag='tput setaf 5'
green='tput setaf 2'
nc='tput sgr0'
red='tput setaf 1'
#VARIABLES
startingDirectory=$PWD
serversPath="/home/servers/ftp/files" #Change this to the directory you dedicate to this script
echo -n "Fecthing servers..."
cd $serversPath
command="ls --hide=*gsm*"
$command > $serversPath/lgsm.temp
serversCount=$(grep -c "." $serversPath/lgsm.temp)
i=1
while [ "$i" != "$(($serversCount + 1))" ]
do
result=$(awk "NR==$i" $serversPath/lgsm.temp)
servers[(($i - 1))]="$result"
result=""
i=$(($i + 1))
done
$green
echo "OK"
$nc
echo "Number of servers detected : $serversCount"
rm $serversPath/lgsm.temp
cd $startingDirectory
if [ "$1" == "download" ]
then
if [ -e "$serversPath/linuxgsm.sh" ]
then
mkdir $serversPath/$2
$serversPath/linuxgsm.sh $2
mv "$serversPath/$2-2" "$serversPath/$2/$2"
echo "Server $2 installed!"
cd $serversPath/$2
echo -n "Would you like to install $2 now ? {y,n} [y] : "
read answer
if [ "$answer" == "" ] || [ "$answer" == "y" ]
then
$serversPath/$2/$2 install
else
echo "Just run ./$2 auto-install"
fi
else
cd $serversPath
echo "Script missing, downloading it"
wget -N --no-check-certificate https://gameservermanagers.com/dl/linuxgsm.sh && chmod +x linuxgsm.sh && bash linuxgsm.sh
$serversPath/linuxgsm.sh $2
fi
elif [ "$1" == "start" ] || [ "$1" == "stop" ] || [ "$1" == "restart" ] || [ "$1" == "backup" ] || [ "$1" == "update" ]
then
i=0
while [ "$i" != "$serversCount" ]
do
serverToExec=${servers[$i]}
command="$serversPath/$serverToExec/$serverToExec $1"
$command
i=$(($i+1))
serverToExec=""
done
elif [ "$1" == "list" ]
then
if [ "$2" == "available" ]
then
$serversPath/linuxgsm.sh list
elif [ "$2" == "installed" ]
then
i=0
while [ "$i" != "$serversCount" ]
do
serverToExec=${servers[$i]}
echo "Server $i : $serverToExec"
i=$(($i+1))
serverToExec=""
done
else
echo "lgsm list {available, installed}"
fi
else
state=0
i=0
while [ "$i" != "$serversCount" ]
do
serverToExec=${servers[$i]}
if [ "$1" == "$serverToExec" ]
then
if [ "$2" != "" ]
then
state=1
command="$serversPath/$serverToExec/$serverToExec $2"
$command
elif [ "$2" == "cfg" ]
then
command="nano $serversPath/$serverToExec/lgsm/config-lgsm/$serverToExec/$serverToExec.cfg"
$command
else
echo "You need to specify what you want to do with $1"
command="$serversPath/$serverToExec/$serverToExec"
$command
fi
fi
i=$(($i+1))
serverToExec=""
done
if [ $state -eq 0 ]
then
echo "---lgsm help---"
echo "lgsm location : $0"
echo "Usage 1 : lgsm {start, stop, restart} -> starts stops or restarts all the servers found in $serversPath"
echo "Usage 2 : lgsm <server> <any option> launch action on specific server"
echo "Usage 3 : lgsm download <server> downloads the server"
echo "Usage 4 : lgsm list {available, installed}"
echo "---------------"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment