-
Notifications
You must be signed in to change notification settings - Fork 0
/
Launch.sh
executable file
·1275 lines (1252 loc) · 38 KB
/
Launch.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
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
#! /bin/bash
# If you just want to start it for the night, auto config should be fine, but if you're using proxy, you must specify that with -p option... If you want to use the machine in the mean time, you can set a fixed amount of RAM or CPU cores in the config files since the defined values in the config file will override the automatic even if the ManualConfig constant is not set to true however the script will still decide automatically if it uses CPU, GPU, both in a single instance, or none for rendering.(that is only true to memory and CPU cores, the credentials, and proxy must be defined by using options. run it with --help for more info, the script does not edit other values.) You can go all manual, with -m option, and the script will not auto-configure anything but set username and proxy(again... options) but will still check if there are enough CPU cores, and RAM for your config...
# Finding Roots
cd $(cd "$(dirname "$0")"; pwd -P)
# Constant(s) and pre defined variables
ManualConfig=false
CommandLine=false
SilentMode=false
Facepalm=true # ...I should have tried killing processes without sudo in the first place.
Permission=false
UpdateScript=false
UpdateClient=false
RevertScript=false
RevertClient=false
CPU=true
GPU=false
CPU_GPU=false
Quit=""
UserName="RPBCACUEAIIBH"
Password="d5y7FgPYCQjrg9JP0iqqjt5AlCYXkGmiKcgCF0O8"
Proxy=""
Version="$(grep "Current version:" "$(pwd)/README.md")"
function NewTerminal
{
ExistingTerm=$(ls /dev/pts/*)
if [[ $Permission == true ]]
then
sudo -u $SUDO_USER gnome-terminal&
else
gnome-terminal&
fi
sleep 1 # need some time for the gnome-terminal command to open the terminal...
NewTerm=""
for i in $(ls /dev/pts/*)
do
if [[ -z $(echo $ExistingTerm | grep $i) ]]
then
NewTerm=$i
fi
done
}
function ComputeMethod
{
if [[ $GPUMem -ge 8000 && $CPUs -gt 7 ]]
then
echo "Rendering with single instance of either CPU or GPU. Server decides..."
CPU=false
GPU=false
CPU_GPU=true
CPUs=$(( $CPUs + 1 ))
else
if [[ $GPUMem -ge 8000 ]]
then
echo "Rendering with GPU only..."
CPU=false
else
if [[ $GPUMem -ge 4000 && $CPUs -ge 5 && $CPUs -le 7 ]]
then
echo "Rendering with single instance of either CPU or GPU. Server decides..."
CPU=false
GPU=false
CPU_GPU=true
CPUs=$(( $CPUs + 1 ))
else
if [[ $GPUMem -ge 4000 && $CPUs -lt 5 ]]
then
echo "Rendering with GPU only..."
CPU=false
else
echo "Rendering with CPU only..."
GPU=false
fi
fi
fi
fi
}
# Processing options
while [[ ! -z $@ ]]
do
case $1
in
"-m" ) ManualConfig=true
;;
"-c" ) CommandLine=true
;;
"-s" ) SilentMode=true
;;
"-p" ) shift
Proxy=$1
;;
"-u" ) shift
UserName=$1
shift
Password=$1
;;
"-A" ) UpdateScript=true
;;
"-RA" ) RevertScript=true
;;
"-C" ) UpdateClient=true
;;
"-RC" ) RevertClient=true
;;
"--help" ) echo ""
echo "Options"
echo "-c Specify this for command line operation.(Will launch the instances but not in new terminals... This runs via SSH, but will NOT continue running if you close the terminal.)"
echo "-m Use manual config(only if at least one of the config files are completed...)"
echo "-s Silent mode... This will launch the instances without any feedback. no need to also specify -c option. (for compatibility with my Systemd-Service-Generator script, which *hopefuly* makes it run automatically at startup...)"
echo ""
echo "-p [proxy] Specify proxy"
echo "-u [username] [password] Specify different user"
echo ""
echo "Specify options separately... For eample: It does not currently recognize -mu as separate options. you must specify them as -m -u"
echo ""
echo "-A Update Autoconfig script(Exits after execution!)"
echo "-RA Revert Autoconfig script to older version(Exits after execution!)"
echo "-C Update Sheepit client"
echo "-RC Revert Sheepit client to older version"
echo "You have to update the script first then the client if you wanna update both!"
echo ""
echo "Since version 1.2 you can make it a systemd service and have your machine autoconfigure and connect automatically at startup!(you may not wanna do that if you're using the machine for anythng else...)"
echo "- Download my Systemd-Service-Generator script from github.com/RPBCACUEAIIBH/Systemd-Service-Generator"
echo "- Run it as root"
echo "- Specify the following settings:"
echo " - Service name: Sheepit"
echo " - Startup command: sudo -u [yourusername] /home/[yourusername]/location/Sheepit-Autoconfig/Launch.sh -u [sheepitusename] [key/password] -s"
echo " - Shutdown command: (leave it empty)"
echo " - ServiceType: forking"
echo " - Should the service be considered running when it exits?: no"
echo " - Would you like to run the service now?: no (you want to reboot, and see if it starts rendering automatically at startup with everything it got autoconfigured...)"
echo "- Reboot, and check if you're rendering... :D"
echo "- You can check the service with: systemctl status Sheepit.service"
echo "- If you mess it up, run Systemd-Service-Generator script again with --cleaup option, and specify the service name: Sheepit"
echo ""
exit
;;
"--version" ) echo ""
echo "$Version"
echo ""
cat $(pwd)/LICENSE.md
exit
;;
*) echo "Error: Unknown option!"
exit
;;
esac
shift
done
# Root check
if [[ $(whoami) == "root" ]]
then
Permission=true
fi
if [[ ! -z $(ps -e | grep "rend.exe") || ! -z $(ps -aux | grep "sheepit" | grep -v "grep") ]]
then
echo "Fatal: Sheepit is already rendering... If the client(s) are closed, please run the following command for closing the process: sudo kill $(ps -e | grep rend.exe | awk '{ print $1 }')"
exit
fi
# Checking java
if [[ $SilentMode == false ]]
then
echo -n "Checking java: "
fi
if [[ -z $(dpkg -l | grep openjdk) ]]
then
echo "Fail"
echo ""
read -p "The sheepit client needs java to run... Do you want to install java?(y/n): " Yy
if [[ $Yy == [Yy]* ]]
then
if [[ $Permission == true ]]
then
apt-get -y install openjdk-8-jdk
echo ""
else
sudo apt-get -y install openjdk-8-jdk
echo ""
if [[ -z $(dpkg -l | grep openjdk) ]]
then
echo "Aborting... Sheepit client won't work without java..."
exit
fi
fi
else
echo "Aborting... Sheepit client won't work without java..."
exit
fi
else
if [[ $SilentMode == false ]]
then
echo "Ok"
echo ""
fi
fi
# Checking git
if [[ -z $(git --version | grep "git version") ]]
then
read -p "Git is required for update management! Do you want to install git?(y/n): " Yy
if [[ $Yy == [Yy]* ]]
then
sudo apt-get -y install git
else
echo "Aborting... Sheepit client won't work without java..."
exit
fi
fi
# Checking inxi
if [[ -z $(dpkg -l | grep inxi) ]]
then
if [[ ! -e ./.noinxi ]]
then
read -p "This script uses inxi for temperature monitoring, but it is not absolutely necessary if you have another prefered way of monitoring CPU and GPU temperatures. Do you want to install it?(y/n): " Yy
else
Yy="n"
fi
if [[ $Yy == [Yy]* ]]
then
TempMon=true
if [[ $Permission == true ]]
then
apt-get -y install inxi
echo ""
else
sudo apt-get -y install inxi
echo ""
if [[ -z $(dpkg -l | grep inxi) ]]
then
TempMon=false
touch ./.noinxi
fi
fi
else
TempMon=false
touch ./.noinxi # if you install inxi later you can delete the .noinxi file to have temperature monitoring...
fi
else
TempMon=true
fi
# Checking htop
if [[ -z $(dpkg -l | grep htop) ]]
then
if [[ ! -e ./.nohtop ]]
then
read -p "Htop is a light weight system monitor program, but it is not absolutely necessary if you have another prefered way of monitoring processes and CPU load. Do you want to install it?(y/n): " Yy
else
Yy="n"
fi
if [[ $Yy == [Yy]* ]]
then
HTop=true
if [[ $Permission == true && -z $Passwd ]]
then
apt-get -y install htop
echo ""
else
sudo apt-get -y install htop
echo ""
if [[ -z $(dpkg -l | grep htop) ]]
then
HTop=false
touch ./.nohtop
fi
fi
else
HTop=false
touch ./.nohtop # if you install htop later you can delete the .nohtop file to launch it...
fi
else
HTop=true
fi
# Update management
if [[ $UpdateScript == true ]]
then
if [[ $Permission == true && ! -z $SUDO_USER ]]
then
rm -Rf ./WD-CPU/*
rm -Rf ./WD-GPU/*
git clone https://github.com/RPBCACUEAIIBH/Sheepit-Autoconfig.git
rm -Rf ./Sheepit-Autoconfig/.git # Otherwise it gives a lecture about embedded git repos...
CloneVersion=$(grep "Current version:" "$(pwd)/Sheepit-Autoconfig/README.md")
if [[ "$CloneVersion" == "$Version" ]]
then
rm -Rf ./Sheepit-Autoconfig
if [[ $SilentMode == false ]]
then
echo "Autoconfig is already up to date!"
fi
exit
fi
CurrentBranch=$(git branch | awk '{ print $2 }')
if [[ ! -z $(git branch | grep "Old") && $(echo $CurrentBranch) != "Old" ]]
then
git branch -D Old
fi
if [[ $CurrentBranch != "Old" ]]
then
git branch -m Old
fi
if [[ ! -z $(git branch | grep "Current") ]]
then
git branch -D Current
fi
git add -A
git commit -a -m $RANDOM
git branch Current
rm -Rf ./Sheepit-Autoconfig
git add -A
git commit -a -m $RANDOM
git checkout Current
cp -Rf ./Sheepit-Autoconfig/* ./
rm -Rf ./Sheepit-Autoconfig
chmod +x ./Launch.sh
chmod +x ./sheepit-client*.jar
chown -R $SUDO_USER:$SUDO_USER ./*
git add -A
git commit -a -m $RANDOM
if [[ $SilentMode == false ]]
then
echo "Autoconfig updated!"
exit # It must exit here otherwise it would malfunction!
fi
fi
if [[ $Permission == false ]]
then
rm -Rf ./WD-CPU/*
rm -Rf ./WD-GPU/*
git clone https://github.com/RPBCACUEAIIBH/Sheepit-Autoconfig.git
rm -Rf ./Sheepit-Autoconfig/.git # Otherwise it gives a lecture about embedded git repos...
CloneVersion=$(grep "Current version:" "$(pwd)/Sheepit-Autoconfig/README.md")
if [[ "$CloneVersion" == "$Version" ]]
then
rm -Rf ./Sheepit-Autoconfig
if [[ $SilentMode == false ]]
then
echo "Autoconfig is already up to date!"
fi
exit
fi
CurrentBranch=$(git branch | awk '{ print $2 }')
if [[ ! -z $(git branch | grep "Old") && $(echo $CurrentBranch) != "Old" ]]
then
git branch -D Old
fi
if [[ $CurrentBranch != "Old" ]]
then
git branch -m Old
fi
if [[ ! -z $(git branch | grep "Current") ]]
then
git branch -D Current
fi
git add -A
git commit -a -m $RANDOM
git branch Current
rm -Rf ./Sheepit-Autoconfig
git add -A
git commit -a -m $RANDOM
git checkout Current
cp -Rf ./Sheepit-Autoconfig/* ./
rm -Rf ./Sheepit-Autoconfig
sudo chmod +x ./Launch.sh
sudo chmod +x ./sheepit-client*.jar
git add -A
git commit -a -m $RANDOM
if [[ $SilentMode == false ]]
then
echo "Autoconfig updated!"
exit # It must exit here otherwise it would malfunction!
fi
else
if [[ $SilentMode == false ]]
then
echo "Error: The script runs as root, and no \$SUDO_USER found! Aborting..."
fi
exit
fi
fi
if [[ $UpdateClient == true ]]
then
if [[ $Permission == true && ! -z $SUDO_USER ]]
then
if [[ ! -d ./Latest ]]
then
mkdir ./Latest
else
rm -f ./Latest/*
fi
if [[ ! -d ./Old ]]
then
mkdir ./Old
fi
cd ./Latest
wget "https://www.sheepit-renderfarm.com/media/applet/client-latest.php" -O sheepit-client-latest.jar
LatestClientSum=$(md5sum ./sheepit-client*.jar)
cd ..
CurrentClientSum=$(md5sum ./sheepit-client*.jar)
if [[ $(echo "$LatestClientSum" | awk '{ print $1 }') == $(echo "$CurrentClientSum" | awk '{ print $1 }') ]]
then
if [[ $SilentMode == false ]]
then
echo "Client is already the latest!"
fi
else
rm -f ./Old/*
mv ./sheepit-client*.jar ./Old/sheepit-client-old.jar
mv ./Latest/sheepit-client*.jar ./sheepit-client-current.jar
chown $SUDO_USER:$SUDO_USER ./sheepit-client-current.jar
chown -R $SUDO_USER:$SUDO_USER ./Old
chmod +x ./sheepit-client-current.jar
rm -r ./Latest
if [[ $SilentMode == false ]]
then
echo "Client updated!"
fi
fi
fi
if [[ $Permission == false ]]
then
if [[ ! -d ./Latest ]]
then
mkdir ./Latest
else
rm -f ./Latest/*
fi
if [[ ! -d ./Old ]]
then
mkdir ./Old
fi
cd ./Latest
wget "https://www.sheepit-renderfarm.com/media/applet/client-latest.php" -O sheepit-client-latest.jar
LatestClientSum=$(md5sum ./sheepit-client*.jar)
cd ..
CurrentClientSum=$(md5sum ./sheepit-client*.jar)
if [[ $(echo "$LatestClientSum" | awk '{ print $1 }') == $(echo "$CurrentClientSum" | awk '{ print $1 }') ]]
then
if [[ $SilentMode == false ]]
then
echo "Client is already the latest!"
fi
else
rm -f ./Old/*
mv ./sheepit-client*.jar ./Old/sheepit-client-old.jar
mv ./Latest/sheepit-client*.jar ./sheepit-client-current.jar
sudo chmod +x ./sheepit-client-current.jar
rm -r ./Latest
if [[ $SilentMode == false ]]
then
echo "Client updated!"
fi
fi
else
if [[ $SilentMode == false ]]
then
echo "Error: The script runs as root, and no \$SUDO_USER found! Aborting..."
fi
exit
fi
fi
if [[ $RevertScript == true ]]
then
if [[ -z $(git branch | grep "Old") ]]
then
if [[ $SilentMode == false ]]
then
echo "Error: No older version found!"
fi
exit
fi
CurrentBranch=$(git branch | awk '{ print $2 }')
git add -A
git commit -a -m $RANDOM
if [[ $(echo $CurrentBranch) != "Old" ]]
then
git checkout Old
else
if [[ $SilentMode == false ]]
then
echo "This is the old version!"
fi
exit
fi
git branch -D Current
if [[ $SilentMode == false ]]
then
echo "Reverted to old Autoconfig!"
exit # It must exit here otherwise it would malfunction!
fi
fi
if [[ $RevertClient == true ]]
then
if [[ $Permission == true && ! -z $SUDO_USER ]]
then
if [[ ! -f ./Old/sheepit-client-old.jar ]]
then
if [[ $SilentMode == false ]]
then
echo "Error: No older version found! Can't revert!"
fi
else
rm -f ./sheepit-client*.jar
mv ./Old/sheepit-client-old.jar ./sheepit-client-current.jar
if [[ ! -z $SUDO_USER ]]
then
chown $SUDO_USER:$SUDO_USER ./sheepit-client-current.jar
fi
chmod +x ./sheepit-client-current.jar
if [[ $SilentMode == false ]]
then
echo "Reverted to old client!"
fi
fi
fi
if [[ $Permission == false ]]
then
if [[ ! -f ./Old/sheepit-client-old.jar ]]
then
if [[ $SilentMode == false ]]
then
echo "Error: No older version found! Can't revert!"
fi
else
rm -f ./sheepit-client*.jar
mv ./Old/sheepit-client-old.jar ./sheepit-client-current.jar
sudo chmod +x ./sheepit-client-current.jar
if [[ $SilentMode == false ]]
then
echo "Reverted to old client!"
fi
fi
else
if [[ $SilentMode == false ]]
then
echo "Error: The script runs as root, and no \$SUDO_USER found! Aborting..."
fi
exit
fi
fi
# Probing system and preparing for launch
CPUs=$(grep -c ^processor /proc/cpuinfo)
if [[ $SilentMode == false ]]
then
echo "Detected CPU cores: $CPUs"
fi
MemAvailable=$(grep "MemAvailable:" /proc/meminfo | awk '{print $2}')
if [[ $MemAvailable -lt 2000000 ]]
then
if [[ $SilentMode == false ]]
then
echo "There's no point rendering with less then 2GB of available RAM... It would produce too much out of memory errors..."
fi
if [[ $GPU != true ]]
then
if [[ $SilentMode == false ]]
then
echo "Aborting..."
fi
exit
fi
fi
if [[ $SilentMode == false ]]
then
echo "Available memory: ~$(( $MemAvailable / 1000 ))MB"
fi
if [[ ! -z $(java -jar $(pwd)/sheepit-client-*.jar --show-gpu | grep "Id") ]]
then
GPU=true
# I don't know exactly how AMD/Intel GPUs supposed to show up, but help says "Name of the GPU used for the render, for example CUDA_0 for Nvidia or OPENCL_0 for AMD/Intel card" I don't have an AMD/Intel GPU to work with, so can't test it.
GPUID=$(java -jar $(pwd)/sheepit-client-*.jar --show-gpu | grep "Id" | awk '{ print $3 }')
GPUID=$(echo $GPUID | awk '{ print $1 }') # This makes shure that only the first GPUID gets specified in the config file. When I have more then 1 supported GPUs to work with will make it lauunch an instance for all separately.
CPUs=$(( $CPUs - 1 ))
GPUMem=$(java -jar $(pwd)/sheepit-client-*.jar --show-gpu | grep "Memory" | awk '{ print $3 }')
if [[ $SilentMode == false ]]
then
echo "Supported GPU: yes($GPUID)"
echo "Reported video memory: ${GPUMem}MB"
fi
else
GPU=false
if [[ $SilentMode == false ]]
then
echo "Supported GPU: No"
fi
fi
AvailSpace=$(echo $(df -k $(pwd)) | awk '{ print $11 }')
SheepitSize=$(du -s $(pwd) | awk '{ print $1 }')
if [[ $SilentMode == false ]]
then
echo "Available disk space: $(( $(( $AvailSpace + $SheepitSize )) / 1000 ))MB"
fi
#Automatic configuration attempt
if [[ $ManualConfig == false ]]
then
if [[ $GPU == true ]]
then
if [[ $GPUMem -lt 2000 ]]
then
if [[ $SilentMode == false ]]
then
echo "There's no point rendering with less then 2GB of VRAM! It would produce too much out of memory errors. Falling back to CPU only rendering..."
fi
GPU=false
CPUs=$(( $CPUs + 1 ))
fi
fi
if [[ $(( $AvailSpace + $SheepitSize )) -lt 2000000 ]]
then
if [[ $SilentMode == false ]]
then
echo "At least 2GB disk space is required per instance for efficient operation. Aborting..."
fi
exit
fi
if [[ $CPU == true && $GPU == true && $(( $AvailSpace + $SheepitSize )) -lt 4000000 ]]
then
if [[ $SilentMode == false ]]
then
echo "At least 2GB disk space is required per instance for efficient operation. Falling back to single client operation..."
fi
ComputeMethod
fi
if [[ $MemAvailable -lt 5000000 ]]
then
if [[ $SilentMode == false ]]
then
echo "Your system is low on memory! It can not run 2 instances of the client efficiently. Falling back to single client operation..."
fi
ComputeMethod
fi
if [[ $CPU == true && $GPU == true ]]
then
AUTORAMGPU=$(( $(( $GPUMem * 1000 )) + 500000 )) # Give it some more memory to work with...
AUTORAMCPU=$(( $MemAvailable - $AUTORAMGPU )) # Subtract that from avaiblable, and give the rest to the CPU instance.
fi
if [[ $CPU != true && $GPU == true ]]
then
AUTORAMGPU=$MemAvailable
fi
if [[ $CPU_GPU == true || $CPU == true && $GPU != true ]]
then
AUTORAMCPU=$MemAvailable
fi
if [[ $CPU == true ]]
then
if [[ -e ./.sheepit-cpu.conf ]]
then
rm -f ./.sheepit-cpu.conf
fi
cp ./sheepit-cpu.conf ./.sheepit-cpu.conf
sed -i "s/AUTO_CORE_COUNT/$CPUs/g" ./.sheepit-cpu.conf
sed -i "s/AUTO_RAM/${AUTORAMCPU}k/g" ./.sheepit-cpu.conf
HOSTNAME="$(uname -a | awk '{ print $2 }')_CPU"
sed -i "s/HOSTNAME/$HOSTNAME/g" ./.sheepit-cpu.conf
if [[ $SilentMode == false ]]
then
echo ""
echo "Auto-config for CPU instance: $CPUs CPU cores, and $(( $AUTORAMCPU / 1000 )) MB of memory."
fi
fi
if [[ $CPU_GPU == true ]] # The CPU_GPU instance uses WD_CPU and .sheepit-cpu.conf but it copies the .sheepit-cpu_gpu.conf not the .sheepit-cpu.conf The only difference is compute method and tile size...
then
if [[ -e ./.sheepit-cpu.conf ]]
then
rm -f ./.sheepit-cpu.conf
fi
cp ./sheepit-cpu_gpu.conf ./.sheepit-cpu.conf
sed -i "s/AUTO_CORE_COUNT/$CPUs/g" ./.sheepit-cpu.conf
sed -i "s/AUTO_RAM/${AUTORAMCPU}k/g" ./.sheepit-cpu.conf
HOSTNAME="$(uname -a | awk '{ print $2 }')"
sed -i "s/HOSTNAME/$HOSTNAME/g" ./.sheepit-cpu.conf
sed -i "s/GPUID/$GPUID/g" ./.sheepit-cpu.conf
if [[ $SilentMode == false ]]
then
echo ""
echo "Auto-config for single instance: $CPUs CPU cores, and $(( $AUTORAMCPU / 1000 )) MB of memory, and will render with either CPU or GPU."
fi
fi
if [[ $GPU == true ]]
then
if [[ -e ./.sheepit-gpu.conf ]]
then
rm -f ./.sheepit-gpu.conf
fi
cp ./sheepit-gpu.conf ./.sheepit-gpu.conf
sed -i "s/AUTO_RAM/${AUTORAMGPU}k/g" ./.sheepit-gpu.conf
HOSTNAME="$(uname -a | awk '{ print $2 }')_GPU"
sed -i "s/HOSTNAME/$HOSTNAME/g" ./.sheepit-gpu.conf
sed -i "s/GPUID/$GPUID/g" ./.sheepit-gpu.conf
if [[ $SilentMode == false ]]
then
echo ""
echo "Auto-config for GPU instance: 1 CPU cores, and $(( $AUTORAMGPU / 1000 )) MB of memory."
fi
fi
else
if [[ -z $(grep "AUTO_RAM" "$(pwd)/sheepit-cpu_gpu.conf") && -z $(grep "AUTO_CORE_COUNT" "$(pwd)/sheepit-cpu_gpu.conf") && $GPU == true ]] # in case of manual config if there is GPU it will be true
then
CPU=false
GPU=false
CPU_GPU=true
if [[ -e ./.sheepit-cpu.conf ]]
then
rm -f ./.sheepit-cpu.conf
fi
cp ./sheepit-cpu_gpu.conf ./.sheepit-cpu.conf
else
if [[ -z $(grep "AUTO_RAM" "$(pwd)/sheepit-cpu.conf") && -z $(grep "AUTO_CORE_COUNT" "$(pwd)/sheepit-cpu.conf") ]]
then
if [[ -e ./.sheepit-cpu.conf ]]
then
rm -f ./.sheepit-cpu.conf
fi
cp ./sheepit-cpu.conf ./.sheepit-cpu.conf
else
CPU=false # Disable if config incomplete
fi
if [[ -z $(grep "AUTO_RAM" "$(pwd)/sheepit-gpu.conf") && $GPU == true ]]
then
if [[ -e ./.sheepit-gpu.conf ]]
then
rm -f ./.sheepit-gpu.conf
fi
cp ./sheepit-gpu.conf ./.sheepit-gpu.conf
else
GPU=false # If gpu supported, but config file is incomplete it should disable GPU
fi
fi
if [[ $CPU == false && $GPU == false && $CPU_GPU == false ]]
then
if [[ $SilentMode == false ]]
then
echo "Error: None of the config files are complete, and ManualConfig is set! (Or GPU not recognized... Make sure you have the latest proprietary driver!) Aborting..."
fi
exit
fi
fi
# Credentials
if [[ $CPU == true || $CPU_GPU == true ]]
then
X=$(grep "login" "$(pwd)/.sheepit-cpu.conf")
UNAME=$(echo ${X##*=})
if [[ "$UNAME" != "$UserName" ]]
then
sed -i "s/login=$UNAME/login=$UserName/g" $(pwd)/.sheepit-cpu.conf
fi
X=$(grep "password" "$(pwd)/.sheepit-cpu.conf")
PASSWD=$(echo ${X##*=})
if [[ "$PASSWD" != "$Password" ]]
then
sed -i "s/password=$PASSWD/password=$Password/g" $(pwd)/.sheepit-cpu.conf
fi
X=$(grep "proxy" "$(pwd)/.sheepit-cpu.conf")
PROXY=$(echo ${X##*=})
if [[ "$PROXY" != "$Proxy" ]]
then
sed -i "s/proxy=$PROXY/proxy=$Proxy/g" $(pwd)/.sheepit-cpu.conf
fi
fi
if [[ $GPU == true ]]
then
X=$(grep "login" "$(pwd)/.sheepit-gpu.conf")
UNAME=$(echo ${X##*=})
if [[ "$UNAME" != "$UserName" ]]
then
sed -i "s/login=$UNAME/login=$UserName/g" $(pwd)/.sheepit-gpu.conf
fi
X=$(grep "password" "$(pwd)/.sheepit-gpu.conf")
PASSWD=$(echo ${X##*=})
if [[ "$PASSWD" != "$Password" ]]
then
sed -i "s/password=$PASSWD/password=$Password/g" $(pwd)/.sheepit-gpu.conf
fi
X=$(grep "proxy" "$(pwd)/.sheepit-gpu.conf")
PROXY=$(echo ${X##*=})
if [[ "$PROXY" != "$Proxy" ]]
then
sed -i "s/proxy=$PROXY/proxy=$Proxy/g" $(pwd)/.sheepit-gpu.conf
fi
fi
# Displaying final config...
if [[ $SilentMode == false ]]
then
if [[ $CPU == true ]]
then
echo ""
echo "CPU instance final configuration:"
X=0
for i in "cache-dir" "login" "proxy" "cpu-cores" "ram" "tile-size"
do
Y=$(grep "$i" "$(pwd)/.sheepit-cpu.conf")
CfCPU[$X]=$(echo ${Y##*=})
if [[ $i == "ram" ]]
then
CfCPU[$X]=${CfCPU[$X]:0:-1}
fi
case $X
in
"0" ) :
;;
"1" ) echo " Login as user: ${CfCPU[$X]}"
;;
"2" ) echo " Proxy: ${CfCPU[$X]}"
;;
"3" ) echo " Assigned CPU cores: ${CfCPU[$X]}"
;;
"4" ) echo " Assigned memory: $(( ${CfCPU[$X]} / 1000 )) MB"
;;
"5" ) echo " Tile size: ${CfCPU[$X]}"
;;
*) echo " Error: Unknown option at: case $X!"
;;
esac
X=$(( $X + 1 ))
done
fi
if [[ $CPU_GPU == true ]]
then
echo ""
echo "Final configuration:"
X=0
for i in "cache-dir" "login" "proxy" "cpu-cores" "ram" "tile-size"
do
Y=$(grep "$i" "$(pwd)/.sheepit-cpu_gpu.conf")
CfCPU[$X]=$(echo ${Y##*=})
if [[ $i == "ram" ]]
then
CfCPU[$X]=${CfCPU[$X]:0:-1}
fi
case $X
in
"0" ) :
;;
"1" ) echo " Login as user: ${CfCPU[$X]}"
;;
"2" ) echo " Proxy: ${CfCPU[$X]}"
;;
"3" ) echo " Assigned CPU cores: ${CfCPU[$X]}"
;;
"4" ) echo " Assigned memory: $(( ${CfCPU[$X]} / 1000 )) MB"
;;
"5" ) echo " Tile size: ${CfCPU[$X]}"
;;
*) echo " Error: Unknown option at: case $X!"
;;
esac
X=$(( $X + 1 ))
done
fi
if [[ $GPU == true ]]
then
echo ""
echo "GPU instance final configuration:"
X=0
for i in "cache-dir" "login" "proxy" "cpu-cores" "ram" "tile-size"
do
Y=$(grep "$i" "$(pwd)/.sheepit-gpu.conf")
CfGPU[$X]=$(echo ${Y##*=})
if [[ $i == "ram" ]]
then
CfGPU[$X]=${CfGPU[$X]:0:-1}
fi
case $X
in
"0" ) :
;;
"1" ) echo " Login as user: ${CfGPU[$X]}"
;;
"2" ) echo " Proxy: ${CfGPU[$X]}"
;;
"3" ) echo " Assigned CPU cores: ${CfGPU[$X]}"
;;
"4" ) echo " Assigned memory: $(( ${CfGPU[$X]} / 1000 )) MB"
;;
"5" ) echo " Tile size: ${CfGPU[$X]}"
;;
*) echo " Error: Unknown option at: case $X!"
;;
esac
X=$(( $X + 1 ))
done
fi
else # Not displaying in silent mode, but still need that array for error checking...
if [[ $CPU == true ]]
then
X=0
for i in "cache-dir" "login" "proxy" "cpu-cores" "ram" "tile-size"
do
Y=$(grep "$i" "$(pwd)/.sheepit-cpu.conf")
CfCPU[$X]=$(echo ${Y##*=})
if [[ $i == "ram" ]]
then
CfCPU[$X]=${CfCPU[$X]:0:-1}
fi
X=$(( $X + 1 ))
done
fi
if [[ $CPU_GPU == true ]]
then
X=0
for i in "cache-dir" "login" "proxy" "cpu-cores" "ram" "tile-size"
do
Y=$(grep "$i" "$(pwd)/.sheepit-cpu_gpu.conf")
CfCPU[$X]=$(echo ${Y##*=})
if [[ $i == "ram" ]]
then
CfCPU[$X]=${CfCPU[$X]:0:-1}
fi
X=$(( $X + 1 ))
done
fi
if [[ $GPU == true ]]
then
X=0
for i in "cache-dir" "login" "proxy" "cpu-cores" "ram" "tile-size"
do
Y=$(grep "$i" "$(pwd)/.sheepit-gpu.conf")
CfGPU[$X]=$(echo ${Y##*=})
if [[ $i == "ram" ]]
then
CfGPU[$X]=${CfGPU[$X]:0:-1}
fi
X=$(( $X + 1 ))
done
fi
fi
# Error checking
if [[ $CPU == true && $GPU == true ]]
then
if [[ ${CfCPU[0]} == ${CfGPU[0]} ]]
then
if [[ $SilentMode == true ]]
then
exit
else
echo "Error: The working directory can not be the same directory! The 2 instance would interfere and crash..."
exit
fi
fi
if [[ ${CfCPU[3]} -gt $CPUs ]]
then
if [[ $SilentMode == true ]]
then
exit
else
echo "Error: You need at least 1 CPU core for feeding the GPU with data unless you disable your GPU..."
exit
fi
fi
if [[ $(( ${CfCPU[3]} + ${CfGPU[3]} )) -gt $(( $CPUs + 1 )) ]]
then
if [[ $SilentMode == true ]]
then
exit
else
echo "Error: You have specified more CPU cores overall then the CPU actually has!"
exit
fi
fi
if [[ $(( ${CfCPU[4]} + ${CfGPU[4]} )) -gt $MemAvailable ]]
then
if [[ $SilentMode == true ]]
then
exit
else
echo "Error: You have specified more RAM overall then the total availabel memory of your machine!"
exit
fi
fi
fi
if [[ $CPU == true || $CPU_GPU == true ]]
then
if [[ ${CfCPU[3]} -gt $CPUs ]]
then
if [[ $SilentMode == true ]]
then
exit
else
echo "Error: You have specified more CPU cores then the CPU actually has!"
exit