forked from endofzero/Minecraft-Sheller
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminecraft.sh
executable file
·675 lines (620 loc) · 21.9 KB
/
minecraft.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
#!/bin/bash
# version 2.5 (4/4/11)
# original author : Relliktsohg
# continued contributions: Maine, endofzero
# dopeghoti, demonspork, robbiet480, sandain, orospakr, jdiamond, FabianN
# https://github.com/endofzero/Minecraft-Sheller
# This is the path to where the location of the config.sh file resides.
# If no file is found, the Configuration settings in this file will be used.
CONFIG_PATH=/home/minecraft/minecraft-Sheller
# Configuration
# Main
WORLD_NAME="world"
OFFLINE_NAME=$WORLD_NAME-offline
MC_PATH=/home/minecraft
SCREEN_NAME="minecraft"
MEMMAX=1536
DISPLAY_ON_LAUNCH=0
SERVER_OPTIONS=""
# Modifications
SERVERMOD=1
MODJAR="craftbukkit-0.0.1-SNAPSHOT.jar"
RUNECRAFT=1
# Backups
BKUP_PATH=$MC_PATH/backup
BKUP_DAYS_INCR=2
BKUP_DAYS_FULL=5
BACKUP_FULL_LINK=${BKUP_PATH}/${WORLD_NAME}_full.tgz
BACKUP_INCR_LINK=${BKUP_PATH}/${WORLD_NAME}_incr.tgz
# Snapshots (for WorldEdit and other .zip based utilities)
SNAP_PATH=$MC_PATH/snapshot
SNAP_DAYS=4
# Logs
LOG_TDIR=/var/www/minecraft/logs
LOGS_DAYS=14
# Mapping
CARTO_PATH=$MC_PATH/carto
MAPS_PATH=/var/www/minecraft/maps
CARTO_OPTIONS="-q -s -m 4"
CARTO_NIGHT=0
CARTO_NIGHTOPTIONS="-q -s -m 4"
CARTO_CAVE=0
CARTO_CAVEOPTIONS="-q -s -m 4"
DATE_DIR=0
BIOME_PATH=/home/minecraft/BiomeExtractor
MAP_CHANGES=0
MCOVERVIEWER_PATH=$MC_PATH/Overviewer/
MCOVERVIEWER_MAPS_PATH=/var/www/minecraft/maps/Overview
MCOVERVIEWER_OPTIONS="--rendermodes=lighting,night"
PNG_OPTIMIZE=0
OPTI_FIND_OPTIONS="-cmin +180"
OPTIPNG_OPTIONS="-o3"
ADVDEF_OPTIONS="-z4"
# End of configuration
[ -f $CONFIG_PATH/config.sh ] && source $CONFIG_PATH/config.sh
# Make sure that Java, Perl, GNU Screen, and GNU Wget are installed.
JAVA=$(which java)
PERL=$(which perl)
SCREEN=$(which screen)
WGET=$(which wget)
OPTIPNG=$(which optipng)
ADVDEF=$(which advdef)
if [ ! -e $JAVA ]; then
printf "Java not found!\n"
printf "Try installing this with:\n"
printf "sudo apt-get install openjdk-6-jre\n"
exit 1
fi
if [ ! -e $PERL ]; then
printf "Perl not found!\n"
printf "Try installing this with:\n"
printf "sudo apt-get install perl\n"
exit 1
fi
if [ ! -e $SCREEN ]; then
printf "GNU Screen not found!\n"
printf "Try installing this with:\n"
printf "sudo apt-get install screen\n"
exit 1
fi
if [ ! -e $WGET ]; then
printf "GNU Wget not found!\n"
printf "Try installing this with:\n"
printf "sudo apt-get install wget\n"
exit 1
fi
if [[ ! -e "$OPTIPNG" && "$PNG_OPTIMIZE" == "1" ]]; then
printf "Optipng not found!\n"
printf "Try installing this with:\n"
printf "sudo apt-get install optipng\n"
exit 1
fi
if [[ ! -e "$ADVDEF" && "$PNG_OPTIMIZE" == "1" ]]; then
printf "ADVDEF not found!\n"
printf "Try installing this with:\n"
printf "sudo apt-get install advancecomp\n"
exit 1DATE_DIR
fi
if [[ -e $MC_PATH/server.log.lck ]]; then
# ps -e | grep java | wc -l
ONLINE=1
else
ONLINE=0
fi
# Get the PID of our Java process for later use. Better
# than just killing the lowest PID java process like the
# original verison did, but still non-optimal.
#
# Explanation:
#
# Find the PID of our screen that's running Minecraft.
# Then, use PS to find children of that screen whose
# command is 'java'.
# SCREEN_PID=$(screen -list | grep $SCREEN_NAME | grep -iv "No sockets found" | head -n1 | sed "s/^\s//;s/\.$SCREEN_NAME.*$//")
USERNAME=$(whoami)
SCREEN_PID=$(screen -ls $SCREEN_NAME | $PERL -ne 'if ($_ =~ /^\t(\d+)\.$SCREEN_NAME.*$/) { print $1; }')
# echo "$SCREEN_PID $JAVA_PID"
if [[ -z $SCREEN_PID ]]; then
# Our server seems offline, because there's no screen running.
# Set MC_PID to a null value.
MC_PID=''
else
# MC_PID=$(ps $SCREEN_PID -F -C java -o pid,ppid,comm | tail -1 | awk '{print $2}')
MC_PID=$(ps -a -u $USERNAME -o pid,ppid,comm | $PERL -ne 'if ($_ =~ /^\s*(\d+)\s+'$SCREEN_PID'\s+java/) { print $1; }')
fi
display() {
screen -x $SCREEN_NAME
}
server_launch() {
echo "Launching minecraft server..."
if [[ 1 -eq $SERVERMOD ]]; then
echo $MODJAR
cd $MC_PATH
screen -dmS $SCREEN_NAME java -server -Xmx${MEMMAX}M -Xincgc $SERVER_OPTIONS -jar $MODJAR nogui
sleep 1
else
echo "minecraft_server.jar"
cd $MC_PATH
screen -dmS $SCREEN_NAME java -server -Xmx${MEMMAX}M -Xincgc $SERVER_OPTIONS -jar minecraft_server.jar nogui
sleep 1
fi
}
server_stop() {
echo "Stopping minecraft server..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "stop.\r")"
sleep 5
}
sync_offline() {
if [[ -e $MC_PATH/synclock ]]; then
echo "Previous sync hasn't completed or has failed"
else
touch $MC_PATH/synclock
echo "Sync in progress..."
if [[ 1 -eq $ONLINE ]]; then
echo "Issuing save-all command, wait 5s...";
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-all\r")"
sleep 5
echo "Issuing save-off command..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-off\r")"
sleep 1
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say World sync in progress, saving is OFF.\r")"
fi
mkdir -p $MC_PATH/$OFFLINE_NAME/
rsync -a $MC_PATH/$WORLD_NAME/ $MC_PATH/$OFFLINE_NAME/
WORLD_SIZE=$(du -s $MC_PATH/$WODATE_DIRRLD_NAME/ | sed s/[[:space:]].*//g)
OFFLINE_SIZE=$(du -s $MC_PATH/$OFFLINE_NAME/ | sed s/[[:space:]].*//g)
echo "WORLD : $WORLD_SIZE KB"
echo "OFFLINE: $OFFLINE_SIZE KB"
if [[ 1 -eq $ONLINE ]]; then
echo "Issuing save-on command..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-on\r")"
sleep 1
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say World sync is complete, saving is ON.\r")"
fi
rm $MC_PATH/synclock
echo "Sync is complete"
fi
}
pngoptimize (){
if [[ "$PNG_OPTIMIZE" == "1" && -n "$OPTI_DIR" ]]; then #Optimize images if it's set
# If there is the spawn or mineral dir it must be overviewer (and using transparent overlays). This doesn't play nice with optipng, so first optimizing the non-transparent png's with optipng, then going back over and optimize the spawn and mineral overlays using only advdef. If there are no signs of overlays, just go for the full optimization.
if [[ -e "$OPTI_DIR/spawn" || -e "$OPTI_DIR/mineral" ]]; then
echo "compressing images..."
find $OPTI_DIR -name "*.png" -o -path '$OPTI_DIR/spawn' -prune -o -path '$OPTI_DIR/mineral' -prune -o $OPTI_FIND_OPTIONS -exec optipng $OPTIPNG_OPTIONS {} \; -exec advdef $ADVDEF_OPTIONS {} \;
find $OPTI_DIR -name "*.png" -o -path '$OPTI_DIR/lighting' -prune -o -path '$OPTI_DIR/night' -prune -o -path '$OPTI_DIR/cave' -prune -o $OPTI_FIND_OPTIONS -exec advdef $ADVDEF_OPTIONS {} \;
else
find $OPTI_DIR -name "*.png" -o $OPTI_FIND_OPTIONS -exec optipng $OPTIPNG_OPTIONS {} \; -exec advdef $ADVDEF_OPTIONS {} \;
fi
OPTI_DIR=
fi
}
if [[ $# -gt 0 ]]; then
case "$1" in
#################################################################
"status")
if [[ 1 -eq $ONLINE ]]; then
echo "Minecraft server seems ONLINE."
else
echo "Minecraft server seems OFFLINE."
fi
;;
#################################################################
"start")
if [[ 1 -eq $ONLINE ]]; then
echo "Server seems to be already running !"
case $2 in
"force")
# TODO:
# Still needs work, but at least we try
# to use the PID we grabbed earlier.
# The fallback is still to blindly
# kill the lowest-PID Java process running
# on the server. This is very bad form.
if [[ -z $MC_PID ]]; then
kill $(ps -e | grep java | cut -d " " -f 1)
else
kill $MC_PID
fi
rm -fr $MC_PATH/*.log.lck 2> /dev/null/;;
esac
else
server_launch
if [[ 1 -eq $DISPLAY_ON_LAUNCH ]]; then
display
fi
fi
;;
#################################################################
"stop")
if [[ 1 -eq $ONLINE ]]; then
server_stop
else
echo "Server seems to be offline..."
case $2 in
"force")
echo "Forcing server to stop if it's lying.."
# TODO:
# Still needs work, but at least we try
# to use the PID we grabbed earlier.
# The fallback is still to blindly
# kill the lowest-PID Java process running
# on the server. This is very bad form.
if [[ -z $MC_PID ]]; then
kill $(ps -e | grep java | cut -d " " -f 1)
else
kill $MC_PID
fi
rm -fr $MC_PATH/*.log.lck 2> /dev/null/
;;
esac
fi
;;
#################################################################
"restart")
if [[ 1 -eq $ONLINE ]]; then
case $2 in
"warn")
echo "30 Second Warning."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Server will restart in 30s !\r")"
sleep 20
echo "10 Second Warning."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Server will restart in 10s !\r")"
sleep 10
;;
esac
server_stop
fi
server_launch
if [[ 1 -eq $DISPLAY_ON_LAUNCH ]]; then
display
fi
;;
#################################################################
"say")
if [[ 1 -eq $ONLINE ]]; then
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say $*\r")"
sleep 1
else
echo "Server seems to be offline..."
fi
;;
#################################################################
"tell")
if [[ 1 -eq $ONLINE ]]; then
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "tell $2 $*\r")"
sleep 1
else
echo "Server seems to be offline..."
fi
;;
#################################################################
"sync")
if [[ "purge" == $2 ]]; then
echo "Purging offline folder..."
rm -rf $MC_PATH/$OFFLINE_NAME/
echo "Purge Complete"
fi
sync_offline
;;
#################################################################
"logs")
mkdir -p $LOG_TDIR
cd $LOG_TDIR
case $2 in
"clean")
#Move all old log folders into the backup directory based on $LOGS_DAYS
mkdir -p $BKUP_PATH/logs
find $LOG_TDIR -type d -mtime +$LOGS_DAYS -print | xargs -I xxx mv xxx $BKUP_PATH/logs/
;;
esac
DATE=$(date +%Y-%m-%d)
LOG_NEWDIR=$DATE-logs
if [[ -e $LOG_TDIR/$LOG_NEWDIR ]]; then
rm $LOG_TDIR/$LOG_NEWDIR/*
else
mkdir $LOG_TDIR/$LOG_NEWDIR
fi
DATE=$(date +%d-%m-%Hh%M)
LOG_TFILE=logs-$DATE.log
cd $MC_PATH
cat server.log >> $LOG_TDIR/$LOG_NEWDIR/$LOG_TFILE
if [[ -e $LOG_TDIR/ip-list.log ]]; then
cat $LOG_TDIR/ip-list.log | sort | uniq > $LOG_TDIR/templist.log
fi
cat $LOG_TDIR/$LOG_NEWDIR/$LOG_TFILE | egrep '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+.+logged in' | sed -e 's/.*\[INFO\]\s//g' -e 's/\[\//\t/g' -e 's/:.*//g' >> $LOG_TDIR/templist.log
cat $LOG_TDIR/templist.log | sort | uniq -w 4 > $LOG_TDIR/ip-list.log
rm $LOG_TDIR/templist.log
cat $LOG_TDIR/$LOG_NEWDIR/$LOG_TFILE | egrep 'logged in|lost connection' | sed -e 's/.*\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\).\[INFO\].\([a-zA-Z0-9_]\{1,\}\).\{1,\}logged in/\1\t\2 : connected/g' -e 's/.*\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\).\[INFO\].\([a-zA-Z0-9_]\{1,\}\).lost connection.*/\1\t\2 : disconnected/g' >> $LOG_TDIR/$LOG_NEWDIR/connexions-$DATE.log
cat $LOG_TDIR/$LOG_NEWDIR/$LOG_TFILE | egrep '<[a-zA-Z0-9_]+>|\[CONSOLE\]' | sed -e 's/.*\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\).\[INFO\]./\1 /g' >> $LOG_TDIR/$LOG_NEWDIR/chat-$DATE.log
cat $LOG_TDIR/$LOG_NEWDIR/$LOG_TFILE | egrep 'Internal exception|error' | sed -e 's/.*\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\).\[INFO\]./\1\t/g' >> $LOG_TDIR/$LOG_NEWDIR/errors-$DATE.log
;;
#################################################################
"backup")
if [[ -e $BKUP_PATH/$WORLD_NAME.lock ]]; then
echo "Backup already in progress. Aborting."
exit 1
else
touch $BKUP_PATH/$WORLD_NAME.lock
fi
if [[ ! -d $BKUP_PATH ]]; then
if ! mkdir -p $BKUP_PATH; then
echo "Backup path $BKUP_PATH does not exist and I could not create the directory!"
rm $BKUP_PATH/$WORLD_NAME.lock
exit 1
fi
fi
cd $BKUP_PATH
if [[ -e $MC_PATH/$WORLD_NAME ]]; then
if [[ $ONLINE -eq 1 ]]; then
echo "Server running, warning players : backup in 10s."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Backing up the map in 10s\r")"
sleep 10
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Now backing up the map...\r")"
echo "Issuing save-all command, wait 5s..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-all\r")"
sleep 5
echo "Issuing save-off command..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-off\r")"
sleep 1
fi
cd $BKUP_PATH
DATE=$(date +%Y-%m-%d-%Hh%M)
FILENAME=$WORLD_NAME-$DATE
BACKUP_FILES=$BKUP_PATH/list.$DATE
if [[ full == $2 ]]; then
# If full flag set, Make full backup, and remove old incrementals
FILENAME=$FILENAME-full.tgz
# Remove incrementals older than $BKUP_DAYS_INCR
# Remove full archives older than $BKUP_DAYS_FULL
find ./$WORLD_NAME-*-incr.tgz -type f -mtime +$BKUP_DAYS_INCR -print > purgelist
find ./$WORLD_NAME-*-full.tgz -type f -mtime +$BKUP_DAYS_FULL -print >> purgelist
rm -f $(cat purgelist) purgelist
# Now make our full backup
pushd $MC_PATH
find $WORLD_NAME -type f -print > $BACKUP_FILES
tar -zcf $BKUP_PATH/$FILENAME --files-from=$BACKUP_FILES
popd
rm -f $BACKUP_FULL_LINK $BACKUP_INCR_LINK
ln -s $FILENAME $BACKUP_FULL_LINK
else
# Make incremental backup
FILENAME=$FILENAME-incr.tgz
pushd $MC_PATH
find $WORLD_NAME -newer $BACKUP_FULL_LINK -type f -print > $BACKUP_FILES
tar -zcf $BKUP_PATH/$FILENAME --files-from=$BACKUP_FILES
popd
rm -f $BACKUP_INCR_LINK
ln -s $FILENAME $BACKUP_INCR_LINK
fi
rm -f $BACKUP_FILES
if [[ 1 -eq $ONLINE ]]; then
echo "Issuing save-on command..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-on\r")"
sleep 1
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Backup is done, have fun !\r")"
fi
echo "Backup process is over."
else
echo "The world \"$WORLD_NAME\" does not exist.";
fi
rm $BKUP_PATH/$WORLD_NAME.lock
;;
#################################################################
"cartography")
if [[ -e $MC_PATH/cartolock ]]; then
echo "Previous cartography run hasn't completed or has failed"
else
touch $MC_PATH/cartolock
if [[ "sync" == $2 ]]; then
sync_offline
fi
if [[ -e $CARTO_PATH ]]; then
if [[ -e $MC_PATH/$WORLD_NAME ]]; then
mkdir -p $MAPS_PATH
DATE=$(date +%Y-%m-%d-%Hh%M)
FILENAME=$WORLD_NAME-map-$DATE
cd $CARTO_PATH
echo "Cartography in progress..."
./c10t -w $MC_PATH/$OFFLINE_NAME/ -o $FILENAME.png $CARTO_OPTIONS
if [[ "$CARTO_NIGHT" == "1" ]]; then
FILENAMENIGHT=$WORLD_NAME-map-$DATE-night
./c10t -w $MC_PATH/$OFFLINE_NAME/ -o $FILENAMENIGHT.png $CARTO_NIGHTOPTIONS -n
fi
if [[ "$CARTO_CAVE" == "1" ]]; then
FILENAMECAVE=$WORLD_NAME-map-$DATE-cave
./c10t -w $MC_PATH/$OFFLINE_NAME/ -o $FILENAMECAVE.png $CARTO_CAVEOPTIONS -c
fi
OPTI_DIR=$CARTO_PATH
pngoptimize
if [[ "$DATE_DIR" == "1" ]]; then
mkdir $MAPS_PATH/$DATE
mv *.png $MAPS_PATH/$DATE
else
mkdir $MAPS_PATH
mv *.png $MAPS_PATH
fi
if [ 1 -eq $MAP_CHANGES ]; then
rm -f $MAPS_PATH/previous.png
ln $MAPS_PATH/current.png $MAPS_PATH/previous.png
rm -f $MAPS_PATH/current.png
if [[ "$DATE_DIR" == "1" ]]; then
ln $MAPS_PATH/$DATE/$FILENAME.png $MAPS_PATH/current.png
else
ln $MAPS_PATH/$FILENAME.png $MAPS_PATH/current.png
fi
fi
cd $MC_PATH
echo "Cartography is done."
if [ 1 -eq $MAP_CHANGES ]; then
echo "Generating changes."
if [[ -e $MAPS_PATH/previous.png ]]; then
cd $MAPS_PATH
mkdir changes
export RTMP=/tmp/makechanges.$$.
compare previous.png current.png $RTMP.1.tga
convert -transparent white $RTMP.1.tga $RTMP.2.tga
composite -quality 100 $RTMP.2.tga previous.png changes/changes-$FILENAME.png
OPTI_DIR=$MAPS_PATH/changes
pngoptimize
rm -f $MAPS_PATH/new.png
ln changes/changes-$FILENAME.png new.png
rm -rf previous.png $RTMP.*
fi
fi
else
echo "The world \"$WORLD_NAME\" does not exist."
fi
else
echo "The path to cartographer seems to be wrong."
fi
rm $MC_PATH/cartolock
fi
;;
#################################################################
"biome")
if [[ -e $BIOME_PATH ]]; then
if [[ -e $MC_PATH/$WORLD_NAME ]]; then
if [[ "sync" == $2 ]]; then
sync_offline
fi
echo "Biome extraction in progress..."
java -jar $BIOME_PATH/MinecraftBiomeExtractor.jar -nogui $MC_PATH/$OFFLINE_NAME/
echo "Biome extraction is complete"
else
echo "The world \"$WORLD_NAME\" does not exist."
fi
else
echo "The path to MinecraftBiomeExtractor.jar seems to be wrong."
fi
;;
#################################################################
"overviewer")
if [[ -e $MC_PATH/overviewlock ]]; then
echo "Previous overview run hasn't completed or has failed"
else
touch $MC_PATH/overviewlock
if [[ "sync" == $2 ]]; then
sync_offline
fi
if [[ -e $MCOVERVIEWER_PATH ]]; then
if [[ -e $MC_PATH/$WORLD_NAME ]]; then
mkdir -p $MCOVERVIEWER_MAPS_PATH
echo "Minecraft-Overviewer in progress..."
python $MCOVERVIEWER_PATH/overviewer.py $MCOVERVIEWER_OPTIONS $MC_PATH/$OFFLINE_NAME $MCOVERVIEWER_MAPS_PATH
OPTI_DIR=$MCOVERVIEWER_MAPS_PATH
pngoptimize
echo "Minecraft-Overviewer is done."
else
echo "The world \"$WORLD_NAME\" does not exist.";
fi
else
echo "The path to Minecraft-Overviewer seems to be wrong."
fi
rm $MC_PATH/overviewlock
fi
;;
#################################################################
"update")
if [[ 1 -eq $ONLINE ]]; then
server_stop
fi
mkdir -p $BKUP_PATH
echo "Backing up current binaries..."
DATE=$(date +%Y-%m-%d)
cd $MC_PATH
if [[ 1 -eq $SERVERMOD ]]; then
tar -czf minecraft_server-$DATE.tar.gz minecraft_server.jar $MODJAR
# rm craftbukkit.jar
else
tar -czf minecraft_server-$DATE.tar.gz minecraft_server.jar
fi
mv minecraft_server-$DATE.tar.gz $BKUP_PATH
echo "Downloading new binaries..."
wget -N http://www.minecraft.net/download/minecraft_server.jar
if [[ 1 -eq $SERVERMOD ]]; then
echo "Downloading Bukkit..."
wget -N http://ci.bukkit.org/job/dev-CraftBukkit/promotion/latest/Recommended/artifact/target/craftbukkit-0.0.1-SNAPSHOT.jar
fi
if [[ 1 -eq $RUNECRAFT ]]; then
if [[ 1 -eq $SERVERMOD ]]; then
echo "Downloading Runecraft..."
cd $MC_PATH/plugins/
wget -N http://llama.cerberusstudios.net/runecraft/runecraft_latest.jar
else
echo "Downloading Runecraft..."
mkdir -p ModTmp
cd ModTmp/
wget -N http://llama.cerberusstudios.net/runecraft_latest.zip
unzip runecraft_latest.zip
jar uvf $MC_PATH/minecraft_server.jar *.class
cd $MC_PATH
rm -rf ModTmp
fi
fi
server_launch
if [[ 1 -eq $DISPLAY_ON_LAUNCH ]]; then
display
fi
;;
#################################################################
"snapshot")
if [[ ! -d $SNAP_PATH ]]; then
if ! mkdir -p $SNAP_PATH; then
echo "Snapshot path $SNAP_PATH does not exist and I could not create the directory!"
exit 1
fi
fi
if [[ -e $SNAP_PATH/$WORLD_NAME.lock ]]; then
echo "Snapshot already in progress. Aborting."
exit 1
else
touch $SNAP_PATH/$WORLD_NAME.lock
fi
cd $SNAP_PATH
if [[ -e $MC_PATH/$WORLD_NAME ]]; then
if [[ $ONLINE -eq 1 ]]; then
echo "Server running, warning players : backup in 10s."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Creating map snapshot in 10s\r")"
sleep 10
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Now backing up the map...\r")"
echo "Issuing save-all command, wait 5s..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-all\r")"
sleep 5
echo "Issuing save-off command..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-off\r")"
sleep 1
fi
cd $SNAP_PATH
DATE=$(date +%Y-%m-%d-%Hh%M)
FILENAME=$WORLD_NAME-$DATE
# Remove snapshots older than $SNAP_DAYS
find $SNAP_PATH/$WORLD_NAME-*.zip -type f -mtime +$SNAP_DAYS -print > purgelist
rm -f $(cat purgelist) purgelist
#Create snapshot file
zip -r -Z store $FILENAME $MC_PATH/$WORLD_NAME
if [[ 1 -eq $ONLINE ]]; then
echo "Issuing save-on command..."
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "save-on\r")"
sleep 1
screen -S $SCREEN_NAME -p 0 -X stuff "$(printf "say Creating map snapshot completed, have fun !\r")"
fi
echo "Backup process is over."
else
echo "The world \"$WORLD_NAME\" does not exist.";
fi
rm $SNAP_PATH/$WORLD_NAME.lock
;;
#################################################################
*)
echo "Usage : minecraft <status | start [force] | stop | restart [warn] | say 'message' | tell user 'message' | logs [clean]"
echo "backup [full] | sync [purge] | cartography [sync] | biome [sync] | overviewer [sync] | snapshot | update>"
;;
esac
else
if [[ 1 -eq $ONLINE ]]; then
display
else
echo "Minecraft server seems to be offline..."
fi
fi
exit 0