This is a little startscript i made for handling multiple server configs.
By no means fail prove, if you have any improvements let me know!
Change the USERNAME to the Username you are logged in with.
Usage example:
bash lfs.sh start "setup"
By no means fail prove, if you have any improvements let me know!
Change the USERNAME to the Username you are logged in with.
Usage example:
bash lfs.sh start "setup"
USERNAME='lfs'
ME=`whoami`
as_user() {
if [ $ME == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}
lfs_start() {
if [ "$1" ]
then
command="$1";
if screen -list | grep -q "$command"
then
echo "Screen session with this config file already running!"
else
if [ -f "$command.cfg" ]
then
as_user "screen -dmS $command"
sleep 3
as_user "screen -p 0 -S $command -X eval 'stuff \"wine LFS.exe /cfg=$command.cfg\"\015'"
if screen -list | grep -q "$command"
then
echo "$command started!"
else
echo "Couldn't start $command"
fi
else
echo "Couldn't find Config File!"
fi
fi
fi
}
lfs_stop() {
if [ "$1" ]
then
command="$1";
if screen -list | grep -q "$command"
then
if [ -f "$command.cfg" ]
then
as_user "screen -p 0 -S $command -X eval 'stuff \"^C\"\015'"
sleep 3
as_user "screen -p 0 -S $command -X eval 'stuff \"exit\"\015'"
sleep 3
if screen -list | grep -q "$command"
then
echo "Couldn't stop screen session!"
else
echo "$command is stoppped!"
fi
else
echo "No Config File with this name exists! Stopping anyway!"
as_user "screen -p 0 -S $command -X eval 'stuff \"^C\"\015'"
sleep 3
as_user "screen -p 0 -S $command -X eval 'stuff \"exit\"\015'"
sleep 3
if screen -list | grep -q "$command"
then
echo "Couldn't stop screen session!"
else
echo "$command is stoppped!"
fi
fi
else
echo "No Screen Session with this Config File Found!"
fi
fi
}
case "$1" in
start)
lfs_start "$2"
;;
stop)
lfs_stop "$2"
;;
*)
echo "Usage: bash lfs.sh stop|start \"configfile\"}"
exit 1
;;
esac