-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.sh
executable file
·210 lines (186 loc) · 5.29 KB
/
start.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
# Obfuscation script to pull from Github and replace $variables
# Declare variables
source /home/config/secret.key
ENDER_RESET_TIME='0'
UPDATE_SERVER=1
UPDATE_PLUGIN=1
HEAPSIZE=1024
JAR_FILE='server.jar'
DEOBFUSCATE=1
#------------------
# Begin Switches
#------------------
while [ "$#" -gt 0 ];
do
case "$1" in
-h|--help)
echo "-h|--help was triggered"
exit 1
;;
-e|--ender)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
ENDER_RESET_TIME=$2
shift
else
echo "Error in -e|--ender syntax. Script failed."
exit 1
fi
;;
-xms|--min-heap-size)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
MIN_HEAP_SIZE=$2
shift
else
echo "Error in -hs|--heap-size syntax. Script failed."
exit 1
fi
;;
-xmx|--max-heap-size)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
MAX_HEAP_SIZE=$2
shift
else
echo "Error in -hs|--heap-size syntax. Script failed."
exit 1
fi
;;
-n|--name)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
SERVER_NAME=$2
shift
else
echo "Error in -n|--name syntax. Script failed."
exit 1
fi
;;
-jf|--jar-file)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
JAR_FILE=$2
shift
else
echo "Error in -jf|--jar-file syntax. Script failed."
exit 1
fi
;;
-us|--update-server)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
UPDATE_SERVER=$2
shift
else
echo "Error in -us|--update-server syntax. Script failed."
exit 1
fi
;;
-up|--update-plugin)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
UPDATE_PLUGIN=$2
shift
else
echo "Error in -up|--update-plugin syntax. Script failed."
exit 1
fi
;;
-d|--deobfuscate)
if [[ "$#" -gt 1 && ! "$2" = \-* ]]; then
DEOBFUSCATE=$2
shift
else
echo "Error in -d|--deobfuscate syntax. Script failed."
exit 1
fi
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
'') # Empty case: If no more options then break out of the loop.
break
;;
*) # Anything unrecognized
echo "The value "$1" was not expected. Script failed."
exit 1
;;
esac
shift
done
#------------------
# DEFINE SERVER NAME
#------------------
SERVER_NAME=${secret_key['$server_name_'$SERVER_NAME]}
if [ -z "$SERVER_NAME" ]; then
echo "Please set a correct server name using --name"
exit 1
fi
#------------------
# Pull from Github
#------------------
if [[ $UPDATE_SERVER == 1 ]]; then
git reset --hard
git pull --recurse-submodules
git submodule update --init --recursive --force
fi
#------------------
# Deobfuscation
#------------------
if [[ $DEOBFUSCATE == 1 ]]; then
echo "Starting to deobfuscate files..."
for i in $(find . -regextype posix-basic -regex '.*/.\{1,13\}.\(yml\|txt\|menu\|properties\|key\|conf\|php\)');
do
sed -i "s|\$server_name\b|$SERVER_NAME|g" $i
for key in "${!secret_key[@]}"
do
sed -i "s|$key|${secret_key[$key]}|g" $i
done
done
echo "Deobfuscation complete."
fi
#------------------
# Reset end dimension
#------------------
if [[ $ENDER_RESET_TIME > 0 && $(find . -name '*_the_end') ]];
then
ENDER_DIR=$(find . -type d -name "*_the_end" | wc -l)
ENDER_REGION_DIR=''$ENDER_DIR'/DIM1/region'
if [ $(find $ENDER_DIR -mtime -$ENDER_RESET_TIME -type f -name "$level.dat" 2>/dev/null) ]; then
echo "Time to reset end dimension."
rm "$ENDER_DIR/level.dat" "$ENDER_REGION_DIR/r.0.0.mca" "$ENDER_REGION_DIR/r.0.-1.mca" "$ENDER_REGION_DIR/r.-1.0.mca" "$ENDER_REGION_DIR/r.-1.-1.mca"
else
echo "Not time to reset end dimension."
fi
fi
#------------------
# Update plugins
#------------------
if [[ $UPDATE_PLUGIN > 0 ]];
then
rm plugins/*.jar
for i in $(tail --lines=+3 plugin.md | awk '/\|/ {print $2}')
do
find /home/plugins/ -iregex '.*/'$i'\([^A-Za-z]\(.+\)?\)?.jar' -exec cp "{}" plugins \;
done
fi
#------------------
# Java arguments
#------------------
G1NewSizePercent=40
G1MaxNewSizePercent=50
G1HeapRegionSize=16
G1ReservePercent=15
InitiatingHeapOccupancyPercent=20
if (($MAX_HEAP_SIZE < 12000))
then
G1NewSizePercent=30
G1MaxNewSizePercent=40
G1HeapRegionSize=8
G1ReservePercent=20
InitiatingHeapOccupancyPercent=15
fi
#------------------
# Java startup
#------------------
echo "Starting server..."
java -Xms${MIN_HEAP_SIZE}M -Xmx${MAX_HEAP_SIZE}M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=${G1NewSizePercent} -XX:G1MaxNewSizePercent=${G1MaxNewSizePercent} -XX:G1HeapRegionSize=${G1HeapRegionSize}M -XX:G1ReservePercent=${G1ReservePercent} -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=${InitiatingHeapOccupancyPercent} -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -Dterminal.jline=false -Dterminal.ansi=true -Dfile.encoding=UTF-8 -Dcom.mojang.eula.agree=true -jar $JAR_FILE nogui