source: scripts/usr/local/bin/7dtd-instances.sh @ 13

Last change on this file since 13 was 13, checked in by alloc, 10 years ago

Instances script updated, more info in list and optional command to show a single instace with details

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/bin/bash
2# Version 2
3
4# Lists available 7dtd instances.
5# Returns:
6#  0
7
8. /usr/local/bin/7dtd-common.sh
9checkRootLoadConf
10
11listInstances() {
12        printf "%-*s | %-*s | %-*s | %-*s\n" 20 "Instance name" 8 "Running" 7 "Players" 5 "Port"
13        printf -v line "%*s-+-%*s-+-%*s-+-%*s\n" 20 " " 8 " " 7 " " 5 " "
14        echo ${line// /-}
15        for I in $SDTD_BASE/instances/*; do
16                ins=`basename $I`
17                run=$(isRunning $ins)
18                if [ $run -eq 1 ]; then
19                        run="yes"
20                        tel=$(telnetCommand $ins lp)
21                        cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\  -f 3`
22                else
23                        run="no"
24                        cur=0
25                fi
26
27                max=$(getConfigValue $ins ServerMaxPlayerCount)
28                port=$(getConfigValue $ins ServerPort)
29
30                printf "%-*s | %*s |   %2d/%2d | %5d\n" 20 "$ins" 8 "$run" $cur $max $port
31        done
32        exit 0
33}
34
35showInfo() {
36        if [ -z $1 ]; then
37                echo "Missing parameter <instance>"
38                exit 1
39        fi
40        checkInstance $1
41
42        line() {
43                printf "    %-*s %s\n" 15 "$1" "$2"
44        }
45       
46        echo
47
48        echo "7dtd instance: $1"
49        echo
50
51        res=$(isRunning $1)
52        if [ $res -eq 1 ]; then
53                echo "Status: Running"
54                echo "Open ports:"
55                netstat -nlp | grep $(getInstancePID $1) | sed -r 's/^([^ ]*)\s+.*[^ :]*:([^ ]*).*[^ :]*:[^ ]*.*/    \2 (\1)/g' | sort
56                tel=$(telnetCommand $1 lp)
57                cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\  -f 3`
58                echo "Players: $cur"
59        else
60                echo "Status: NOT running"
61        fi
62
63        echo
64        echo "Game info:"
65        line "Server name:" $(getConfigValue $1 ServerName)
66        line "Password:" $(getConfigValue $1 ServerPassword)
67        line "Max players:" $(getConfigValue $1 ServerMaxPlayerCount)
68        line "World:" $(getConfigValue $1 GameWorld)
69
70        echo
71        echo "Network info:"
72        line "Port:" $(getConfigValue $1 ServerPort)
73        line "Public:" $(getConfigValue $1 ServerIsPublic)
74        if [ "$(getConfigValue $1 ControlPanelEnabled)" = "false" ]; then
75                cp="off"
76        else
77                cp="Port $(getConfigValue $1 ControlPanelPort), Pass $(getConfigValue $1 ControlPanelPassword)"
78        fi
79        line "Control Panel:" "$cp"
80        if [ "$(getConfigValue $1 TelnetEnabled)" = "false" ]; then
81                tn="off"
82        else
83                tn="Port $(getConfigValue $1 TelnetPort), Pass $(getConfigValue $1 TelnetPassword)"
84        fi
85        line "Telnet:" "$tn"
86
87        echo
88        exit 0
89}
90
91showHelp() {
92        name=`basename $0`
93        echo "Unknown parameter: $1"
94        echo "Usage:"
95        echo $name [list]          - List all instances"
96        echo $name show <instance> - Show detailed info on the given instance"
97        exit 0
98}
99
100COMMAND=${1:-list}
101
102case "$COMMAND" in
103        list)
104                listInstances
105        ;;
106        show)
107                showInfo $2
108        ;;
109        *)
110                showHelp $COMMAND
111esac
112exit 1
Note: See TracBrowser for help on using the repository browser.