-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmmokillserver.sh
182 lines (157 loc) · 5.33 KB
/
mmokillserver.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
#########################################################################################################
#
# Copyright (C) 2012 LORDofDOOM <https://github.com/LORDofDOOM>
#
# 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 2 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 <http://www.gnu.org/licenses/>.
#
#########################################################################################################
#-------------------------------------------------------------------------------------------------------#
# INI Parser #
#-------------------------------------------------------------------------------------------------------#
# prefix for all global variables
INI_PREFIX=bash_inifile_
function ini_load {
# param1 inifile
local tmpfile=`(mktemp "${TMPDIR-/tmp}/bash_inifileXXXXXXXX") 2>/dev/null || echo ${TMPDIR-/tmp}/bash_inifile$$`
awk -v INI_PREFIX=${INI_PREFIX} -f - "$1" >$tmpfile <<EOF
# default global section
BEGIN {
FS="[[:space:]]*=[[:space:]]*"
section="globals";
}
{
# kill comments
sub(/;.*/, "");
}
/^\[[^\]]+\]$/ {
section=substr(\$0, 2, length(\$0) -2);
# map section to valid shell variables
gsub(/[^[[:alnum:]]/, "_", section)
printf "%s%s_keys=()\n", INI_PREFIX, section, INI_PREFIX, section
printf "%s%s_values=()\n", INI_PREFIX, section, INI_PREFIX, section
}
\$1 ~ /^[[:alnum:]\._]+\$/ {
# remove trail/head single/double quotes
gsub(/(^[\"\']|[\'\"]\$)/, "", \$2);
# escape inside single quotes
gsub(/\47/, "'\"'\"'", \$2);
printf "%s%s_keys=(\"\${%s%s_keys[@]}\" '%s')\n", INI_PREFIX, section, INI_PREFIX, section, \$1
printf "%s%s_values=(\"\${%s%s_values[@]}\" '%s')\n", INI_PREFIX, section, INI_PREFIX, section, \$2
}
EOF
while read line ; do
eval $line
done <${tmpfile}
rm ${tmpfile}
}
function ini_get_value {
# param1 section
# param2 key
# map section to valid bash variable like in awk parsing
local section=${1//[![:alnum:]]/_}
local keyarray=${INI_PREFIX}${section}_keys[@]
local valuearray=${INI_PREFIX}${section}_values[@]
local keys=("${!keyarray}")
local values=("${!valuearray}")
for (( i=0; i<${#keys[@]}; i++ )); do
if [[ "${keys[$i]}" = "$2" ]]; then
echo "${values[$i]}"
return 0
fi
done
return 1
}
function ini_get_sections {
eval local prefix_arrays=\${!$INI_PREFIX\*}
for varname in $prefix_arrays; do
# grep for key arrays
local arrayname=${varname#${INI_PREFIX}}
# strip trailing keys suffix
if [[ ${arrayname%*_keys} != ${arrayname} ]]; then
echo ${arrayname%*_keys}
fi
done
}
function ini_get_keys {
#param1 section
# map section to valid bash variable like in awk parsing
local section=${1//[![:alnum:]]/_}
local keyarray=${INI_PREFIX}${section}_keys[@]
local keys=("${!keyarray}")
echo ${keys[@]}
}
#-------------------------------------------------------------------------------------------------------#
# Color Codes #
#-------------------------------------------------------------------------------------------------------#
#white='\E[37;40m'
#red='\E[31;40m\033[1m'
#green='\E[32;40m\033[1m'
#yellow='\E[33;40m\033[1m'
red='\E[0;31m'
RED='\E[1;31m'
blue='\E[0;34m'
BLUE='\E[1;34m'
cyan='\E[0;36m'
CYAN='\E[1;36m'
NC='\033[0m' # no color
black='\E[0;30m'
BLACK='\E[1;30m'
green='\E[0;32m'
GREEN='\E[1;32m'
yellow='\E[0;33m'
YELLOW='\E[1;33m'
magenta='\E[0;35m'
MAGENTA='\E[1;35m'
white='\E[0;37m'
WHITE='\E[1;37m'
alias Reset="tput sgr0" # Reset colors #+ without clear command
cecho () # Color-echo.
# Argument $1 = Nachricht
# Argument $2 = Farbe
{
local default_msg="Text fehlt"
message=${1:-$default_msg} # default if no echo text
color=${2:-$white} # default color is white
echo -e "$color$message"
#Reset # Reset to normal color
tput sgr0 # Reset to normal color
return
}
#-------------------------------------------------------------------------------------------------------#
# Script variables #
#-------------------------------------------------------------------------------------------------------#
WORKING_DIR=$PWD
if [ "$1" != "" ]; then
if [ ! -f $1 ];
then
echo "$1 not found - Exit"
exit
fi
ini_load $1
else
if [ ! -f mmoconfig.ini ];
then
echo "mmoconfig.ini not found - Exit"
exit
fi
ini_load mmoconfig.ini
fi
#INI Admin
LAUNCHER_SCREENNAME=`ini_get_value LAUNCHER SCREENNAME`
LAUNCHER_USERNAME=`ini_get_value LAUNCHER USERNAME`
#-------------------------------------------------------------------------------------------------------#
# Script start #
#-------------------------------------------------------------------------------------------------------#
sudo -u $LAUNCHER_USERNAME kill `sudo -u $LAUNCHER_USERNAME screen -ls |grep $LAUNCHER_SCREENNAME |awk -F . '{print $1}'|awk '{print $1}'`