-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdh-autobenchmark.sh
More file actions
1425 lines (1232 loc) · 41.7 KB
/
Copy pathdh-autobenchmark.sh
File metadata and controls
1425 lines (1232 loc) · 41.7 KB
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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Source: https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
# gets the full directory name where the script is executed from no matter where it is called from
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
checkCTRLC() {
if test ${QUIT} == "Yes"
then
echo -e "\nCTRL+C detected, shutting down Server and exiting script!\n" >&2
echo "If you want to exit the script immediatly, press CTRL+Z, you will need to kill the server yourself though." >&2
stopServer
echo "Exiting script"
exit 100
fi
}
# Check if CTRL+C has been pressed and if yes, set variable 'QUIT' to 'Yes'
trap 'QUIT=Yes' INT
## VARIABLES ##
# Do not manually edit
# This accounts as the "totalState" variable for the ProgressBar function
_end=100
# Start value for the ProgressBar function
_start=0
BACKUPHARDWAREINFORMATIONCSV="${DIR}/hardware-information.csv"
BENCHMARKTIME_SECONDS_MILLISECONDS="do_not_edit"
BENCHMARKTIME_SUM="0"
BUFFERCOUNTER="1"
CPS_AVERAGE="0"
CPS_TOTALAVERAGE="0"
CUSTOMDATAPACKFOLDER="${DIR}/custom_datapacks"
CONFIG="dh-benchmark.toml"
DATAPACKFOLDER="${DIR}/server/world/datapacks"
DBSIZE_SUM="0"
ETA_HOUR="0"
ETA_MINUTE="0"
ETA_SECONDS="0"
EULAFILE="${DIR}/server/eula.txt"
FINISHED="false"
LATESTLOG="${DIR}/server/logs/latest.log"
PROGRESS="false"
PROGRESSFILE="${DIR}/benchmark-progress.txt"
QUIT="NO"
RESULTSCSVFILE="${DIR}/benchmark-results.csv"
RUN="1"
SERVERPROPERTIES="${DIR}/server/server.properties"
SCREEN="dh-automation-benchmark"
WORLDFOLDER="${DIR}/server/world"
## Arrays ##
ARRAYDEVTYPES=(ata scsi nvme sat usbcypress usbjmicron usbprolific usbsunplus sntasmedia sntjmicron sntrealtek auto)
CPS=()
CPS_CSV=()
DBSIZES=()
RUNTIMES=()
## EXIT CODES ##
# 1 = Screen not installed
# 2 = wget and curl not installed
# 3 = folder "mods" could not be created
# 4 = EULA not accepted
# 5 = There is no Seed that could be set
# 6 = Not able to set threadPreset when server is running
# 7 = Server did not start correctly
# 8 = A File could not be deleted or overwritten
# 9 = Not able to delete world folder
# 10 = Folder "server" could not be created, check if you have valid permissions
# 11 = Config file could not be created
# 12 = Invalid Answer in configCheck
# 13 = Not able to use any editor to edit the config file
# 14 = Clean progress file could not be created
# 100 = CTRL+C detected, shut down server and exited script
# commandAvailable(command)
# Check whether the command $1 is available for execution
# Source: https://github.com/Griefed/ServerPackCreator/blob/7.1.3/serverpackcreator-api/src/main/resources/de/griefed/resources/server_files/default_template.sh
commandAvailable() {
command -v "$1" >/dev/null 2>&1
}
# downloadIfNotExist(fileToCheck,fileToDownload,downloadURL)
# Checks whether file $1 exists. If not, then it is downloaded from $3 and stored as $2. Can be used in if-statements.
# Source: https://github.com/Griefed/ServerPackCreator/blob/7.1.3/serverpackcreator-api/src/main/resources/de/griefed/resources/server_files/default_template.sh
downloadIfNotExist() {
if [[ ! -s "${1}" ]]; then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "${1} could not be found." >&2
echo "Downloading ${2}" >&2
echo "from ${3}" >&2
sleep 1s
else
echo "Downloading ${2}" >&2
fi
if commandAvailable curl ; then
curl -# -L -o "${2}" "${3}"
elif commandAvailable wget ; then
wget --show-progress -O "${2}" "${3}"
else
echo "wget or curl is required to download files"
exit 2
fi
if [[ -s "${2}" ]]; then
echo "Download complete." >&2
if test ${debug_mode} == "true" 2>/dev/null
then
echo "true"
sleep 1s
fi
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "false"
sleep 1s
fi
fi
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "${1} present."
echo "false"
sleep 1s
fi
fi
}
createConfig(){
echo '####################################################
# DISTANT HORIZONS COMMUNITY AUTO-BENCHMARK-SCRIPT #
####################################################
#-------#
# DEBUG #
#-------#
# Debug mode: enables verbose output which helps debugging potential bugs
# true / false
# Default: false
debug_mode="false"
#-----------------#
# SERVER SETTINGS #
#-----------------#
# RAM allocated to the server in GB.
# Default: 8
ram_gb="8"
# Extra JVM arguments to pass to the server.
# Example: "-XX:+UseZGC -XX:AllocatePrefetchStyle=1 -XX:-ZProactive"
# Note: You do not need to include the -Xmx flag here, it is set automatically based on the ram_gb config value.
# Default: None
extra_jvm_args=""
#----------------#
# WORLD SETTINGS #
#----------------#
# List of world seeds to use for the benchmark.
seeds=(5057296280818819649 2412466893128258733 3777092783861568240 -8505774097130463405 4753729061374190018)
#---------------
# DH SETTINGS #
#---------------
# This controls the Distant Horizons thread preset used when generating chunks.
# Available Presets are: MINIMAL_IMPACT, LOW_IMPACT, BALANCED, AGGRESSIVE, I_PAID_FOR_THE_WHOLE_CPU.
# Default: Default: I_PAID_FOR_THE_WHOLE_CPU
thread_preset="I_PAID_FOR_THE_WHOLE_CPU"
# The radius in chunks of the area to generate around the center of the world.
# Default: 256
generation_radius="256"
# The URL to download the Fabric server jar from.
fabric_download_url="https://meta.fabricmc.net/v2/versions/loader/1.21.1/0.17.2/1.1.0/server/jar"
# The URL to download the Distant Horizons mod jar from.
dh_download_url="https://cdn.modrinth.com/data/uCdwusMi/versions/P14vqscU/DistantHorizons-2.3.4-b-1.21.1-fabric-neoforge.jar"' >${CONFIG}
}
# check if config file exists, otherwise create config file and fill it with necessary entries
configCheck() {
if test -s ${DIR}/${CONFIG} 2>/dev/null
then
if test ${PROGRESS} == "true"
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Config file exists and progress is available, using available config"
fi
else
# Config file exists
read -r -p "Do you want to edit the current config, keep the current config or do a standardized run? (edit/keep/standard): " CONFIGANSWER
case ${CONFIGANSWER} in
Edit | edit)
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Using locally set editor"
sleep 1s
fi
if "${EDITOR:-nano}" ${CONFIG}
then
echo "Using edited config for the benchmark"
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Using nano as the editor"
sleep 1s
fi
if nano ${CONFIG}
then
echo "Using edited config for the benchmark"
else
echo "Could not use any editor for the config"
echo "Exiting script.."
exit 13
fi
fi
;;
Keep | keep)
echo "Using current available config"
;;
Standard | standard)
echo "Using standardized config!"
createConfig
;;
*)
echo "Invalid Answer: ${CONFIGANSWER}"
exit 12
;;
esac
fi
else
if test ${PROGRESS} == "true"
then
read -r -p "There is progress but no config file, would you like to redo the config or start a new run? (r/n) " PROGRESSCONFIGANSWER
case ${PROGRESSCONFIGANSWER} in
R | r)
if createConfig
then
# Debug output
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Config file created"
fi
# Debug output
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Using locally set editor"
sleep 1s
fi
if "${EDITOR:-nano}" ${CONFIG}
then
echo "Using edited config for the benchmark"
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Using nano as the editor"
sleep 1s
fi
if nano ${CONFIG}
then
echo "Using edited config for the benchmark"
else
echo "Could not use any editor for the config"
echo "Exiting script.."
exit 13
fi
fi
else
echo "Config could not be created!"
exit 11
fi
;;
N | n)
if createConfig
then
# Debug output
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Config file created"
fi
else
echo "Config could not be created!"
exit 11
fi
if createEmptyProgressFile
then
# Debug output
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Created clean progress file"
fi
fi
RUN="1"
;;
esac
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Config file does not exist, creating fresh config file"
sleep 1s
fi
if createConfig
then
# Debug output
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Config file created"
fi
# User input
read -r -p "Do you want to edit the config and do a custom run? (Y/N): " CONFIGANSWER
# Reacting to user input
if test ${CONFIGANSWER} == "Y" || test ${CONFIGANSWER} == "y"
then
if "${EDITOR:-nano}" ${CONFIG}
then
echo "Using edited config for the benchmark"
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Using nano as the editor"
sleep 1s
fi
if nano ${CONFIG}
then
echo "Using edited config for the benchmark"
else
echo "Could not use any editor for the config"
echo "Exiting script.."
exit 13
fi
fi
else
echo "Using standardized benchmark config!"
fi
else
echo "Config could not be created!"
exit 11
fi
fi
fi
}
# check if screen is installed
screenCheck() {
if commandAvailable screen
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Screen is installed"
sleep 1s
fi
else
echo "Screen is not installed, please install screen"
echo "via 'apt install screen'"
exit 1
fi
}
serverPropertiesCreate() {
echo "#Minecraft server properties
accepts-transfers=false
allow-flight=false
allow-nether=true
broadcast-console-to-ops=true
broadcast-rcon-to-ops=true
bug-report-link=
difficulty=easy
enable-command-block=false
enable-jmx-monitoring=false
enable-query=false
enable-rcon=false
enable-status=false
enforce-secure-profile=true
enforce-whitelist=true
entity-broadcast-range-percentage=100
force-gamemode=false
function-permission-level=2
gamemode=survival
generate-structures=true
generator-settings={}
hardcore=false
hide-online-players=false
initial-disabled-packs=
initial-enabled-packs=vanilla,fabric
level-name=world
level-type=minecraft\:normal
log-ips=true
max-chained-neighbor-updates=1000000
max-players=20
max-tick-time=60000
max-world-size=29999984
motd=A Minecraft Server
network-compression-threshold=256
online-mode=true
op-permission-level=4
player-idle-timeout=0
prevent-proxy-connections=false
pvp=true
query.port=25565
rate-limit=0
rcon.password=
rcon.port=25575
region-file-compression=deflate
require-resource-pack=false
resource-pack=
resource-pack-id=
resource-pack-prompt=
resource-pack-sha1=
server-ip=
server-port=61337
simulation-distance=10
spawn-animals=true
spawn-monsters=true
spawn-npcs=true
spawn-protection=16
sync-chunk-writes=true
text-filtering-config=
use-native-transport=true
view-distance=10
white-list=true" >${SERVERPROPERTIES}
}
serverPropertiesCheck() {
if test -s ${SERVERPROPERTIES}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "server.properties exists"
sleep 1s
fi
else
serverPropertiesCreate
fi
}
downloadFabricAndDistantHorizons() {
downloadIfNotExist ${DIR}/server/fabricserver.jar ${DIR}/server/fabricserver.jar ${fabric_download_url}
if test -d ${DIR}/server/mods
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "mods folder exists"
sleep 1s
fi
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "mods folder does not exist, creating folder..."
sleep 1s
fi
if mkdir ${DIR}/server/mods
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo 'folder "mods" created'
sleep 1s
fi
else
echo 'folder "mods" could not be created'
exit 3
fi
fi
downloadIfNotExist ${DIR}/server/mods/DistantHorizons-neoforge-fabric-2.3.2-b-1.21.1.jar ${DIR}/server/mods/DistantHorizons-neoforge-fabric-2.3.2-b-1.21.1.jar ${dh_download_url}
}
eulaCheck() {
# Source: https://github.com/Griefed/ServerPackCreator/blob/7.1.3/serverpackcreator-api/src/main/resources/de/griefed/resources/server_files/default_template.sh
if [[ ! -s "${EULAFILE}" ]]
then
echo "Mojang's EULA has not yet been accepted. In order to run a Minecraft server, you must accept Mojang's EULA."
echo "Mojang's EULA is available to read at https://aka.ms/MinecraftEULA"
echo "If you agree to Mojang's EULA then type 'I agree'"
echo -n "Response: "
read -r ANSWER
if [[ "${ANSWER}" == "I agree" ]]
then
echo "User agreed to Mojang's EULA."
echo "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA)." >${EULAFILE}
echo "eula=true" >>${EULAFILE}
else
echo "User did not agree to Mojang's EULA. Entered: ${ANSWER}. You can not run a Minecraft server unless you agree to Mojang's EULA."
exit 4
fi
fi
}
startServer() {
printf "Starting Server! ▀ "
# Go into the server folder to have all server files being created in the server folder
cd ${DIR}/server
screen -d -m -S ${SCREEN} java -Xmx${ram_gb}G ${extra_jvm_args} -jar ${DIR}/server/fabricserver.jar nogui &
# Wait for the server to generate a new 'latest.log'
while ! test -f ${DIR}/server/logs/latest.log
do
sleep 1s
done
# Wait for server to succesfully start
while ! grep -w "Done" <${LATESTLOG} 1>/dev/null 2>/dev/null
do
checkCTRLC
if test ${BUFFERCOUNTER} -lt 300
then
BUFFERCOUNTER=$((++BUFFERCOUNTER))
printf "\rStarting Server! ▌ "
sleep 0.5
printf "\rStarting Server! ▄ "
sleep 0.5
printf "\rStarting Server! ▐ "
sleep 0.5
printf "\rStarting Server! ▀ "
sleep 0.3
sleep 1s
else
echo "Server did not start correctly, exiting script..."
exit 7
fi
done
echo " - Server started!"
# Go back to the original directory to prevent bugs
cd ${DIR}
}
setSeed() {
if test ${1} -le ${#seeds[@]} && test ${1} -gt 0
then
echo "level-seed=${seeds[$((${1}-1))]}" >>${SERVERPROPERTIES}
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Set seed to ${seeds[$((${1}-1))]}"
sleep 1s
fi
else
echo "Seed #${1} does not exist!"
exit 5
fi
}
setThreadPreset() {
if screen -S $SCREEN -X stuff "dh config common.threadPreset ${thread_preset}"^M
then
# Wait for the thread preset to be active
while ! tail -n 5 <${LATESTLOG} | grep -w "preset active: ${thread_preset}" >/dev/null
do
sleep 1s
done
echo "Set Thread Preset to ${thread_preset}"
else
echo "Could not set common.threadPreset to ${thread_preset}"
exit 6
fi
# Wait another five seconds to prevent the pregen of instantly being queued when the threadPreset is being set
sleep 5s
}
stopServer() {
printf "Shutting down server ▀ "
sleep 12s
screen -S ${SCREEN} -X stuff "/stop^M"
sleep 3s
STOPCOUNTER="0"
while screen -ls | grep -w ${SCREEN} >/dev/null
do
if test ${STOPCOUNTER} -ge 120
then
echo "Server did not stop gracefully, force closing server..."
screen -S ${SCREEN} -X kill
else
printf "\rShutting down server ▌ "
sleep 0.5
printf "\rShutting down server ▄ "
sleep 0.5
printf "\rShutting down server ▐ "
sleep 0.5
printf "\rShutting down server ▀ "
sleep 0.3
fi
sleep 1s
done
echo " - Server stopped!"
}
worldDelete() {
if test -d ${DIR}/server/world
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "World folder detected, trying to delete..."
sleep 1s
fi
if rm -r ${DIR}/server/world
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Successfully deleted previous world!"
sleep 1s
fi
else
echo "Could not delete previous world, exiting script..."
exit 9
fi
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "No world folder detected!"
sleep 1s
fi
fi
}
removeFileIfExists() {
for FILE in $@
do
if test -s ${FILE}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "File ${FILE} exists, trying to delete..."
sleep 1s
fi
if rm ${FILE}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Successfully removed File ${FILE}"
sleep 1s
fi
else
echo "Could not delete File ${FILE}, trying to overwrite..."
if echo "" >${FILE}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Successfully overwritten File ${FILE}"
sleep 1s
fi
else
echo "Could not overwrite File ${FILE}, exiting script..."
exit 8
fi
fi
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Could not find ${FILE}"
sleep 1s
fi
fi
done
}
# 1. Create ProgressBar function
# 1.1 Input is currentState($1) and totalState($2)
ProgressBar() {
# Process data
if test ${1} = "0"
then
_progress="0"
_fill=""
_empty="░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"
else
let _progress=(${1}*100/${2}*100)/100
let _done=(${_progress}*4)/10
let _left=40-$_done
# Build progressbar string lengths
_fill=$(printf "%${_done}s")
_empty=$(printf "%${_left}s")
fi
# 1.2 Build progressbar strings and print the ProgressBar line
# 1.2.1 Output example:
# 1.2.1.1 Progress : [########################################] 100%
printf "\rProgress: [${_fill// /▓}${_empty// /░}] ${_progress}%% ($(printTimeElapsed) / $(printETA))"
}
getDatapacksIfExist() {
if test -d ${CUSTOMDATAPACKFOLDER}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "${CUSTOMDATAPACKFOLDER} folder exists"
sleep 1s
fi
if test -n "$(ls ${CUSTOMDATAPACKFOLDER} 2>/dev/null)"
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Datapacks exist, moving them"
sleep 1s
fi
if mkdir -p ${DATAPACKFOLDER}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "created ${DATAPACKFOLDER}"
sleep 1s
fi
else
echo "Could not create ${DATAPACKFOLDER}"
echo "Using Vanilla world generation"
# Exit the function since datapacks cannot be added
return 1
fi
for datapack in $(ls ${CUSTOMDATAPACKFOLDER})
do
if cp ${CUSTOMDATAPACKFOLDER}/${datapack} ${DATAPACKFOLDER}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Successfully copied ${datapack}"
sleep 1s
fi
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Could not copy ${datapack}"
sleep 1s
fi
fi
done
else
echo "No datapacks in ${CUSTOMDATAPACKFOLDER}, did you forget to delete the folder?"
fi
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "${CUSTOMDATAPACKFOLDER} folder does not exist, datapacks will not be used."
sleep 1s
fi
fi
}
collectHardwareInformation() {
# Hardware Information #
HARDWAREINFORMATION=()
# Data preparation
echo "Collecting CPU information..."
CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1')
if test -z "${CPU}"
then
CPU="UNKNOWN"
fi
# Clean up cpu naming scheme
CPU=$(echo "${CPU}" | sed -E 's/\b[0-9]+(st|nd|rd|th) Gen[[:space:]]+//g' | sed 's/(R)//g; s/(TM)//g' |
sed -E 's/[[:space:]]*@[[:space:]]*[0-9]+(\.[0-9]+)?[[:space:]]*GHz//g' | sed 's/ with Radeon Graphics//g' | sed 's/ CPU//g' |
sed -E 's/[[:space:]]+[0-9]+-Core[[:space:]]+Processor//g' | sed 's/[[:space:]]\{2,\}/ /g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
CPUCORES=$(lscpu | awk '/^Socket\(s\):/ {sockets=$2} /^Core\(s\) per socket:/ {cores=$4} END {print sockets * cores}')
if test -z "${CPUCORES}"
then
CPUCORES="x"
fi
CPUTHREADS=$(nproc --all)
if test -z "${CPUTHREADS}"
then
CPUTHREADS="x"
fi
echo "CPU: ${CPU} ${CPUCORES}C/${CPUTHREADS}T"
# Add CPU information to HARDWAREINFORMATION array
HARDWAREINFORMATION+=("${CPU} ${CPUCORES}C/${CPUTHREADS}T,")
read -r -p "The following commands have to be executed with elevated privileges to get the full data automatically, you may be asked multiple times, do you agree? (Yes/No): " ANSWERHARDWAREDATA
if test ${ANSWERHARDWAREDATA} == "Yes"
then
echo 'Please make sure that the package "dmidecode" is installed with your linux system otherwise the following data collection will not work.'
sleep 3s
# Collect RAM information
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Collecting RAM information..."
sleep 1s
fi
RAMSIZEONCE=$(sudo dmidecode -t memory | grep -w "Size" | grep -w "GB" | cut -d " " -f 2 | head -n 1)
RAMSTICKSDOUBLE=$(sudo dmidecode -t memory | grep -w "Size" | grep -w "GB" | wc -l)
if test ${RAMSTICKSDOUBLE} -eq 1
then
RAMSTICKS=${RAMSTICKSDOUBLE}
else
RAMSTICKS=$((RAMSTICKSDOUBLE / 2))
fi
# Get/calculate each variable and set to default value if not successful
RAMSIZETOTAL=$((RAMSIZEONCE * RAMSTICKS))
if test -z "${RAMSIZETOTAL}"
then
echo "RAM Size could not be collected!"
RAMSIZETOTAL="x"
fi
RAMTYPE=$(sudo dmidecode -t memory | grep "DDR" | cut -d " " -f 2 | head -n 1)
if test -z "${RAMTYPE}"
then
echo "RAM Type could not be determined!"
RAMTYPE="Unknown"
fi
RAMSPEED=$(sudo dmidecode -t memory | grep "Configured Memory Speed" | cut -d " " -f 4,5 | head -n 1)
if test -z "${RAMSPEED}"
then
echo "RAM Speed could not be determined!"
RAMSPEED="xxxxMT/s"
fi
echo "RAM: ${RAMSIZETOTAL}GB ${RAMTYPE} ${RAMSPEED}"
# Add RAM information to HARDWAREINFORMATION array
HARDWAREINFORMATION+=("${RAMSIZETOTAL}GB ${RAMTYPE} ${RAMSPEED},")
# Collect disk information
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Collecting Disk information..."
sleep 1s
fi
if commandAvailable findmnt
then
DISKMOUNT=$(findmnt -T ${DIR} -n -o SOURCE)
else
DISKPARTITION=$(df ${DIR} | grep dev | cut -d " " -f 1 | cut -d "/" -f 3)
DISKID=$(ls -l /dev/disk/by-id | grep ${DISKPARTITION} | cut -d " " -f 9 | head -n 1 | cut -d "-" -f 1,2)
DISKMOUNT=$(ls -l /dev/disk/by-id | grep ${DISKID} | head -n 1 | cut -d ">" -f 2 | cut -d "/" -f 3)
DISKMOUNT="/dev/"${DISKMOUNT}
fi
# Get Disk Model
for ARGDEVTYPE in ${ARRAYDEVTYPES[@]}
do
if test -z "${DISKMODEL}"
then
DISKMODEL=$(sudo smartctl -d ${ARGDEVTYPE} -a ${DISKMOUNT} | grep -w "Model" | tr -s " " | cut -d ":" -f 2 | tr -d " ")
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Found Device Type: ${DISKMODEL} with argument: ${ARGDEVTYPE}"
sleep 1s
fi
break
fi
done
# Get Disk Capacity
for ARGDEVTYPE in ${ARRAYDEVTYPES[@]}
do
if test -z "${DISKSIZE}"
then
DISKSIZE=$(sudo smartctl -d ${ARGDEVTYPE} -a ${DISKMOUNT} | grep "Capacity" | head -n 1 | cut -d "[" -f 2 | cut -d " " -f 1)
else
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Found Capacity: ${DISKSIZE} with argument: ${ARGDEVTYPE}"
sleep 1s
fi
break
fi
done
# Do seperate check for both variables
if test -z "${DISKMODEL}"
then
DISKMODEL="UNKNOWN"
fi
if test -z "${DISKSIZE}"
then
DISKSIZE="UNKNOWN"
fi
echo "DISK: ${DISKMODEL} ${DISKSIZE}GB"
# Add disk information to HARDWAREINFORMATION array
HARDWAREINFORMATION+=("${DISKMODEL} ${DISKSIZE}GB")
HARDWAREINFORMATION=($(echo ${HARDWAREINFORMATION[@]} | tr " " "_" | tr "," " "))
HARDWAREINFORMATIONCSV=${HARDWAREINFORMATION[@]}
# Add hardware information to separate csv file for Backup-purposes
if echo ${HARDWAREINFORMATIONCSV} >${BACKUPHARDWAREINFORMATIONCSV}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Hardware information added to backup csv file!"
sleep 1s
fi
# Fetching results from the runs and adding the hardware-information to it
INCOMPLETEDATA=($(tail -n 1 <${RESULTSCSVFILE} | tr " " "_" | tr "," " "))
INCOMPLETEDATA[0]=${HARDWAREINFORMATION[0]}
INCOMPLETEDATA[1]=${HARDWAREINFORMATION[1]}
INCOMPLETEDATA[2]=${HARDWAREINFORMATION[2]}
INCOMPLETEDATA=($(echo ${INCOMPLETEDATA[@]} | tr " " "," | tr "_" " "))
if test ${debug_mode} == "true" 2>/dev/null
then
# Labeling Results CSV file for debug purposes
if echo "CPU,RAM,DRIVE,Allocated RAM,Run 1,Run 2,Run 3,Run 4,Run 5,Average Time,Average Chunks per Second,DB Size Run 1,DB Size Run 2,DB Size Run 3,DB Size Run 4,DB Size Run 5,Average DB Size,----DEBUG TRUE----" >${RESULTSCSVFILE} \
&& echo ${INCOMPLETEDATA[@]} >>${RESULTSCSVFILE}
then
removeFileIfExists ${BACKUPHARDWAREINFORMATIONCSV}
else
benchmarkResultsCSVCreate
echo "Could not add hardware information to main csv file, please provide the following files when submitting:"
echo ${BACKUPHARDWAREINFORMATIONCSV}
echo ${RESULTSCSVFILE}
fi
sleep 1s
else
# Not labeling Results CSV file for automatic importing
if echo ${INCOMPLETEDATA[@]} >${RESULTSCSVFILE}
then
if test ${debug_mode} == "true" 2>/dev/null
then
echo "Added cleaned csv formatted data to csv file"
sleep 1s
fi
removeFileIfExists ${BACKUPHARDWAREINFORMATIONCSV}
else
benchmarkResultsCSVCreate
echo "Could not add hardware information to main csv file, please provide the following files when submitting:"
echo ${BACKUPHARDWAREINFORMATIONCSV}
echo ${RESULTSCSVFILE}
fi
fi
else
echo "Adding Hardware information to separate csv file"
if echo -e "CPU,RAM,DRIVE\n"${HARDWAREINFORMATIONCSV} >>${BACKUPHARDWAREINFORMATIONCSV}
then
echo "Added hardware information to separate csv file"
else
echo "Could not add hardware information to separate csv file, please provide this information when submitting:"
echo "${CPU} ${CPUCORES}C/${CPUTHREADS}T,${RAMSIZETOTAL}GB ${RAMTYPE} ${RAMSPEED},${DISKMODEL} ${DISKSIZE}GB"