-
Notifications
You must be signed in to change notification settings - Fork 4
/
Run.sh
executable file
·2620 lines (2497 loc) · 121 KB
/
Run.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
#!/usr/bin/env bash
shopt -s extglob
DEVELOPERS="VHSgunzo"
export RUNIMAGE_VERSION='0.39.1'
RED='\033[1;91m'
BLUE='\033[1;94m'
GREEN='\033[1;92m'
YELLOW='\033[1;33m'
RESETCOLOR='\033[1;00m'
[ ! -n "$SYS_PATH" ] && \
export SYS_PATH="$PATH"
export RUNPPID="$PPID"
export RUNPID="$BASHPID"
export BWINFFL="/tmp/.bwinf.$RUNPID"
export EXECFLDIR="/tmp/.exec.$RUNPID"
RPIDSFL="/tmp/.rpids.$RUNPID"
UNPASSWDFL="/tmp/.passwd.$RUNPID"
UNGROUPFL="/tmp/.group.$RUNPID"
unset RO_MNT RUNROOTFS SQFUSE BUWRAP NOT_TERM UNIONFS VAR_BIND \
MKSQFS NVDRVMNT BUWRAP_CAP NVIDIA_DRIVER_BIND EXEC_STATUS \
SESSION_MANAGER UNSQFS TMP_BIND SYS_HOME UNSHARE_BIND \
NETWORK_BIND SET_HOME_DIR SET_CONF_DIR HOME_BIND BUWRAP_ARGS \
LD_CACHE_BIND ADD_LD_CACHE NEW_HOME TMPDIR_BIND EXEC_ARGS \
FUSE_PIDS XDG_RUN_BIND XORG_CONF_BIND SUID_BUWRAP OVERFS_MNT \
SET_RUNIMAGE_CONFIG SET_RUNIMAGE_INTERNAL_CONFIG OVERFS_DIR \
RUNRUNTIME RUNSTATIC UNLIM_WAIT SETENV_ARGS SLIRP RUNDIR_BIND \
SANDBOX_HOME_DIR MACHINEID_BIND MODULES_BIND DEF_MOUNTS_BIND \
LOCALTIME_BIND NSSWITCH_BIND
which_exe() { command -v "$@" ; }
[[ ! -n "$LANG" || "$LANG" =~ "UTF8" ]] && \
export LANG=en_US.UTF-8
if [[ -n "$RUNOFFSET" && -n "$ARGV0" ]]
then
export RUNSTATIC="$RUNDIR/static"
[ "$SYS_TOOLS" == 1 ] && \
export PATH="$SYS_PATH:$RUNSTATIC"||\
export PATH="$RUNSTATIC:$SYS_PATH"
if [ ! -n "$RUNIMAGE" ] # KDE Neon, CachyOS, Puppy Linux bug
then
if [ -x "$(realpath "$ARGV0" 2>/dev/null)" ]
then
export RUNIMAGE="$(realpath "$ARGV0" 2>/dev/null)"
elif [ -x "$(realpath "$(which_exe "$ARGV0")" 2>/dev/null)" ]
then
export RUNIMAGE="$(realpath "$(which_exe "$ARGV0")" 2>/dev/null)"
else
export RUNIMAGE="$ARGV0"
fi
fi
if [ -x "$(realpath -s "$ARGV0" 2>/dev/null)" ]
then
RUNSRC="$(realpath -s "$ARGV0" 2>/dev/null)"
elif [ -x "$(realpath -s "$(which_exe "$ARGV0")" 2>/dev/null)" ]
then
RUNSRC="$(realpath -s "$(which_exe "$ARGV0")" 2>/dev/null)"
else
RUNSRC="$RUNIMAGE"
fi
export RUNIMAGEDIR="$(dirname "$RUNIMAGE" 2>/dev/null)"
RUNIMAGENAME="$(basename "$RUNIMAGE" 2>/dev/null)"
else
[ ! -d "$RUNDIR" ] && \
export RUNDIR="$(dirname "$(realpath "$0" 2>/dev/null)" 2>/dev/null)"
export RUNSTATIC="$RUNDIR/static"
[ "$SYS_TOOLS" == 1 ] && \
export PATH="$SYS_PATH:$RUNSTATIC"||\
export PATH="$RUNSTATIC:$SYS_PATH"
export RUNIMAGEDIR="$(realpath "$RUNDIR/../" 2>/dev/null)"
if [ ! -n "$RUNSRC" ]
then
if [ -x "$(realpath -s "$0" 2>/dev/null)" ]
then
RUNSRC="$(realpath -s "$0" 2>/dev/null)"
elif [ -x "$(realpath -s "$(which_exe "$0")" 2>/dev/null)" ]
then
RUNSRC="$(realpath -s "$(which_exe "$0")" 2>/dev/null)"
else
RUNSRC="$RUNDIR/Run"
fi
fi
fi
[ ! -n "$RUNTTY" ] && \
export RUNTTY="$(tty|grep -v 'not a')"
[ ! -n "$(echo "$RUNTTY"|grep -Eo 'tty|pts')" ] && \
NOT_TERM=1||NOT_TERM=0
[ "$NOT_TERM" != 1 ] && \
SETSID_RUN=("ptyspawn")||\
SETSID_RUN=("setsid" "--wait")
if [[ "$RUNSETSID" != 1 && ! "$RUNTTY" =~ "tty" && "$ALLOW_BG" != 1 ]]
then
RUNSETSID=1 "${SETSID_RUN[@]}" "$RUNSTATIC/bash" \
"$(realpath -s "$0" 2>/dev/null)" "$@"
exit $?
fi
unset RUNSETSID
export RUNROOTFS="$RUNDIR/rootfs"
export RUNCACHEDIR="$RUNIMAGEDIR/cache"
export RUNCONFIGDIR="$RUNIMAGEDIR/config"
export RUNOVERFSDIR="$RUNIMAGEDIR/overlayfs"
export RUNRUNTIME="$RUNSTATIC/runtime-fuse2-all"
export SANDBOXHOMEDIR="$RUNIMAGEDIR/sandbox-home"
export PORTABLEHOMEDIR="$RUNIMAGEDIR/portable-home"
export RUNSRCNAME="$(basename "$RUNSRC" 2>/dev/null)"
OVERFSLIST="$(ls -A "$RUNOVERFSDIR" 2>/dev/null)"
export RUNSTATIC_VERSION="$(cat "$RUNSTATIC/.version" 2>/dev/null)"
export RUNROOTFS_VERSION="$(cat "$RUNROOTFS/.version" \
"$RUNROOTFS/.type" \
"$RUNROOTFS/.build" 2>/dev/null|\
sed ':a;/$/N;s/\n/./;ta')"
export RUNROOTFSTYPE="$(cat "$RUNROOTFS/.type" 2>/dev/null)"
export RUNRUNTIME_VERSION="$("$RUNRUNTIME" --runtime-version|& awk '{print$2}')"
nocolor() { sed -r 's|\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]||g' ; }
error_msg() {
echo -e "${RED}[ ERROR ][$(date +"%Y.%m.%d %T")]: $@ $RESETCOLOR"
if [ "$NOT_TERM" == 1 ]
then notify-send -a 'RunImage Error' "$(echo -e "$@"|nocolor)" 2>/dev/null &
fi
}
info_msg() {
if [ "$QUIET_MODE" != 1 ]
then echo -e "${GREEN}[ INFO ][$(date +"%Y.%m.%d %T")]: $@ $RESETCOLOR"
if [[ "$NOT_TERM" == 1 && "$DONT_NOTIFY" != 1 ]]
then notify-send -a 'RunImage Info' "$(echo -e "$@"|nocolor)" 2>/dev/null &
fi
fi
}
warn_msg() {
if [[ "$QUIET_MODE" != 1 && "$NO_WARN" != 1 ]]
then echo -e "${YELLOW}[ WARNING ][$(date +"%Y.%m.%d %T")]: $@ $RESETCOLOR"
if [[ "$NOT_TERM" == 1 && "$DONT_NOTIFY" != 1 ]]
then notify-send -a 'RunImage Warning' "$(echo -e "$@"|nocolor)" 2>/dev/null &
fi
fi
}
console_info_notify() {
[ "$NOT_TERM" == 1 ] && \
notify-send -a "RunImage Info" "See the information in the console!" &
}
mount_exist() {
time_out=1000 # =~ 3 sec
wait_time=0
while true
do
if [ "$wait_time" -le "$time_out" ]
then
if [[ -d "/proc/$1" && -n "$(ls -A "$2" 2>/dev/null)" ]]
then
return 0
else
wait_time="$(( $wait_time + 1 ))"
sleep 0.0001 2>/dev/null
fi
else
return 1
fi
done
}
is_sys_exe() {
[[ -x "$(which -a "$1" 2>/dev/null|grep -v "$RUNSTATIC"|head -1)" ]] && \
return 0||return 1
}
which_sys_exe() { which -a "$1" 2>/dev/null|grep -v "$RUNSTATIC"|head -1 ; }
is_exe_exist() { command -v "$@" &>/dev/null ; }
yn_case() {
while true
do
read -p "$(echo -e "${RED}$1 ${GREEN}(y/n) ${BLUE}> $RESETCOLOR")" yn
case $yn in
[Yy] ) return 0 ;;
[Nn] ) return 1 ;;
esac
done
}
check_url_stat_code() { curl -sL -o /dev/null --insecure -I -w "%{http_code}" "$@" 2>/dev/null ; }
is_url() {
[ ! -n "$1" ] && \
return 1
if [ -n "$2" ]
then [ "$(check_url_stat_code "$1")" == "$2" ]
else [ "$(check_url_stat_code "$1")" == "200" ]
fi
}
try_dl() {
err_no_downloader() {
error_msg "Downloader not found!"
cleanup force
exit 1
}
rm_fail_dl() {
[ -f "$FILEDIR/$FILENAME" ] && \
rm -rf "$FILEDIR/$FILENAME" \
"$FILEDIR/$FILENAME"*.aria2
}
dl_ret() {
if [ "$1" != 0 ]
then
rm_fail_dl
dl_repeat && \
try_dl "$URL" "$FILEDIR/$FILENAME"||\
return 1
else return 0
fi
}
dl_repeat() {
[ "$NO_DL_REPEAT" == 1 ] && \
return 1
DL_REP_TITLE="Download interrupted!"
DL_REP_TEXT="Failed to download: $FILENAME from $(echo "$URL"|awk -F/ '{print$3"/"$4}') \nWould you like to repeat it?"
if [[ "$NOT_TERM" != 1 || "$NO_DL_GUI" == 1 ]]
then
yn_case "$DL_REP_TEXT"||return 1
elif is_exe_exist yad
then
yad --image="dialog-error" --button="CANCEL:1" --center \
--button="REPEAT:0" --title="$DL_REP_TITLE" \
--text="$DL_REP_TEXT" --on-top --fixed
elif is_exe_exist zenity
then
zenity --question --title="$DL_REP_TITLE" --no-wrap \
--text="$DL_REP_TEXT"
else return 1
fi
}
if [ -n "$1" ]
then
URL="$1"
if [ -n "$2" ]
then
if [ -d "$2" ]
then
FILEDIR="$2"
FILENAME="$(basename "$1")"
else
FILEDIR="$(dirname "$2")"
FILENAME="$(basename "$2")"
fi
else
FILEDIR="."
FILENAME="$(basename "$1")"
fi
if is_url "$URL"
then
WGET_ARGS=(--no-check-certificate --content-disposition -t 3 -T 5 -w 0.5 "$URL" -O "$FILEDIR/$FILENAME")
[ ! -d "$FILEDIR" ] && \
try_mkdir "$FILEDIR"
if [[ "$NOT_TERM" == 1 && "$NO_DL_GUI" != 1 ]] && \
(is_exe_exist yad||is_exe_exist zenity)
then
set -o pipefail
dl_progress() {
[[ "$URL" =~ '&key=' ]] && \
local URL="$(echo "$URL"|sed "s|\&key=.*||g")"
[[ "$URL" =~ '&' && ! "$URL" =~ '&' ]] && \
local URL="$(echo "$URL"|sed "s|\&|\&|g")"
if is_exe_exist yad
then
yad --progress --percentage=0 --text="Download:\t$FILENAME\n$URL" \
--auto-close --no-escape --selectable-labels --auto-kill \
--center --on-top --fixed --no-buttons --undecorated --skip-taskbar
elif is_exe_exist zenity
then
zenity --progress --text="Connecting to $URL" --width=650 --height=40 \
--auto-close --no-cancel --title="Download: $FILENAME"
else return 1
fi
}
dl_progress_pulsate() {
local ret=1
[[ "$URL" =~ '&key=' ]] && \
local URL="$(echo "$URL"|sed "s|\&key=.*||g")"
[[ "$URL" =~ '&' && ! "$URL" =~ '&' ]] && \
local URL="$(echo "$URL"|sed "s|\&|\&|g")"
if is_exe_exist yad
then
local yad_args=(
--progress --pulsate --text="Download:\t$FILENAME\n$URL"
--width=650 --height=40 --undecorated --skip-taskbar
--no-buttons --text-align center --auto-close --auto-kill
--center --fixed --on-top --no-escape --selectable-labels
)
"$@" &
local exec_pid="$!"
if [[ -n "$exec_pid" && -d "/proc/$exec_pid" ]]
then
(while [ -d "/proc/$exec_pid" ]
do echo -e "#\n" ; sleep 0.1 2>/dev/null
done)|yad "${yad_args[@]}" &>/dev/null &
local yad_pid="$!"
wait "$exec_pid" &>/dev/null
ret="$?"
kill "$yad_pid" &>/dev/null
fi
elif is_exe_exist zenity
then
"$@"|zenity --progress --pulsate --text="$URL" --width=650 --height=40 \
--auto-close --no-cancel --title="Download: $FILENAME"
ret="$?"
fi
return "$ret"
}
if [ "$NO_ARIA2C" != 1 ] && \
is_exe_exist aria2c
then
aria2c --no-conf -R -x 13 -s 13 --allow-overwrite --summary-interval=1 -o \
"$FILENAME" -d "$FILEDIR" "$URL"|grep --line-buffered 'ETA'|\
sed -u 's|(.*)| &|g;s|(||g;s|)||g;s|\[||g;s|\]||g'|\
awk '{print$3"\n#Downloading at "$3,$2,$5,$6;system("")}'|\
dl_progress
elif is_exe_exist curl
then
curl -R --progress-bar --insecure --fail -L "$URL" -o \
"$FILEDIR/$FILENAME" |& tr '\r' '\n'|\
sed -ur 's|[# ]+||g;s|.*=.*||g;s|.*|#Downloading at &\n&|g'|\
dl_progress
elif is_exe_exist wget2
then
dl_progress_pulsate wget2 "${WGET_ARGS[@]}"
elif is_exe_exist wget
then
wget "${WGET_ARGS[@]}"|& tr '\r' '\n'|\
sed -u 's/.* \([0-9]\+%\)\ \+\([0-9,.]\+.\) \(.*\)/\1\n#Downloading at \1\ ETA: \3/; s/^20[0-9][0-9].*/#Done./'|\
dl_progress
else
err_no_downloader
fi
dl_ret "${PIPESTATUS[0]}"||return 1
else
if [ "$NO_ARIA2C" != 1 ] && is_exe_exist aria2c
then
aria2c --no-conf -R -x 13 -s 13 --allow-overwrite -d "$FILEDIR" -o "$FILENAME" "$URL"
elif is_exe_exist curl
then
curl -R --progress-bar --insecure --fail -L "$URL" -o "$FILEDIR/$FILENAME"
elif is_exe_exist wget2
then
wget2 -q --force-progress "${WGET_ARGS[@]}"
elif is_exe_exist wget
then
wget -q --show-progress "${WGET_ARGS[@]}"
else
err_no_downloader
fi
dl_ret "$?"||return 1
fi
else
error_msg "$FILENAME not found in $(echo "$URL"|awk -F/ '{print$3"/"$4}')"
return 1
fi
else
error_msg "Specify download URL!"
return 1
fi
}
get_nvidia_driver_image() {
(if [[ -n "$1" || -n "$nvidia_version" ]]
then
[ ! -n "$nvidia_version" ] && \
nvidia_version="$1"
[[ -d "$2" && ! -n "$NVIDIA_DRIVERS_DIR" ]] && \
export NVIDIA_DRIVERS_DIR="$2"
[[ ! -d "$2" && ! -n "$NVIDIA_DRIVERS_DIR" ]] && \
export NVIDIA_DRIVERS_DIR="."
[ ! -n "$nvidia_driver_image" ] && \
nvidia_driver_image="$nvidia_version.nv.drv"
try_mkdir "$NVIDIA_DRIVERS_DIR"
info_msg "Downloading Nvidia ${nvidia_version} driver, please wait..."
nvidia_driver_run="NVIDIA-Linux-x86_64-${nvidia_version}.run"
driver_url_list=(
"https://storage.yandexcloud.net/runimage/nvidia-drivers/$nvidia_driver_image"
"https://huggingface.co/runimage/nvidia-drivers/resolve/main/releases/$nvidia_driver_image"
"https://github.com/VHSgunzo/runimage-nvidia-drivers/releases/download/v${nvidia_version}/$nvidia_driver_image"
"https://us.download.nvidia.com/XFree86/Linux-x86_64/${nvidia_version}/$nvidia_driver_run"
"https://us.download.nvidia.com/tesla/${nvidia_version}/$nvidia_driver_run"
"https://developer.nvidia.com/downloads/vulkan-beta-${nvidia_version//.}-linux"
"https://developer.nvidia.com/vulkan-beta-${nvidia_version//.}-linux"
"https://developer.nvidia.com/linux-${nvidia_version//.}"
)
if try_dl "${driver_url_list[0]}" "$NVIDIA_DRIVERS_DIR"||\
try_dl "${driver_url_list[1]}" "$NVIDIA_DRIVERS_DIR"||\
try_dl "${driver_url_list[2]}" "$NVIDIA_DRIVERS_DIR"
then return 0
elif try_dl "${driver_url_list[3]}" "$NVIDIA_DRIVERS_DIR"||\
try_dl "${driver_url_list[4]}" "$NVIDIA_DRIVERS_DIR"||\
try_dl "${driver_url_list[5]}" "$NVIDIA_DRIVERS_DIR" "$nvidia_driver_run"||\
try_dl "${driver_url_list[6]}" "$NVIDIA_DRIVERS_DIR" "$nvidia_driver_run"||\
try_dl "${driver_url_list[7]}" "$NVIDIA_DRIVERS_DIR" "$nvidia_driver_run"
then
binary_files="mkprecompiled nvidia-cuda-mps-control nvidia-cuda-mps-server \
nvidia-debugdump nvidia-installer nvidia-modprobe nvidia-ngx-updater tls_test \
nvidia-persistenced nvidia-powerd nvidia-settings nvidia-smi nvidia-xconfig"
trash_libs="libEGL.so* libGLdispatch.so* *.swidtag libnvidia-egl-wayland.so* \
libGLESv!(*nvidia).so* libGL.so* libGLX.so* libOpenCL.so* libOpenGL.so* \
libnvidia-compiler* *.la"
chmod u+x "$NVIDIA_DRIVERS_DIR/$nvidia_driver_run"
info_msg "Unpacking $nvidia_driver_run..."
(cd "$NVIDIA_DRIVERS_DIR" && \
"./$nvidia_driver_run" --target "$nvidia_version" -x &>/dev/null
rm -f "$nvidia_driver_run")
info_msg "Creating a driver directory structure..."
(cd "$NVIDIA_DRIVERS_DIR/$nvidia_version" && \
rm -rf html kernel* libglvnd_install_checker 32/libglvnd_install_checker \
supported-gpus systemd *.gz *.bz2 *.txt .manifest *.desktop *.png firmware *.h
for temp in $(ls *.template 2>/dev/null) ; do mv "$temp" "${temp%.template}" ; done
try_mkdir profiles && mv *application-profiles* profiles
[ -f "nvoptix.bin" ] && mv nvoptix.bin profiles
[ -n "$(ls *nvngx.dll 2>/dev/null)" ] && try_mkdir wine && mv *nvngx.dll wine
try_mkdir json && mv *.json json
try_mkdir conf && mv *.conf *.icd conf
for lib in $trash_libs ; do rm -f $lib 32/$lib ; done
try_mkdir bin && mv *.sh bin
for binary in $binary_files ; do [ -f "$binary" ] && mv $binary bin ; done
try_mkdir 64 && mv *.so* 64
[ -d "tls" ] && mv tls/* 64 && rm -rf tls
[ -d "32/tls" ] && mv 32/tls/* 32 && rm -rf 32/tls)
info_msg "Creating a squashfs driver image..."
info_msg "$NVIDIA_DRIVERS_DIR/$nvidia_driver_image"
echo -en "$BLUE"
if "$MKSQFS" "$NVIDIA_DRIVERS_DIR/$nvidia_version" "$NVIDIA_DRIVERS_DIR/$nvidia_driver_image" \
-root-owned -no-xattrs -noappend -b 1M -comp zstd -Xcompression-level 19 -quiet
then
info_msg "Deleting the source directory of the driver..."
rm -rf "$NVIDIA_DRIVERS_DIR/$nvidia_version"
return 0
else
return 1
fi
echo -en "$RESETCOLOR"
else
error_msg "Failed to download nvidia driver!"
return 1
fi
else
error_msg "You must specify the nvidia driver version!"
return 1
fi)
}
mount_nvidia_driver_image() {
if [[ -n "$1" && -n "$(echo "$1"|grep -o "\.nv\.drv$")" ]]
then
[ ! -n "$nvidia_version" ] && \
nvidia_version="$(echo "$1"|sed 's|.nv.drv||g')"
[ ! -n "$NVDRVMNT" ] && \
NVDRVMNT="/tmp/.mount_nv${nvidia_version}drv.$RUNPID"
info_msg "Mounting the nvidia driver image: $(basename "$1")"
try_mkdir "$NVDRVMNT"
"$SQFUSE" -f "$1" "$NVDRVMNT" -o ro &>/dev/null &
FUSE_PID="$!"
export FUSE_PIDS="$FUSE_PID $FUSE_PIDS"
if mount_exist "$FUSE_PID" "$NVDRVMNT"
then
nvidia_driver_dir="$NVDRVMNT"
else
error_msg "Failed to mount the nvidia driver image!"
rm -f "$1" 2>/dev/null
return 1
fi
else
error_msg "You must specify the nvidia driver image!"
return 1
fi
}
check_nvidia_driver() {
unset NVIDIA_DRIVER_BIND
print_nv_drv_dir() { info_msg "Found nvidia driver directory: $(basename "$nvidia_driver_dir")" ; }
update_ld_cache() {
if [ "$(cat "$RUNCACHEDIR/ld.so.version" 2>/dev/null)" != "$RUNROOTFS_VERSION-$nvidia_version" ]
then
info_msg "Updating the nvidia library cache..."
if (ALLOW_BG=0 SANDBOX_NET=0 bwrun /usr/bin/ldconfig -C "/tmp/ld.so.cache" 2>/dev/null)
then
try_mkdir "$RUNCACHEDIR"
if mv -f "/tmp/ld.so.cache" \
"$RUNCACHEDIR/ld.so.cache" 2>/dev/null
then
echo "$RUNROOTFS_VERSION-$nvidia_version" > \
"$RUNCACHEDIR/ld.so.version"
if [ -w "$RUNROOTFS" ]
then
cp -f "$RUNCACHEDIR/ld.so.cache" \
"$RUNROOTFS/etc/ld.so.cache" 2>/dev/null
echo "$RUNROOTFS_VERSION-$nvidia_version" > \
"$RUNROOTFS/etc/ld.so.version"
else
ADD_LD_CACHE=1
fi
else
error_msg "Failed to merge nvidia library cache!"
return 1
fi
else
error_msg "Failed to update nvidia library cache!"
return 1
fi
else
if [ -w "$RUNROOTFS" ]
then
if [ "$(cat "$RUNROOTFS/etc/ld.so.version" 2>/dev/null)" != "$RUNROOTFS_VERSION-$nvidia_version" ]
then
cp -f "$RUNCACHEDIR/ld.so.cache" \
"$RUNROOTFS/etc/ld.so.cache" 2>/dev/null
echo "$RUNROOTFS_VERSION-$nvidia_version" > \
"$RUNROOTFS/etc/ld.so.version"
fi
else
ADD_LD_CACHE=1
fi
fi
}
if [ -e '/sys/module/nvidia/version' ]||\
grep -owm1 nvidia /proc/modules &>/dev/null
then
unset nvidia_driver_dir
[ ! -n "$NVIDIA_DRIVERS_DIR" ] && \
export NVIDIA_DRIVERS_DIR="$RUNIMAGEDIR/nvidia-drivers"
if [ -e '/sys/module/nvidia/version' ]
then
nvidia_version="$(cat /sys/module/nvidia/version 2>/dev/null)"
elif modinfo nvidia &>/dev/null
then
nvidia_version="$(modinfo -F version nvidia 2>/dev/null)"
elif nvidia-smi &>/dev/null
then
nvidia_version="$(nvidia-smi --query-gpu=driver_version --format=csv,noheader|head -1)"
else
if [ -d '/usr/lib/x86_64-linux-gnu' ]
then
nvidia_version="$(basename /usr/lib/x86_64-linux-gnu/libGLX_nvidia.so.*.*|tail -c +18)"
else
nvidia_version="$(basename /usr/lib/libGLX_nvidia.so.*.*|tail -c +18)"
fi
fi
if [[ -n "$nvidia_version" && "$nvidia_version" != "*.*" ]]
then
nvidia_version_inside="$(basename "$RUNROOTFS/usr/lib/libGLX_nvidia.so".*.*|tail -c +18)"
if [ "$nvidia_version" != "$nvidia_version_inside" ]
then
if [[ -n "$nvidia_version_inside" && "$nvidia_version_inside" != "*.*" ]]
then
nvidia_driver_image="$nvidia_version.nv.drv"
NVDRVMNT="/tmp/.mount_nv${nvidia_version}drv.$RUNPID"
[ "$nvidia_version_inside" != "000.00.00" ] && \
warn_msg "Nvidia driver version mismatch detected, trying to fix it"
if [ ! -f "$NVIDIA_DRIVERS_DIR/$nvidia_version/64/nvidia_drv.so" ] && \
[ ! -f "$RUNIMAGEDIR/$nvidia_driver_image" ] && \
[ ! -f "$NVIDIA_DRIVERS_DIR/$nvidia_driver_image" ] && \
[ ! -f "$NVDRVMNT/64/nvidia_drv.so" ] && \
[ ! -f "$RUNDIR/nvidia-drivers/$nvidia_version/64/nvidia_drv.so" ] && \
[ ! -f "$RUNDIR/nvidia-drivers/$nvidia_driver_image" ]
then
if DONT_NOTIFY=0 QUIET_MODE=0 get_nvidia_driver_image
then
mount_nvidia_driver_image "$NVIDIA_DRIVERS_DIR/$nvidia_driver_image"
else
nvidia_driver_dir="$NVIDIA_DRIVERS_DIR/$nvidia_version"
fi
else
if [ -f "$NVDRVMNT/64/nvidia_drv.so" ]
then
nvidia_driver_dir="$NVDRVMNT"
print_nv_drv_dir
elif [ -f "$NVIDIA_DRIVERS_DIR/$nvidia_version/64/nvidia_drv.so" ]
then
nvidia_driver_dir="$NVIDIA_DRIVERS_DIR/$nvidia_version"
print_nv_drv_dir
elif [ -f "$RUNIMAGEDIR/$nvidia_driver_image" ]
then
mount_nvidia_driver_image "$RUNIMAGEDIR/$nvidia_driver_image"
elif [ -f "$NVIDIA_DRIVERS_DIR/$nvidia_driver_image" ]
then
mount_nvidia_driver_image "$NVIDIA_DRIVERS_DIR/$nvidia_driver_image"
elif [ -f "$RUNDIR/nvidia-drivers/$nvidia_version/64/nvidia_drv.so" ]
then
nvidia_driver_dir="$RUNDIR/nvidia-drivers/$nvidia_version"
print_nv_drv_dir
elif [ -f "$RUNDIR/nvidia-drivers/$nvidia_driver_image" ]
then
mount_nvidia_driver_image "$RUNDIR/nvidia-drivers/$nvidia_driver_image"
fi
fi
else
error_msg "No nvidia driver found in RunImage!"
return 1
fi
if [ -f "$nvidia_driver_dir/64/nvidia_drv.so" ]
then
nvidia_libs_list="libcuda.so libEGL_nvidia.so libGLESv1_CM_nvidia.so libnvidia-opencl.so \
libGLESv2_nvidia.so libGLX_nvidia.so libnvcuvid.so libnvidia-allocator.so \
libnvidia-cfg.so libnvidia-eglcore.so libnvidia-encode.so libnvidia-fbc.so \
libnvidia-glcore.so libnvidia-glsi.so libnvidia-glvkspirv.so libnvidia-ml.so \
libnvidia-ngx.so libnvidia-opticalflow.so libnvidia-ptxjitcompiler.so libcudadebugger.so \
libnvidia-rtcore.so libnvidia-tls.so libnvidia-vulkan-producer.so libnvoptix.so \
libnvidia-nvvm.so libnvidia-pkcs11.so libnvidia-pkcs11-openssl3.so libnvidia-wayland-client.so"
for lib in ${nvidia_libs_list}
do
if [ -f "$RUNROOTFS/usr/lib/${lib}.${nvidia_version_inside}" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/64/${lib}.${nvidia_version}" \
"/usr/lib/${lib}.${nvidia_version_inside}")
fi
if [ -f "$RUNROOTFS/usr/lib32/${lib}.${nvidia_version_inside}" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/32/${lib}.${nvidia_version}" \
"/usr/lib32/${lib}.${nvidia_version_inside}")
fi
done
if [ -f "$RUNROOTFS/usr/lib/libnvidia-api.so.1" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/64/libnvidia-api.so.1" \
"/usr/lib/libnvidia-api.so.1")
fi
if [ -f "$RUNROOTFS/usr/lib/libnvidia-egl-gbm.so.1.1.0" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/64/libnvidia-egl-gbm.so.1.1.0" \
"/usr/lib/libnvidia-egl-gbm.so.1.1.0")
fi
if [ -f "$RUNROOTFS/usr/lib/xorg/modules/drivers/nvidia_drv.so" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/64/nvidia_drv.so" \
"/usr/lib/xorg/modules/drivers/nvidia_drv.so")
fi
if [ -f "$RUNROOTFS/usr/lib/nvidia/xorg/libglxserver_nvidia.so.${nvidia_version_inside}" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/64/libglxserver_nvidia.so.${nvidia_version}" \
"/usr/lib/nvidia/xorg/libglxserver_nvidia.so.${nvidia_version_inside}")
fi
if [ -f "$RUNROOTFS/usr/lib/vdpau/libvdpau_nvidia.so.${nvidia_version_inside}" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/64/libvdpau_nvidia.so.${nvidia_version}" \
"/usr/lib/vdpau/libvdpau_nvidia.so.${nvidia_version_inside}")
fi
if [ -f "$RUNROOTFS/usr/lib32/vdpau/libvdpau_nvidia.so.${nvidia_version_inside}" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/32/libvdpau_nvidia.so.${nvidia_version}" \
"/usr/lib32/vdpau/libvdpau_nvidia.so.${nvidia_version_inside}")
fi
if [ -f "$RUNROOTFS/usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/json/15_nvidia_gbm.json" \
"/usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json")
fi
if [ -f "$RUNROOTFS/usr/share/glvnd/egl_vendor.d/10_nvidia.json" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/json/10_nvidia.json" \
"/usr/share/glvnd/egl_vendor.d/10_nvidia.json")
fi
if [ -f "$RUNROOTFS/usr/share/vulkan/icd.d/nvidia_icd.json" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/json/nvidia_icd.json" \
"/usr/share/vulkan/icd.d/nvidia_icd.json")
fi
if [ -f "$RUNROOTFS/usr/share/vulkan/implicit_layer.d/nvidia_layers.json" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/json/nvidia_layers.json" \
"/usr/share/vulkan/implicit_layer.d/nvidia_layers.json")
fi
if [ -f "$RUNROOTFS/etc/OpenCL/vendors/nvidia.icd" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/conf/nvidia.icd" \
"/etc/OpenCL/vendors/nvidia.icd")
fi
if [ -d "$RUNROOTFS/usr/share/nvidia" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/profiles" \
"/usr/share/nvidia")
fi
if [ -d "$RUNROOTFS/usr/lib/nvidia/wine" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" \
"$nvidia_driver_dir/wine" \
"/usr/lib/nvidia/wine")
fi
if [ -w "$RUNROOTFS" ]
then
if [[ ! -d "$RUNROOTFS/usr/bin/nvidia" || \
! -d "$RUNROOTFS/usr/lib/nvidia/64" || \
! -d "$RUNROOTFS/usr/lib/nvidia/32" ]]
then
mkdir -p "$RUNROOTFS/usr/bin/nvidia"
mkdir -p "$RUNROOTFS/usr/lib/nvidia/64"
mkdir -p "$RUNROOTFS/usr/lib/nvidia/32"
fi
if [ ! -f "$RUNROOTFS/etc/ld.so.conf.d/nvidia.conf" ]
then
mkdir -p "$RUNROOTFS/etc/ld.so.conf.d"
echo -e "/usr/lib/nvidia/64\n/usr/lib/nvidia/32" > \
"$RUNROOTFS/etc/ld.so.conf.d/nvidia.conf"
rm -f "$RUNCACHEDIR/ld.so."*
fi
fi
if [ -d "$RUNROOTFS/usr/bin/nvidia" ] && \
[ -d "$RUNROOTFS/usr/lib/nvidia/64" ] && \
[ -d "$RUNROOTFS/usr/lib/nvidia/32" ]
then
NVIDIA_DRIVER_BIND+=("--ro-bind-try" "$nvidia_driver_dir/bin" "/usr/bin/nvidia" \
"--ro-bind-try" "$nvidia_driver_dir/64" "/usr/lib/nvidia/64" \
"--ro-bind-try" "$nvidia_driver_dir/32" "/usr/lib/nvidia/32")
add_bin_pth '/usr/bin/nvidia'
add_lib_pth '/usr/lib/nvidia/64:/usr/lib/nvidia/32'
elif [ -d "$nvidia_driver_dir/bin" ] && \
[ -d "$nvidia_driver_dir/64" ] && \
[ -d "$nvidia_driver_dir/32" ]
then
add_bin_pth "$nvidia_driver_dir/bin"
add_lib_pth "$nvidia_driver_dir/64:$nvidia_driver_dir/32"
fi
update_ld_cache
NVXSOCKET="$(ls /run/nvidia-xdriver-* 2>/dev/null|head -1)"
[ -S "$NVXSOCKET" ] && \
XDG_RUN_BIND+=("--bind-try" "$NVXSOCKET" "$NVXSOCKET")
else
error_msg "Nvidia driver not found!"
return 1
fi
fi
fi
fi
}
add_lib_pth() {
if [ -n "$LIB_PATH" ]
then
if [ ! -n "$(echo "$LIB_PATH"|grep -ow "$1" 2>/dev/null)" ]
then
LIB_PATH="${1}:${LIB_PATH}"
fi
else
LIB_PATH="${1}"
fi
}
add_bin_pth() {
if [ -n "$BIN_PATH" ]
then
if [ ! -n "$(echo "$BIN_PATH"|grep -ow "$1" 2>/dev/null)" ]
then
BIN_PATH="${1}:${BIN_PATH}"
fi
else
BIN_PATH="${1}"
fi
}
try_unmount() {
if [ -n "$1" ]
then
unset DORM
if [ -n "$(grep -o "$1" /proc/self/mounts 2>/dev/null)" ]
then
if fusermount -uz "$1" 2>/dev/null
then DORM=1
elif umount -l "$1" 2>/dev/null
then DORM=1
elif [ "$ALLOW_BG" != 1 ] && \
kill -2 $FUSE_PIDS 2>/dev/null
then DORM=1
else
error_msg "Failed to unmount: '$1'"
return 1
fi
elif [ -d "$1" ]
then DORM=1
fi
if [ "$DORM" == 1 ]
then
if ! rm -rf "$1" 2>/dev/null
then
error_msg "Failed to remove: '$1'"
return 1
fi
fi
return 0
fi
return 1
}
try_mkdir() {
if [ ! -d "$1" ]
then
if ! mkdir -p "$1"
then
error_msg "Failed to create directory: '$1'"
cleanup force
exit 1
fi
fi
}
run_attach() {
set_target() {
unset NSU
[ "$EUID" != 0 ] && NSU="-U"
for pid in $(cat "/tmp/.rpids.$1")
do
for args in "-n -p" "-n" "-p" " "
do
if nsenter --preserve-credentials $NSU -m $args \
-t $pid /usr/bin/true &>/dev/null
then
target="$pid"
target_args="$args"
return 0
fi
done
done
return 1
}
ns_attach() {
unset WAITRPIDS
if set_target "$1"
then
info_msg "Attaching to RunImage RUNPID: $1"
(while [[ -d "/proc/$target" && -d "/proc/$RUNPID" ]]
do sleep 0.5 2>/dev/null
done
cleanup force) &
shift
if [[ "$ALLOW_BG" == 1 || "$RUNTTY" =~ "tty" ]]
then
(wait_rpids=100
while [[ "$wait_rpids" -gt 0 && ! -n "$(ps -o pid= -p \
$(cat "$RPIDSFL" 2>/dev/null) 2>/dev/null)" ]]
do
wait_rpids="$(( $wait_rpids - 1 ))"
sleep 0.01 2>/dev/null
done; sleep 1) &
WAITRPIDS=$!
fi
importenv $target nsenter --preserve-credentials \
--wd=/proc/$target/cwd $NSU -m $target_args -t $target "$@"
EXEC_STATUS=$?
[ -n "$WAITRPIDS" ] && \
wait "$WAITRPIDS"
return $EXEC_STATUS
fi
error_msg "Failed to attach to RunImage container!"
return 1
}
if [[ "$1" =~ ^[0-9]+$ ]]
then
if [ -f "/tmp/.rpids.$1" ]
then
if [ -n "$2" ]
then ns_attach "$@"
else ns_attach "$@" "${RUN_SHELL[@]}"
fi
else
error_msg "RunImage container not found by RUNPID: $1"
return 1
fi
else
rpids_num="$(ls -1 /tmp/.rpids.* 2>/dev/null|wc -l)"
if [ "$rpids_num" == 0 ]
then
error_msg "No running RunImage containers found!"
return 1
elif [ "$rpids_num" == 1 ]
then
runpid="$(ls -1 /tmp/.rpids.* 2>/dev/null|head -1|cut -d'.' -f3)"
if [ -n "$1" ]
then ns_attach "$runpid" "$@"
else ns_attach "$runpid" "${RUN_SHELL[@]}"
fi
else
error_msg "Specify the RunImage RUNPID!"
info_msg "Available RUNPIDs: $(echo $(ls -1 /tmp/.rpids.* 2>/dev/null|cut -d'.' -f3))"
return 1
fi
fi
}
force_kill() {
unset SUCCKILL MOUNTPOINTS SUCCUMNT
MOUNTPOINTS="$(grep -E "$([ -n "$RUNIMAGENAME" ] && \
echo "$RUNIMAGENAME"||echo "$RUNIMAGEDIR")|/tmp/.mount_nv.*drv|unionfs.*$RUNIMAGEDIR" \
/proc/self/mounts|grep -v "$RUNDIR"|awk '{print$2}')"
if [ -n "$MOUNTPOINTS" ]
then
(IFS=$'\n' ; for umnt in $MOUNTPOINTS
do try_unmount "$umnt"
done) && SUCCUMNT=1
fi
try_kill "$(cat /tmp/.rpids.* 2>/dev/null)" && \
SUCCKILL=1
[[ "$SUCCKILL" == 1 || "$SUCCUMNT" == 1 ]] && \
info_msg "RunImage successfully killed!"
}
try_kill() {
ret=1
if [ -n "$1" ]
then
for pid in $1
do
trykillnum=0
while [[ -n "$pid" && -d "/proc/$pid" ]]
do
if [[ "$trykillnum" -lt 1 ]]
then
kill -2 $pid 2>/dev/null
ret=$?
sleep 0.05 2>/dev/null
elif [[ "$trykillnum" -lt 2 ]]
then
kill -15 $pid 2>/dev/null
ret=$?
sleep 0.05 2>/dev/null
else
kill -9 $pid 2>/dev/null
ret=$?
break
fi
trykillnum="$(( $trykillnum + 1 ))"
done
done
fi
return $ret
}
cleanup() {
if [[ "$NO_CLEANUP" != 1 || "$1" == "force" ]]
then
[ "$1" == "force" ] && \
QUIET_MODE=1
if [ -n "$FUSE_PIDS" ]
then
[[ "$ALLOW_BG" != 1 && "$KEEP_OVERFS" != 1 ]] && \
try_unmount "$OVERFS_MNT"
[[ "$ALLOW_BG" == 1 && -d "$OVERFS_MNT" ]] ||\
try_unmount "$RO_MNT"
try_unmount "$NVDRVMNT"
fi
[ -d "$EXECFLDIR" ] && \
rm -rf "$EXECFLDIR" 2>/dev/null
if [[ "$ALLOW_BG" != 1 || "$1" == "force" ]]
then
kill -2 $FUSE_PIDS 2>/dev/null
if [ -n "$DBUSP_PID" ]
then
kill $DBUSP_PID 2>/dev/null
[ -S "$DBUSP_SOCKET" ] && \
rm -f "$DBUSP_SOCKET" 2>/dev/null
fi
try_kill "$(cat "$RPIDSFL" 2>/dev/null)"
if [[ -d "$OVERFS_DIR" && "$KEEP_OVERFS" != 1 ]]
then
info_msg "Removing OverlayFS..."
rm -rf "$OVERFS_DIR" 2>/dev/null
fi
fi
[ -f "$RPIDSFL" ] && \
rm -f "$RPIDSFL" 2>/dev/null
[ -f "$BWINFFL" ] && \
rm -f "$BWINFFL" 2>/dev/null
[ -f "$UNPASSWDFL" ] && \
rm -f "$UNPASSWDFL" 2>/dev/null
[ -f "$UNGROUPFL" ] && \
rm -f "$UNGROUPFL" 2>/dev/null
else
warn_msg "Cleanup is disabled!"