forked from m-ab-s/media-autobuild_suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media-suite_helper.sh
1921 lines (1750 loc) · 63.5 KB
/
media-suite_helper.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 [[ ! $cpuCount =~ ^[0-9]+$ ]]; then
cpuCount="$(($(nproc)/2))"
fi
bits="${bits:-64bit}"
curl_opts=(/usr/bin/curl --connect-timeout 15 --retry 3
--retry-delay 5 --silent --location --insecure --fail)
if command -v tput &>/dev/null; then
ncolors=$(tput colors)
if test -n "$ncolors" && test "$ncolors" -ge 8; then
bold=$(tput bold)
blue=$(tput setaf 12)
orange=$(tput setaf 11)
purple=$(tput setaf 13)
green=$(tput setaf 2)
red=$(tput setaf 1)
reset=$(tput sgr0)
fi
ncols=72
fi
[[ -f "$LOCALBUILDDIR"/grep.exe ]] &&
rm -f "$LOCALBUILDDIR"/{7za,wget,grep}.exe
do_print_status() {
local name="$1 "
local color="$2"
local status="$3"
local pad
pad=$(printf '%0.1s' "."{1..72})
if [[ $timeStamp = y ]]; then
printf "${purple}"'%(%H:%M:%S)T'"${reset}"' %s%*.*s [%s]\n' -1 "${bold}$name${reset}" 0 \
"$((ncols-${#name}-${#status}-12))" "$pad" "${color}${status}${reset}"
else
printf '%s%*.*s [%s]\n' "${bold}$name${reset}" 0 \
"$((ncols-${#name}-${#status}-3))" "$pad" "${color}${status}${reset}"
fi
}
do_print_progress() {
if [[ $logging = y ]]; then
if [[ $timeStamp = y ]]; then
[[ ${1} =~ ^[a-zA-Z] ]] && printf "${purple}"'%(%H:%M:%S)T'"${reset}"' %s\n' -1 \
"${bold}├${reset} $*..." || printf "${purple}"'%(%H:%M:%S)T'"${reset}"' %s\n' -1 "$*..."
else
[[ ${1} =~ ^[a-zA-Z] ]] && echo "${bold}├${reset} $*..." || echo -e "$*..."
fi
else
set_title "$* in $(get_first_subdir)"
if [[ $timeStamp = y ]]; then
printf "${purple}"'%(%H:%M:%S)T'"${reset}"' %s\n' -1 "${bold}$* in $(get_first_subdir)${reset}"
else
echo -e "${bold}$* in $(get_first_subdir)${reset}"
fi
fi
}
set_title() {
local title="media-autobuild_suite ($bits)"
[[ -z $1 ]] || title="$title: $1"
echo -ne "\e]0;$title\a"
}
do_exit_prompt() {
if [[ -n $build32 || -n $build64 ]]; then
create_diagnostic
zip_logs
fi
do_prompt "$*"
[[ -n $build32 || -n $build64 ]] && exit 1
}
cd_safe() {
cd "$1" || do_exit_prompt "Failed changing to directory $1."
}
test_newer() {
[[ $1 = installed ]] && local installed=y && shift
local file
local files=("$@")
local cmp="${files[-1]}"
[[ $installed ]] && cmp="$(file_installed "$cmp")"
[[ ${#files[@]} -gt 1 ]] && unset 'files[-1]'
[[ -f $cmp ]] || return 0
for file in "${files[@]}"; do
[[ $installed ]] && file="$(file_installed "$file")"
[[ -f $file ]] &&
[[ $file -nt "$cmp" ]] && return
done
return 1
}
check_valid_vcs() {
local root="${1:-.}"
local _type="${vcsType:-git}"
[[ "$_type" = "git" && -d "$root"/.git ]] ||
[[ "$_type" = "hg" && -d "$root"/.hg ]] ||
[[ "$_type" = "svn" && -d "$root"/.svn ]]
}
vcs_clone() {
set -x
if [[ "$vcsType" = "svn" ]]; then
svn checkout -r "$ref" "$vcsURL" "$vcsFolder"-svn
else
"$vcsType" clone "$vcsURL" "$vcsFolder-$vcsType"
fi
set +x
check_valid_vcs "$vcsFolder-$vcsType"
}
vcs_reset() {
local ref="$1"
check_valid_vcs
set -x
if [[ $vcsType = svn ]]; then
svn revert --recursive .
oldHead=$(svnversion)
elif [[ $vcsType = hg ]]; then
hg update -C -r "$ref"
oldHead=$(hg id --id)
elif [[ $vcsType = git ]]; then
[[ -n "$vcsURL" ]] && git remote set-url origin "$vcsURL"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
[[ -f .git/refs/heads/ab-suite ]] || git branch -f --no-track ab-suite
git checkout ab-suite
git reset --hard "$(vcs_getlatesttag "$ref")"
oldHead=$(git rev-parse HEAD)
fi
set +x
}
vcs_update() {
local ref="$1"
check_valid_vcs
set -x
if [[ $vcsType = svn ]]; then
svn update -r "$ref"
newHead=$(svnversion)
elif [[ $vcsType = hg ]]; then
hg pull
hg update -C -r "$ref"
newHead=$(hg id --id)
elif [[ $vcsType = git ]]; then
local unshallow
[[ -f .git/shallow ]] && unshallow="--unshallow"
git fetch -t $unshallow origin
ref="$(vcs_getlatesttag "$ref")"
git reset --hard "$ref"
newHead=$(git rev-parse HEAD)
fi
set +x
}
vcs_log() {
check_valid_vcs
if [[ "$vcsType" = "git" ]]; then
git log --no-merges --pretty="%ci: %an - %h%n %s" \
"$oldHead".."$newHead" >> "$LOCALBUILDDIR"/newchangelog
elif [[ "$vcsType" = "hg" ]]; then
hg log --template "{date|localdate|isodatesec}: {author|person} - {node|short}\n {desc|firstline}\n" \
-r "reverse($oldHead:$newHead)" >> "$LOCALBUILDDIR"/newchangelog
fi
}
vcs_getlatesttag() {
local ref="$1"
if [[ -n "$vcsType" && "$vcsType" != git ]]; then
echo "$ref"
return
fi
local tag
if [[ "$ref" = "LATEST" ]]; then
tag="$(git describe --abbrev=0 --tags "$(git rev-list --tags --max-count=1)")"
elif [[ "$ref" = "GREATEST" ]]; then
tag="$(git describe --abbrev=0 --tags)"
elif [[ "${ref//\*}" != "$ref" ]]; then
tag="$(git describe --abbrev=0 --tags "$(git tag -l "$ref" | sort -Vr | head -1)")"
fi
echo "${tag:-${ref}}"
}
# get source from VCS
# example:
# do_vcs "url#branch|revision|tag|commit=NAME" "folder"
do_vcs() {
local vcsType="${1%::*}"
local vcsURL="${1#*::}"
[[ "$vcsType" = "$vcsURL" ]] && vcsType="git"
local vcsBranch="${vcsURL#*#}"
[[ "$vcsBranch" = "$vcsURL" ]] && vcsBranch=""
local vcsFolder="$2"
local vcsCheck=("${_check[@]}")
local deps=("${_deps[@]}") && unset _deps
local ref
if [[ $vcsBranch ]]; then
vcsURL="${vcsURL%#*}"
case ${vcsBranch%%=*} in
commit|tag|revision)
ref=${vcsBranch##*=}
;;
branch)
ref=${vcsBranch##*=}
[[ $vcsType = git && $ref = ${ref%/*} ]] && ref=origin/$ref
;;
esac
else
if [[ $vcsType = git ]]; then
ref="origin/HEAD"
elif [[ $vcsType = hg ]]; then
ref="tip"
elif [[ $vcsType = svn ]]; then
ref="HEAD"
fi
fi
[[ ! "$vcsFolder" ]] && vcsFolder="${vcsURL##*/}" && vcsFolder="${vcsFolder%.*}"
cd_safe "$LOCALBUILDDIR"
if [[ ! -d "$vcsFolder-$vcsType" ]]; then
do_print_progress " Running $vcsType clone for $vcsFolder"
log quiet "$vcsType.clone" vcs_clone || do_exit_prompt "Failed cloning to $vcsFolder-$vcsType"
if [[ -d "$vcsFolder-$vcsType" ]]; then
cd_safe "$vcsFolder-$vcsType"
touch recently_updated recently_checked
else
echo "$vcsFolder $vcsType seems to be down"
echo "Try again later or <Enter> to continue"
do_prompt "if you're sure nothing depends on it."
return
fi
else
cd_safe "$vcsFolder-$vcsType"
fi
if [[ $ffmpegUpdate = onlyFFmpeg ]] &&
[[ $vcsFolder != ffmpeg ]] && [[ $vcsFolder != mpv ]] &&
{ { [[ -z "${vcsCheck[*]}" ]] && files_exist "$vcsFolder.pc"; } ||
{ [[ -n "${vcsCheck[*]}" ]] && files_exist "${vcsCheck[@]}"; }; }; then
do_print_status "${vcsFolder} ${vcsType}" "$green" "Already built"
return 1
fi
log quiet "$vcsType.reset" vcs_reset "$ref" || do_exit_prompt "Failed resetting in $vcsFolder-$vcsType"
if ! [[ -f recently_checked && recently_checked -nt "$LOCALBUILDDIR"/last_run ]]; then
do_print_progress " Running $vcsType update for $vcsFolder"
log quiet "$vcsType.update" vcs_update "$ref" || do_exit_prompt "Failed updating in $vcsFolder-$vcsType"
touch recently_checked
else
newHead="$oldHead"
fi
rm -f custom_updated
check_custom_patches
if { [[ "$oldHead" != "$newHead" ]] || [[ -f custom_updated ]]; }; then
touch recently_updated
rm -f ./build_successful{32,64}bit{,_*}
if [[ $build32 = "yes" && $build64 = "yes" ]] && [[ $bits = "64bit" ]]; then
new_updates="yes"
new_updates_packages="$new_updates_packages [$vcsFolder]"
fi
echo "$vcsFolder" >> "$LOCALBUILDDIR"/newchangelog
vcs_log
echo >> "$LOCALBUILDDIR"/newchangelog
do_print_status "┌ ${vcsFolder} ${vcsType}" "$orange" "Updates found"
elif [[ -f recently_updated ]] && { [[ ! -f "build_successful$bits" ]] ||
[[ -n "$flavor" && ! -f "build_successful${bits}_${flavor}" ]]; }; then
do_print_status "┌ ${vcsFolder} ${vcsType}" "$orange" "Recently updated"
elif [[ -z "${vcsCheck[*]}" ]] && ! files_exist "$vcsFolder.pc"; then
do_print_status "┌ ${vcsFolder} ${vcsType}" "$orange" "Missing pkg-config"
elif [[ -n "${vcsCheck[*]}" ]] && ! files_exist "${vcsCheck[@]}"; then
do_print_status "┌ ${vcsFolder} ${vcsType}" "$orange" "Files missing"
elif [[ -n "${deps[*]}" ]] && test_newer installed "${deps[@]}" "${vcsCheck[0]}"; then
do_print_status "┌ ${vcsFolder} ${vcsType}" "$orange" "Newer dependencies"
else
do_print_status "${vcsFolder} ${vcsType}" "$green" "Up-to-date"
return 1
fi
return 0
}
guess_dirname() {
expr "$1" : '\(.\+\)\.\(tar\(\.\(gz\|bz2\|xz\)\)\?\|7z\|zip\)$'
}
check_hash() {
local file="$1" check="$2" md5sum sha256sum
if [[ -f $file ]]; then
md5sum=$(md5sum "$file" | awk '{ print $1 }')
sha256sum=$(sha256sum "$file" | awk '{ print $1 }')
if [[ $check = print ]]; then
echo "$sha256sum"
else
test "$sha256sum" = "$check" || test "$md5sum" = "$check"
fi
else
return 1
fi
}
# get wget download
do_wget() {
local nocd norm quiet hash notmodified
while true; do
case $1 in
-c) nocd=nocd && shift;;
-r) norm=y && shift;;
-q) quiet=y && shift;;
-h) hash="$2" && shift 2;;
-z) notmodified=y && shift;;
--) shift; break;;
*) break;;
esac
done
local url="$1" archive="$2" dirName="$3" response_code curlcmds tries=1
if [[ -z $archive ]]; then
# remove arguments and filepath
archive=${url%%\?*}
archive=${archive##*/}
fi
[[ ! $dirName ]] && dirName=$(guess_dirname "$archive")
[[ ! $nocd ]] && cd_safe "$LOCALBUILDDIR"
if ! check_hash "$archive" "$hash"; then
[[ ${url#/patches} != "$url" || ${url#/extras} != "$url" ]] &&
url="https://jb-alvarado.github.io/media-autobuild_suite${url}"
curlcmds=("${curl_opts[@]}")
[[ $notmodified && -f $archive ]] && curlcmds+=(-z "$archive" -R)
[[ $hash ]] && tries=3
while [[ $tries -gt 0 ]]; do
response_code="$("${curlcmds[@]}" -w "%{response_code}" -o "$archive" "$url")"
(( tries-=1 ))
if [[ $response_code = "200" || $response_code = "226" ]]; then
[[ $quiet ]] || do_print_status "┌ ${dirName:-$archive}" "$orange" "Downloaded"
if { [[ $hash ]] && check_hash "$archive" "$hash"; } || [[ ! $hash ]]; then
tries=0
else
rm -f "$archive"
fi
elif [[ $response_code = "304" ]]; then
[[ $quiet ]] || do_print_status "┌ ${dirName:-$archive}" "$orange" "File up-to-date"
if { [[ $hash ]] && check_hash "$archive" "$hash"; } || [[ ! $hash ]]; then
tries=0
else
rm -f "$archive"
fi
fi
done
if [[ $response_code -gt 400 || $response_code = "000" ]]; then
if [[ -f $archive ]]; then
echo -e "${orange}${archive}${reset}"
echo -e "\tFile not found online. Using local copy."
else
do_print_status "└ ${dirName:-$archive}" "$red" "Failed"
echo "Error $response_code while downloading $url"
echo "<Ctrl+c> to cancel build or <Enter> to continue"
do_prompt "if you're sure nothing depends on it."
return 1
fi
fi
else
[[ $quiet ]] || do_print_status "${bold}├${reset} ${dirName:-$archive}" "$green" "File up-to-date"
fi
[[ $norm ]] || add_to_remove "$(pwd)/$archive"
do_extract "$archive" "$dirName"
[[ ! $norm && $dirName && ! $nocd ]] && add_to_remove
[[ -z $response_code || $response_code != "304" ]] && return 0
}
real_extract() {
case $archive_type in
zip|7z)
7z x -aoa -o"$2" "$1"
;;
tar*)
[[ $archive_type = tar.* ]] && 7z x -aoa "$1"
if [[ $(/usr/bin/file -b "${1%.tar*}.tar") = POSIX* ]]; then
tar -xf "${1%.tar*}.tar" || 7z x -aoa "${1%.tar*}.tar"
else
7z x -aoa "${1%.tar*}.tar"
fi
rm -f "${1%.tar*}.tar"
;;
esac
}
do_extract() {
local nocd="${nocd:-}"
local archive="$1" dirName="$2" archive_type
# accepted: zip, 7z, tar, tar.gz, tar.bz2 and tar.xz
[[ -z "$dirName" ]] && dirName=$(guess_dirname "$archive")
archive_type=$(expr "$archive" : '.\+\(tar\(\.\(gz\|bz2\|xz\)\)\?\|7z\|zip\)$')
if [[ $dirName != "." && -d "$dirName" ]] &&
{ [[ $build32 = "yes" ]] && { [[ ! -f "$dirName"/build_successful32bit ]] ||
[[ -n "$flavor" && ! -f "$dirName/build_successful32bit_${flavor}" ]]; } ||
[[ $build64 = "yes" ]] && { [[ ! -f "$dirName"/build_successful64bit ]] ||
[[ -n "$flavor" && ! -f "$dirName/build_successful64bit_${flavor}" ]]; };
}; then
rm -rf "$dirName"
elif [[ -d "$dirName" ]]; then
[[ $nocd ]] || cd_safe "$dirName"
return 0
elif [[ ! $archive_type ]]; then
return 0
fi
log "extract" real_extract "$archive" "$dirName"
[[ -d "$dirName/$dirName" ]] &&
find "$dirName/$dirName" -maxdepth 1 -print0 | xargs -r0 mv -t "$dirName/" &&
rmdir "$dirName/$dirName" 2>/dev/null
[[ $nocd ]] || cd_safe "$dirName"
}
do_wget_sf() {
# do_wget_sf "faac/faac-src/faac-1.28/faac-$_ver.tar.bz2" "faac-$_ver"
local hash
[[ $1 = "-h" ]] && hash="$2" && shift 2
local url="https://download.sourceforge.net/$1"
shift 1
check_custom_patches
if [[ -n $hash ]]; then
do_wget -h "$hash" "$url" "$@"
else
do_wget "$url" "$@"
fi
}
do_strip() {
local cmd exts nostrip file val
local cmd=(strip)
local nostrip="x265|x265-numa|ffmpeg|ffprobe|ffplay"
local exts="exe|dll|com|a"
[[ -f $LOCALDESTDIR/bin-video/mpv.exe.debug ]] && nostrip+="|mpv"
for file; do
if [[ "$file" =~ \.($exts)$ && ! "$file" =~ ($nostrip)\.exe$ ]]; then
do_print_progress Stripping
break
fi
done
for file; do
local orig_file="$file"
if ! file="$(file_installed $orig_file)"; then
continue
fi
if [[ $file =~ \.(exe|com)$ ]] &&
[[ ! $file =~ ($nostrip)\.exe$ ]]; then
cmd+=(--strip-all)
elif [[ $file =~ \.dll$ ]] ||
[[ $file =~ x265(|-numa)\.exe$ ]]; then
cmd+=(--strip-unneeded)
elif ! disabled debug && [[ $file =~ \.a$ ]]; then
cmd+=(--strip-debug)
else
file=""
fi
[[ $file ]] &&
{ eval "${cmd[@]}" "$file" 2>/dev/null ||
eval "${cmd[@]}" "$file" -o "$file.stripped" 2>/dev/null; }
[[ -f ${file}.stripped ]] && mv -f "${file}"{.stripped,}
done
}
do_pack() {
local file
local cmd=(/opt/bin/upx -9 -qq)
local nopack=""
local exts="exe|dll"
[[ $bits = 64bit ]] && enabled_any libtls openssl && nopack="ffmpeg|mplayer|mpv"
for file; do
if [[ "$file" =~ \.($exts)$ && ! "$file" =~ ($nopack)\.exe$ ]]; then
do_print_progress Packing with UPX
break
fi
done
for file; do
local orig_file="$file"
if ! file="$(file_installed $orig_file)"; then
continue
fi
if [[ $file =~ \.($exts)$ ]] &&
! [[ -n "$nopack" && $file =~ ($nopack)\.exe$ ]]; then
[[ $stripping = y ]] && cmd+=(--strip-relocs=0)
else
file=""
fi
[[ $file ]] && eval "${cmd[@]}" "$file"
done
}
do_zipman() {
local file
local man_dirs=(/local{32,64}/share/man)
local files=$(find ${man_dirs[@]} -type f \! -name "*.gz" \! -name "*.db" \! -name "*.bz2" 2>/dev/null)
for file in $files; do
gzip -9 -n -f "$file"
rm -f "$file"
done
}
# check if compiled file exist
do_checkIfExist() {
local packetName
packetName="$(get_first_subdir)"
local dry="${dry:-n}"
local check=("${_check[@]}")
[[ -z ${check[*]} ]] && echo "No files to check" && exit 1
if [[ $dry = y ]]; then
files_exist -v -s "${check[@]}"
else
if files_exist -v "${check[@]}"; then
[[ $stripping = y ]] && do_strip "${check[@]}"
[[ $packing = y ]] && do_pack "${check[@]}"
do_print_status "└ $packetName" "$blue" "Updated"
[[ $build32 = yes || $build64 = yes ]] && [[ -d "$LOCALBUILDDIR/$packetName" ]] &&
touch "$LOCALBUILDDIR/$packetName/build_successful$bits"
else
[[ $build32 = yes || $build64 = yes ]] && [[ -d "$LOCALBUILDDIR/$packetName" ]] &&
rm -f "$LOCALBUILDDIR/$packetName/build_successful$bits"
do_print_status "└ $packetName" "$red" "Failed"
echo
echo "Try deleting '$LOCALBUILDDIR/$packetName' and start the script again."
echo "If you're sure there are no dependencies <Enter> to continue building."
do_prompt "Close this window if you wish to stop building."
fi
fi
unset _check
unset_extra_script
}
file_installed() {
local file
local silent
[[ "$1" = "-s" ]] && silent=y
case $1 in
/*|./* )
file="$1" ;;
*.pc )
file="lib/pkgconfig/$1" ;;
*.a|*.la|*.lib )
file="lib/$1" ;;
*.h|*.hpp|*.c )
file="include/$1" ;;
* )
file="$1" ;;
esac
[[ ${file::1} != "/" ]] && file="$LOCALDESTDIR/$file"
[[ -z $silent ]] && echo "$file"
test -e "$file"
}
files_exist() {
local verbose list soft ignorebinaries term="\n"
while true; do
case $1 in
-v) verbose=y && shift;;
-l) list=y && shift;;
-s) soft=y && shift;;
-b) ignorebinaries=y && shift;;
-l0) list=y && term="\0" && shift;;
--) shift; break;;
*) break;;
esac
done
local file
[[ $list ]] && verbose= && soft=y
for opt; do
if file=$(file_installed $opt); then
[[ $verbose && $soft ]] && do_print_status "${bold}├${reset} $file" "${green}" "Found"
if [[ $list ]]; then
if [[ $ignorebinaries && $file =~ .(exe|com)$ ]]; then
continue
fi
echo -n "$file" && echo -ne "$term"
fi
else
[[ $verbose ]] && do_print_status "${bold}├${reset} $file" "${red}" "Not found"
[[ ! $soft ]] && return 1
fi
done
return 0
}
pc_exists() {
for opt; do
local _pkg=${opt%% *}
local _check=${opt#$_pkg}
[[ $_pkg = "$_check" ]] && _check=""
[[ $_pkg = *.pc ]] || _pkg="${LOCALDESTDIR}/lib/pkgconfig/${_pkg}.pc"
pkg-config --exists --silence-errors "${_pkg}${_check}" || return
done
}
do_install() {
[[ $1 = dry ]] && local dryrun=y && shift
local files=("$@")
local dest="${files[-1]}"
[[ ${dest::1} != "/" ]] && dest="$(file_installed "$dest")"
[[ ${#files[@]} -gt 1 ]] && unset 'files[-1]'
[[ ${dest: -1:1} = "/" ]] && mkdir -p "$dest"
if [[ -n $dryrun ]]; then
echo install -D -p "${files[@]}" "$dest"
else
extra_script pre install
install -D -p "${files[@]}" "$dest"
extra_script post install
fi
}
do_uninstall() {
local dry quiet all files
[[ $1 = dry ]] && dry=y && shift
[[ $1 = q ]] && quiet=y && shift
[[ $1 = all ]] && all=y && shift
[[ $all ]] && files=($(files_exist -l "$@")) || files=($(files_exist -l -b "$@"))
if [[ -n "${files[*]}" ]]; then
[[ ! $quiet ]] && do_print_progress Running uninstall
if [[ $dry ]]; then
echo "rm -rf ${files[*]}"
else
rm -rf "${files[@]}"
fi
fi
}
do_pkgConfig() {
local pkg="${1%% *}"
local pc_check="${1#$pkg}"
local pkg_and_version="$pkg"
[[ $pkg = "$pc_check" ]] && pc_check=""
local version=$2
local deps=("${_deps[@]}") && unset _deps
[[ ! "$version" && "$pc_check" ]] && version="${pc_check#*= }"
[[ "$version" ]] && pkg_and_version="${pkg} ${version}"
if ! pc_exists "${pkg}"; then
do_print_status "${pkg_and_version}" "$red" "Not installed"
elif ! pc_exists "${pkg}${pc_check}"; then
do_print_status "${pkg_and_version}" "$orange" "Outdated"
elif [[ -n "${deps[*]}" ]] && test_newer installed "${deps[@]}" "${pkg}.pc"; then
do_print_status "${pkg_and_version}" "$orange" "Newer dependencies"
elif [[ -n "${_check[*]}" ]] && ! files_exist "${_check[@]}"; then
do_print_status "${pkg_and_version}" "$orange" "Files missing"
else
do_print_status "${pkg_and_version}" "$green" "Up-to-date"
return 1
fi
}
do_readoptionsfile() {
local filename="$1"
if [[ -f "$filename" ]]; then
< $filename dos2unix |
sed -r '# remove commented text
s/#.*//
# delete empty lines
/^\s*$/d
# remove leading/trailing whitespace
s/(^\s+|\s+$)//
'
echo "Imported options from ${filename##*/}" >&2
fi
}
do_readbatoptions() {
local varname="$1"
printf '%s\n' "${bat[@]}" | \
sed -rne "/set ${varname}=/,/[^^]$/p" | \
sed -re '/^:/d' -e "s/(set ${varname}=| \^|\")//g" | tr ' ' '\n' | \
sed -re '/^#/d' -e '/^[^-]/{s/^/--enable-/g}'
}
do_getFFmpegConfig() {
local license="${1:-nonfree}"
FFMPEG_DEFAULT_OPTS=()
if [[ -f "/trunk/media-autobuild_suite.bat" && $ffmpegChoice =~ (n|z|f) ]]; then
IFS=$'\n' read -d '' -r -a bat < <(< /trunk/media-autobuild_suite.bat dos2unix)
FFMPEG_DEFAULT_OPTS=($(do_readbatoptions "ffmpeg_options_(builtin|basic)"))
[[ $ffmpegChoice != n ]] &&
FFMPEG_DEFAULT_OPTS+=($(do_readbatoptions "ffmpeg_options_zeranoe"))
[[ $ffmpegChoice = f ]] &&
FFMPEG_DEFAULT_OPTS+=($(do_readbatoptions "ffmpeg_options_full"))
echo "Imported default FFmpeg options from .bat"
else
local custom_opts_file="$LOCALBUILDDIR/ffmpeg_options.txt"
if [[ -f "$LOCALBUILDDIR/ffmpeg_options_$bits.txt" ]]; then
custom_opts_file="$LOCALBUILDDIR/ffmpeg_options_$bits.txt"
fi
IFS=$'\n' read -d '' -r -a FFMPEG_DEFAULT_OPTS < \
<(do_readoptionsfile "$custom_opts_file")
echo "Imported custom options from ${custom_opts_file##*/}"
fi
echo "License: $license"
FFMPEG_OPTS=("${FFMPEG_BASE_OPTS[@]}" "${FFMPEG_DEFAULT_OPTS[@]}")
# we set these accordingly for static or shared
do_removeOption "--(en|dis)able-(shared|static)"
# OK to use GnuTLS for rtmpdump if not nonfree since GnuTLS was built for rtmpdump anyway
# If nonfree will use SChannel if neither openssl/libtls or gnutls are in the options
if ! enabled_any libtls openssl gnutls &&
{ enabled librtmp || [[ $rtmpdump = y ]]; }; then
if [[ $license = nonfree ]] ||
[[ $license = lgpl* && $rtmpdump = n ]]; then
do_addOption --enable-openssl
else
do_addOption --enable-gnutls
fi
do_removeOption "--enable-(gmp|gcrypt|mbedtls)"
fi
local _all_tls="--enable-(mbedtls|gnutls|openssl|libtls|schannel)"
if enabled_any libtls openssl && [[ $license != gpl* ]]; then
# prefer openssl/libtls if both are in options and not gpl
# prefer openssl over libtls if both enabled
local _prefer=libtls
if enabled openssl; then
_prefer=openssl
fi
do_removeOption "${_all_tls}"
do_addOption "--enable-${_prefer}"
elif enabled mbedtls; then
# prefer mbedtls if any other tls libs are enabled and gpl
do_removeOption "${_all_tls}"
do_addOption --enable-mbedtls
elif enabled gnutls; then
do_removeOption "${_all_tls}"
do_addOption --enable-gnutls
elif ! disabled schannel; then
# fallback to schannel if no other tls libs are enabled
do_addOption --enable-schannel
fi
enabled_any lib{vo-aacenc,aacplus,utvideo,dcadec,faac,ebur128,ndi_newtek,ndi-newtek} netcdf &&
do_removeOption "--enable-(lib(vo-aacenc|aacplus|utvideo|dcadec|faac|ebur128|ndi_newtek|ndi-newtek)|netcdf)" &&
sed -ri 's;--enable-(lib(vo-aacenc|aacplus|utvideo|dcadec|faac|ebur128|ndi_newtek|ndi-newtek)|netcdf);;g' \
"$LOCALBUILDDIR/ffmpeg_options.txt"
}
do_changeFFmpegConfig() {
local license="${1:-nonfree}"
do_print_progress Changing options to comply to "$license"
# if w32threads is disabled, pthreads is used and needs this cflag
# decklink includes zvbi, which requires pthreads
if disabled w32threads || enabled pthreads || enabled_all decklink libzvbi || enabled libvmaf; then
do_removeOption --enable-w32threads
do_addOption --disable-w32threads
fi
# add options for static kvazaar
enabled libkvazaar && do_addOption --extra-cflags=-DKVZ_STATIC_LIB
# get libs restricted by license
local config_script=configure
[[ $(get_first_subdir) != "ffmpeg-git" ]] && config_script="$LOCALBUILDDIR/ffmpeg-git/configure"
[[ -f "$config_script" ]] || do_exit_prompt "There's no configure script to retrieve libs from"
eval "$(sed -n '/EXTERNAL_LIBRARY_GPL_LIST=/,/^"/p' "$config_script")"
eval "$(sed -n '/HWACCEL_LIBRARY_NONFREE_LIST=/,/^"/p' "$config_script")"
eval "$(sed -n '/EXTERNAL_LIBRARY_NONFREE_LIST=/,/^"/p' "$config_script")"
eval "$(sed -n '/EXTERNAL_LIBRARY_VERSION3_LIST=/,/^"/p' "$config_script")"
# handle gpl libs
local gpl=(${EXTERNAL_LIBRARY_GPL_LIST//_/-} gpl)
if [[ $license = gpl* || $license = nonfree ]] &&
{ enabled_any "${gpl[@]}" || ! disabled postproc; }; then
do_addOption --enable-gpl
else
do_removeOptions "${gpl[*]/#/--enable-} --enable-postproc --enable-gpl"
fi
# handle (l)gplv3 libs
local version3=(${EXTERNAL_LIBRARY_VERSION3_LIST//_/-})
if [[ $license =~ (l|)gplv3 || $license = nonfree ]] && enabled_any "${version3[@]}"; then
do_addOption --enable-version3
else
do_removeOptions "${version3[*]/#/--enable-} --enable-version3"
fi
local nonfreehwaccel=(${HWACCEL_LIBRARY_NONFREE_LIST//_/-})
if [[ $license = "nonfree" ]] && enabled_any "${nonfreehwaccel[@]}"; then
do_addOption --enable-nonfree
else
do_removeOptions "${nonfreehwaccel[*]/#/--enable-} --enable-nonfree"
fi
# cuda-only workarounds
if [[ $license = "nonfree" ]] && verify_cuda_deps; then
if enabled libnpp; then
echo -e "${orange}FFmpeg and related apps will depend on CUDA SDK to run!${reset}"
local fixed_CUDA_PATH="$(cygpath -sm "$CUDA_PATH")"
do_addOption "--extra-cflags=-I$fixed_CUDA_PATH/include"
do_addOption "--extra-ldflags=-L$fixed_CUDA_PATH/lib/x64"
fi
if enabled cuda-nvcc; then
local fixed_CUDA_PATH_UNIX="$(cygpath -u "$CUDA_PATH")"
command -v nvcc.exe &>/dev/null || export PATH="$PATH:$fixed_CUDA_PATH_UNIX/bin"
echo -e "${orange}FFmpeg and related apps will depend on Nvidia drivers!${reset}"
fi
else
do_removeOption "--enable-(libnpp|cuda-nvcc)"
fi
# handle gpl-incompatible libs
local nonfreegpl=(${EXTERNAL_LIBRARY_NONFREE_LIST//_/-})
if enabled_any "${nonfreegpl[@]}"; then
if [[ $license = "nonfree" ]] && enabled gpl; then
do_addOption --enable-nonfree
elif [[ $license = gpl* ]]; then
do_removeOptions "${nonfreegpl[*]/#/--enable-}"
fi
# no lgpl here because they are accepted with it
fi
if ! disabled debug "debug=gdb"; then
# fix issue with ffprobe not working with debug and strip
do_addOption --disable-stripping
fi
# both openssl and mbedtls don't need gcrypt/gmp for rtmpe
enabled_any openssl mbedtls && do_removeOption "--enable-(gcrypt|gmp)"
# remove libs that don't work with shared
if [[ $ffmpeg =~ "shared" || $ffmpeg = "both" ]]; then
FFMPEG_OPTS_SHARED=("${FFMPEG_OPTS[@]}")
fi
}
opt_exists() {
local array="${1}[@]" && shift 1
local opt value
for opt; do
for value in "${!array}"; do
[[ "$value" =~ $opt ]] && return
done
done
return 1
}
enabled() {
test "${FFMPEG_OPTS[*]}" != "${FFMPEG_OPTS[*]#--enable-$1}"
}
disabled() {
test "${FFMPEG_OPTS[*]}" != "${FFMPEG_OPTS[*]#--disable-$1}"
}
enabled_any() {
local opt
for opt; do
enabled "$opt" && return 0
done
return 1
}
disabled_any() {
local opt
for opt; do
disabled "$opt" && return 0
done
return 1
}
enabled_all() {
local opt
for opt; do
enabled "$opt" || return 1
done
return 0
}
disabled_all() {
local opt
for opt; do
disabled "$opt" || return 1
done
return 0
}
do_getMpvConfig() {
MPV_OPTS=()
if [[ -f "/trunk/media-autobuild_suite.bat" && "$ffmpegChoice" =~ (n|z|f) ]]; then
IFS=$'\n' read -d '' -r -a bat < <(< /trunk/media-autobuild_suite.bat dos2unix)
MPV_OPTS=($(do_readbatoptions "mpv_options_(builtin|basic)"))
[[ $ffmpegChoice = f ]] &&
MPV_OPTS+=($(do_readbatoptions "mpv_options_full"))
echo "Imported default mpv options from .bat"
else
IFS=$'\n' read -d '' -r -a MPV_OPTS < \
<(do_readoptionsfile "$LOCALBUILDDIR/mpv_options.txt")
fi
do_removeOption MPV_OPTS \
"--(en|dis)able-(vapoursynth-lazy|libguess|static-build|enable-gpl3|egl-angle-lib|encoding)"
if [[ $mpv = "y" ]]; then
mpv_disabled vapoursynth || do_addOption MPV_OPTS --disable-vapoursynth
elif [[ $mpv = "v" ]] && ! mpv_disabled vapoursynth; then
do_addOption MPV_OPTS --enable-vapoursynth
fi
}
mpv_enabled() {
local option
[[ $mpv = n ]] && return 1
for option in "${MPV_OPTS[@]}"; do
[[ "$option" =~ "--enable-$1"$ ]] && return
done
return 1
}
mpv_disabled() {
local option
[[ $mpv = n ]] && return 0
for option in "${MPV_OPTS[@]}"; do
[[ "$option" =~ "--disable-$1"$ ]] && return
done
return 1
}
mpv_enabled_any() {
local opt
for opt; do
mpv_enabled "$opt" && return 0
done
return 1
}
mpv_enabled_all() {
local opt
for opt; do
mpv_enabled $opt || return 1
done
}
mpv_disabled_all() {
local opt
for opt; do
mpv_disabled $opt || return 1
done
}
mpv_enable() {
local opt newopts=()
for opt in "${MPV_OPTS[@]}"; do
if [[ "$opt" =~ "--disable-$1"$ ]]; then
newopts+=("--enable-$1")
else
newopts+=("$opt")
fi
done
MPV_OPTS=("${newopts[@]}")
}
mpv_disable() {
local opt newopts=()
for opt in "${MPV_OPTS[@]}"; do
if [[ "$opt" =~ "--enable-$1"$ ]]; then
newopts+=("--disable-$1")
else
newopts+=("$opt")
fi
done
MPV_OPTS=("${newopts[@]}")
}
do_addOption() {
local varname="$1" array opt
if [[ ${varname#--} = $varname ]]; then
array="$varname" && shift 1
else
array="FFMPEG_OPTS"
fi
for opt; do
! opt_exists "$array" "$opt" && declare -ag "$array+=(\"$opt\")"
done
}
do_removeOption() {
local varname="$1"
local arrayname
if [[ ${varname#--} = $varname ]]; then
arrayname="$varname" && shift 1
else
arrayname="FFMPEG_OPTS"
fi
local option="$1"
local basearray opt temp=()
basearray="${arrayname}[@]"
local orig=("${!basearray}")
for ((i = 0; i < ${#orig[@]}; i++)); do
if [[ ! "${orig[$i]}" =~ ^${option}$ ]]; then
temp+=("${orig[$i]}")
fi
done
eval "$arrayname"=\(\"\${temp[@]}\"\)