minecraft-minder/mineautoshutdown.sh

48 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
2023-01-29 22:37:59 +00:00
# Copyright (C) 2023 zyphlar
#
# 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-01-26 23:15:40 +00:00
DO_STATUS_URL="http://example.com/minecraft.php"
PASSWORD="your_password_here"
status=$(curl -s -X POST -F "action=status" "$DO_STATUS_URL?password=$PASSWORD")
2023-01-26 23:15:40 +00:00
2023-01-27 08:32:24 +00:00
if [[ $status == "running" ]]; then
players=$(python3 $(dirname $0)/minestatus.py | jq ".players")
2023-01-26 23:15:40 +00:00
if [[ $players == 0 ]]; then
if [ ! -f "/tmp/minecount" ]; then
touch /tmp/minecount
fi
2023-01-26 23:15:40 +00:00
count=$(cat /tmp/minecount)
if [[ $count -gt 6 ]]; then
echo "players $players count $count, killing"
curl -s -X POST -F "action=off" "$DO_STATUS_URL?password=$PASSWORD"
2023-01-26 23:15:40 +00:00
echo "0" > /tmp/minecount
else
echo $(($count+1)) > /tmp/minecount
echo "players $players count $count, waiting"
fi
else
echo "players $players, resetting"
echo "0" > /tmp/minecount
fi
else
echo "not active: $status"
2023-01-26 23:15:40 +00:00
fi