-
Notifications
You must be signed in to change notification settings - Fork 0
/
assets.make
executable file
·2071 lines (1739 loc) · 63.7 KB
/
assets.make
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
# TODO:
# - 2.12.2021: update of multi-package PKGBUILD? Install should work, but deletion of old packages (thus updating) doesn't!
# - older: check if deletion of e.g. pamac-aur might remove also pamac-aur-git (names have same beginning)
# - better epoch handling
echoreturn() { echo "$@" ; } # for "return" values!
echo2() { echo "$@" >&2 ; } # output to stderr
printf2() { printf "$@" >&2 ; } # output to stderr
DIE() {
echo2 "Error: $@"
if [ "${FUNCNAME[1]}" = "Main" ] ; then
Usage
fi
Destructor
exit 1
}
WARN() { echo2 -n "Warning: " ; echo2 "$@" ; }
FileSizePrint() {
# Print size of file in bytes, numbers are is groups of three.
# Examples:
# 43854 ==> 43 854
# 52341928 ==> 52 341 928
# Note: user must align right if needed.
local file="$1"
local nr nr2="" nrtail
local left remove=3
nr=$(stat -c %s "$file")
left=${#nr}
while [ $left -gt 0 ] ; do
if [ $remove -gt $left ] ; then
remove=$left
fi
((left -= remove))
nrtail="${nr: -remove}"
nr="${nr:: -remove}"
nr2="$nrtail $nr2"
done
[ "${nr2::1}" = " " ] && nr2="${nr2:1}" # skip leading space
[ "${nr2: -1}" = " " ] && nr2="${nr2:: -1}" # skip trailing space
echo "$nr2"
}
read2() {
# Special handling for option -t (and -p).
# The read value goes to the REPLY variable only.
local name=""
local prompt=""
local count=0
local cr=$'\r'
local args=()
local arg
local has_t_opt="no"
local prev=""
local retval=0
OPTIND=1 # for some reason this is required!
# get the prompt and timeout (=count) values, if they exist
while getopts ersa:d:i:n:N:p:t:u: name ; do
case $name in
t) count="$OPTARG" ; has_t_opt="yes" ;;
p) prompt="$OPTARG" ;;
esac
done
# add parameters from "$@" to the "args" array, except -t and -p and their values
for arg in "$@" ; do
case "$arg" in
-t) prev=t ;;
-t*) ;;
-p) prev=p ;;
-p*) ;;
*)
case "$prev" in
t|p) prev="" ;;
*) args+=("$arg") ;;
esac
;;
esac
done
# read value
if [ "$has_t_opt" = "yes" ] ; then
# while reading, show a seconds counter
while [ $count -gt 0 ] ; do
printf2 "%s[%s] " "$cr" "$count"
read -t 1 -p "$prompt" "${args[@]}" >&2
retval=$?
test $retval -eq 0 && break
test -n "$REPLY" && break
((count--))
done
else
# just read the value, no special handling
read -p "$prompt" "${args[@]}" >&2
retval=$?
fi
test -z "$REPLY" && echo2 ""
return $retval
}
Pushd() { pushd "$@" >/dev/null || DIE "${FUNCNAME[1]}: pushd $* failed" ; }
Popd() {
local count=1 xx
case "$1" in
-c=*) count=${1:3} ; shift ;;
-c*) count=${1:2} ; shift ;;
esac
for ((xx=0;xx<count;xx++)) ; do
popd "$@" >/dev/null || DIE "${FUNCNAME[1]}: popd $* failed"
done
}
GetPkgbuildValue() { # this is used in assets.conf too!
#
# Extract one or more values from variables of file PKGBUILD into respective user variables.
#
# Usage: GetPkgbuildValue PKGBUILD toVariable pkgbuildVariable [torVariable pkgbuildVariable [toVariable pkgbuildVariable] ...]
#
# Example:
# local Pkgver Pkgrel # user variables
# GetPkgbuildValue $mydir/PKGBUILD Pkgver "pkgver" Pkgrel "pkgrel"
# will return values of 'pkgver' and 'pkgrel' from $mydir/PKGBUILD into Pkgver and Pkgrel, respectively
#
local PKGBUILD="$1"
shift
while declare -F pkgver &> /dev/null ; do
unset -f pkgver # remove possible function from another PKGBUILD
done
source "$PKGBUILD" || return 1 # reading PKGBUILD may fail
while [ "$1" ] ; do
[ "$2" ] || DIE "$FUNCNAME: internal error: number of call parameters is not even!"
local -n retvar_for_all="$1"
GetPkgbuildValue1 "$2" retvar_for_all
unset -n retvar_for_all
shift 2
done
}
CursorLeft() { local num="$1"; echo2 -en "\033[${num}D"; } # move cursor left $num chars
GetPkgbuildValue1() {
local varname="$1"
local -n retvar="$2"
local retval2=""
case "$varname" in
arch) retvar=("${arch[@]}") ;;
backup) retvar=("${backup[@]}") ;;
conflicts) retvar=("${conflicts[@]}") ;;
depends) retvar=("${depends[@]}") ;;
makedepends) retvar=("${makedepends[@]}") ;;
optdepends) retvar=("${optdepends[@]}") ;;
pkgname) retvar=("${pkgname[@]}") ;;
provides) retvar=("${provides[@]}") ;;
replaces) retvar=("${replaces[@]}") ;;
source) retvar=("${source[@]}") ;;
validpgpkeys) retvar=("${validpgpkeys[@]}") ;;
epoch) retvar="$epoch" ;;
install) retvar="$install" ;;
pkgdesc) retvar="$pkgdesc" ;;
pkgrel) retvar="$pkgrel" ;;
url) retvar="$url" ;;
_ver) retvar="$_ver" ;;
pkgver)
if declare -F pkgver &> /dev/null ; then
# printf2 " running function pkgver() ... "
if [ $listing_updates = yes ] ; then
CursorLeft 2
HookIndicator "$hook_pkgver_func" yes
# echo2 -n "p "
fi
# We want to run pkgver() to get the correct pkgver.
# But first we must run makepkg because the needed git stuff hasn't been fetched yet...
Pushd ${PKGBUILD%/*}
makepkg --skipinteg -od &> /dev/null || DIE "$FUNCNAME: cannot determine 'pkgver' from $PKGBUILD."
# sed -E -i "$PKGBUILD" -e "s|^pkgrel=[0-9\.]+|pkgrel=$pkgrel|" # Prevents makepkg from changing pkgrel to 1.
if false ; then
unset -f pkgver
source "$PKGBUILD"
retvar="$(pkgver)"
else
retvar=$(grep ^pkgver= "$PKGBUILD") # pkgver=something
retvar=${retvar#*=} # remove pkgver=
retvar=${retvar%% *} # remove all after space
retvar=${retvar//[\'\"]/} # remove all quote marks
fi
unset -f pkgver
Popd
retval2="$(echo "$retvar" | tail -n1)" # $retvar may have 2 items in 2 lines !?
[ -n "$retval2" ] && retvar="$retval2"
else
retvar="$pkgver"
fi
;;
*)
WARN "$FUNCNAME: unsupported variable name '$varname'"
return 1
;;
esac
}
IsListedPackage() {
# Is a package one of the listed packages in PKGNAMES?
local Pkgname="$1"
printf "%s\n" "${PKGNAMES[@]}" | grep -P "^$Pkgname/aur$|^$Pkgname$" >/dev/null
}
IsAurPackage() {
# Determine AUR from PKGNAMES array directly since we don't have PKGBUILD yet.
local Pkgname="$1"
printf "%s\n" "${PKGNAMES[@]}" | grep "^$Pkgname/aur$" >/dev/null
}
HandlePossibleEpoch() {
# Github release assets cannot have colon (:) in the file name.
# So if a package has an epoch value in PKGBUILD, return a new fixed name for a package
# fetched from github release assets.
local Pkgname="$1" # e.g. welcome
local pkg="$2" # e.g. welcome-2.3.9.6-1-any.pkg.tar.zst # assumes: epoch=2
local -n Newname="$3"
local cwd=""
local Epoch=""
if [ ! -r PKGBUILD ] ; then
cwd="$PWD"
if [ ! -r "$PKGBUILD_ROOTDIR/$Pkgname/PKGBUILD" ] ; then
if IsAurPackage "$Pkgname" ; then
cd "$PKGBUILD_ROOTDIR"
yay -Ga "$Pkgname" >/dev/null || DIE "fetching PKGBUILD of '$Pkgname' failed."
else
DIE "sorry, getting PKGBUILD of '$Pkgname' not supported yet."
fi
fi
cd "$PKGBUILD_ROOTDIR/$Pkgname"
fi
GetPkgbuildValue "PKGBUILD" Epoch "epoch"
if [ -z "$Epoch" ] ; then
Newname="$pkg"
else
Newname=$(echo "$pkg" | sed "s|\(${Pkgname}-[0-9][0-9]*\)\.\(.*\)|\1:\2|")
fi
if [ -n "$cwd" ] ; then
cd "$cwd"
[ -n "$tmpdir" ] && rm -rf $tmpdir
fi
}
IncludesOption() {
local where="$1" # list of options, e.g. "-r --rmdeps"
local opt="$2" # e.g. "-r"
printf "%s\n" $where | grep -w "\\$opt" >/dev/null
}
Build()
{
local pkgdirname="$1"
local assetsdir="$2"
local pkgbuilddir="$3"
local Pkgname
local pkg pkgs
local workdir=$(mktemp -d)
local log=$workdir/buildlog-"$pkgdirname".log
local missdeps="Missing dependencies"
local opts=""
local msg=""
if [ "${#PKG_MAKEPKG_OPTIONS[@]}" -gt 0 ] ; then
if [ -n "${PKG_MAKEPKG_OPTIONS[$pkgdirname]}" ] ; then # from assets.conf
opts="${PKG_MAKEPKG_OPTIONS[$pkgdirname]}"
fi
fi
Pushd "$workdir"
cp -r "$pkgbuilddir" .
Pkgname="$(PkgBuildName "$pkgdirname")"
Pushd "$workdir/$pkgdirname"
# now build, assume we have PKGBUILD
# special handling for missing dependencies
LANG=C makepkg --clean $opts 2>/dev/null >"$log" || {
if [ -z "$(grep "$missdeps:" "$log")" ] ; then
Popd -c2
DIE "makepkg for '$Pkgname' failed"
fi
msg="Installing $(echo "$missdeps" | tr [:upper:] [:lower:])"
if IncludesOption "$opts" "--rmdeps" || IncludesOption "$opts" "-r" ; then
msg+=" and removing them right after build"
fi
echo2 "$msg:"
# grep -A100 "$missdeps:" "$log" | grep "^ -> " >&2
# use special pacman wrapper in the makepkg call below
local wrapper=/usr/bin/pacman-for-assets.make
[ -x "$wrapper" ] || DIE "sorry, $wrapper does not exist!"
PACMAN=$wrapper makepkg --syncdeps --clean $opts >/dev/null || { Popd -c2 ; DIE "makepkg for '$Pkgname' failed" ; }
}
pkgs=(*.pkg.tar.$_COMPRESSOR)
case "$pkgs" in
"" | "*.pkg.tar.$_COMPRESSOR") DIE "$pkgdirname: build failed" ;;
esac
for pkg in $pkgs ; do
# HandlePossibleEpoch "$Pkgname" "$pkg" pkg # not needed here since makepkg should handle epoch OK (?)
mv $pkg "$assetsdir"
built+=("$assetsdir/$pkg")
built_under_this_pkgname+=("$pkg")
done
Popd
Popd
rm -rf "$workdir"
}
PkgBuildName()
{
local pkgdirname="$1"
source "$PKGBUILD_ROOTDIR"/"$(JustPkgname "$pkgdirname")"/PKGBUILD
echoreturn "$pkgname"
}
PkgBuildVersion()
{
local _pkgdirname="$1"
local _srcfile="$PKGBUILD_ROOTDIR"/"$(JustPkgname "$_pkgdirname")"/PKGBUILD
if [ ! -r "$_srcfile" ] ; then
DIE "'$_srcfile' does not exist."
fi
local Epoch="" Pkgver="" Pkgrel=""
# GetPkgbuildValue "$_srcfile" Epoch "epoch" Pkgver "pkgver" Pkgrel "pkgrel"
GetPkgbuildValue "$_srcfile" Epoch "epoch"
GetPkgbuildValue "$_srcfile" Pkgver "pkgver"
GetPkgbuildValue "$_srcfile" Pkgrel "pkgrel"
if [ -n "$Epoch" ] ; then
echoreturn "$Epoch:${Pkgver}-$Pkgrel"
else
echoreturn "${Pkgver}-$Pkgrel"
fi
}
LocalVersion()
{
local Pkgname="$1"
local pkgs
local xx
Pkgname="$(JustPkgname "$Pkgname")"
for xx in zst xz ; do # order is important because of change to zstd!
pkgs=$(ListPkgsWithName "$ASSETSDIR/$Pkgname" "$xx")
test -n "$pkgs" && break
done
[ "$pkgs" ] || { echoreturn "0"; return; }
case "$(echo "$pkgs" | wc -l)" in
0) echoreturn "0" ; return ;;
1) ;;
*) echo2 -n "$hook_multiversion "
# WARN -n "$Pkgname: many local versions, using the latest. "
pkgs="$(echo "$pkgs" | tail -n 1)"
;;
esac
local tail="$(echo "$pkgs" | sed 's|^.*/'"$Pkgname"'-||')"
local ver="$(echo "$tail" | cut -d '-' -f 1)"
local rel="$(echo "$tail" | cut -d '-' -f 2)"
echoreturn "${ver}-$rel"
}
AurMarkingFail() {
local fakepath="$1" # no more: "aur/pkgname"
DIE "marking AUR packages as $fakepath is no more supported!"
}
JustPkgname()
{
local fakepath="$1"
case "$fakepath" in
./*) fakepath="${fakepath:2}" ;;
*/aur) fakepath="${fakepath:: -4}" ;;
aur/*) AurMarkingFail "$fakepath" ;;
# *) fakepath="${fakepath}" ;;
esac
echoreturn ${fakepath##*/}
}
HookIndicator() {
local mark="$1"
local force="$2"
if [ "$fetch" = "yes" ] || [ "$force" = "yes" ] ; then
echo2 -n "$mark "
fi
}
ExplainHookMarks() {
printf2 "\nPossible markings above mean indications from %s:\n" "$ASSETS_CONF"
printf2 " %s = a package hook changed pkgver in PKGBUILD.\n" "$hook_pkgver"
printf2 " %s = execute pkgver() from PKGBUILD.\n" "$hook_pkgver_func" # not a hook!
printf2 " %s = a package hook found many local versions, used latest.\n" "$hook_multiversion"
printf2 " %s = a package hook was executed.\n" "$hook_yes"
printf2 " %s = compare new and existing PKGBUILD files from AUR.\n" "$hook_compare"
printf2 "\n"
}
FetchAurPkgs() {
local pkgs
readarray -t pkgs <<< $(printf "%s\n" "${PKGNAMES[@]}" | /bin/grep /aur | /bin/sed 's|/aur||')
if [ "${pkgs[0]}" ] ; then
echo2 "==> From AUR: ${pkgs[*]}"
local -r url="https://aur.archlinux.org"
curl -Lsm 30 "$url" >/dev/null || DIE "sorry, $url is not currently available!"
rm -rf "${pkgs[@]}"
yay -Ga "${pkgs[@]}" >/dev/null || DIE "yay -Ga ${pkgs[*]} failed."
fi
}
ListNameToPkgName()
{
# "returns" pkgdirname and hookout
#
# PKGNAMES array (from $ASSETS_CONF) uses certain syntax for package names
# to mark where they come from, either local or AUR packages.
# AUR packages are fetched from AUR, local packages
# are simply used from a local folder.
#
# Supported syntax:
# pkgname local package
# ./pkgname local package (emphasis)
# aur/pkgname AUR package "aur/pkgname" NO MORE SUPPORTED!
# pkgname/aur AUR package (another way)
local xx="$1"
local run_hook="$2"
local Pkgname
local hook
hookout=""
Pkgname=$(JustPkgname "$xx")
[ "${xx::4}" = "aur/" ] && AurMarkingFail "$xx"
# if [ "${xx: -4}" = "/aur" ] ; then
# case "$run_hook" in
# yes)
# rm -rf "$Pkgname"
# yay -Ga "$Pkgname" >/dev/null || DIE "'yay -Ga $Pkgname' failed."
# # Compare "$Pkgname" "$Pkgname/PKGBUILD" || return 1
# ;;
# esac
# fi
# A pkg may need some changes:
hook="${ASSET_PACKAGE_HOOKS[$Pkgname]}"
if [ -n "$hook" ] ; then
if [ "$run_hook" = "yes" ] ; then
hookout=$($hook)
case $? in
0) HookIndicator "$hook_yes" ;; # OK
11) HookIndicator "$hook_pkgver" ;; # pkgver was updated by hook
1) HookIndicator "?" ;; # failed
*) HookIndicator "??" ;; # unknown error
esac
fi
else
HookIndicator "$hook_no"
fi
pkgdirname="$Pkgname"
}
Compare() {
# Compare new PKGBUILD from AUR to the saved PKGBUILD.
local PKGNAME="$1"
local pkgbuild_new="$2"
local pkgbuild_old="$HOME/.aur-pkgbuilds/$PKGNAME/PKGBUILD"
mkdir -p "${pkgbuild_old%/*}"
if [ -e "$pkgbuild_old" ] ; then
diff "$pkgbuild_old" "$pkgbuild_new" >/dev/null && return # return if identical
fi
HookIndicator "$hook_compare"
/bin/meld "$pkgbuild_old" "$pkgbuild_new"
if [ -e "$pkgbuild_old" ] ; then
# Skip copying if package is marked as unacceptable, or user wants to skip.
if [ "${SKIP_UNACCEPTABLE_PKGBUILD[$PKGNAME]}" ] ; then
echo2 "SKIP (unacceptable PKGBUILD)"
return 1
else
read -p "Continue $PROGNAME (Y/n): " >&2
case "$REPLY" in
[Nn]*) DIE "stopped due to the unacceptable PKGBUILD of $PKGNAME" ;;
esac
fi
fi
/bin/cp "$pkgbuild_new" "$pkgbuild_old"
}
LogStuff() {
case "$cmd" in
dryrun-local) return ;; # avoid unnecessary pw asking
# dryrun) return ;; # avoid unnecessary pw asking
esac
if which logstuff >& /dev/null ; then
if ! logstuff state ; then
echo2 "==> logstuff on"
logstuff on
fi
fi
}
HubRelease() {
hub release "$@"
}
HubReleaseShow() {
# also convert characters:
# %2B ==> +
# %3A ==> :
HubRelease show "$@" | sed -e 's|%2B|+|g' # -e 's|%3A|:|g'
}
GetRemoteAssetNames() {
GetFromGit() {
local dir="$1"
if [ -r "$dir/$REPONAME.db" ] && [ -d "$GITDIR/.git" ] ; then
Pushd "$dir"
git pull >& /dev/null
remote_files=$(ls -1 | sort)
Popd
return 0
else
return 1
fi
}
if [ "$PREFER_GIT_OVER_RELEASE" = "yes" ] ; then
names_from_git=yes
case "$REPONAME" in
endeavouros) GetFromGit "$GITDIR/$REPONAME/$ARCH" && return ;;
endeavouros-testing-dev) GetFromGit "$GITDIR/$REPONAME" && return ;;
*) GetFromGit "$GITDIR/repo" && return ;;
esac
fi
# fallback to release assets
remote_files=$(release-asset-names ${RELEASE_TAGS[0]} | sort)
names_from_git=no
}
AskFetchingFromGithub() {
local -r msg="Fetch assets from github (Y=only if different, n=no, f=yes)? "
if [ "$fetch_timeout" ] ; then
read2 -p "$msg" -t "$fetch_timeout"
else
printf2 "\n%s " "$msg"
read2
fi
case "$REPLY" in
[yY]*|"")
echo2 "==> Using remote assets if there are differences, otherwise local."
;;
[fF]*|"")
echo2 "==> Using remote assets."
return 0
;;
*)
echo2 "==> Using local assets."
echo2 ""
return 1
;;
esac
# Selected using remote assets with checks.
# Check if there differences between local and remote file names.
# If not, use local assets.
DebugBreak "remote assets with checking"
local local_files=""
local remote_files=""
local diffs=none # what kind of diffs, if any?
if [ "$use_release_assets" = "yes" ] ; then
local_files=$(ls -1 *.{db,files,zst,xz,sig} 2> /dev/null | sort) # $asset_file_endings
GetRemoteAssetNames
fi
if [ "$local_files" != "$remote_files" ] ; then
# There are differences in file names.
# Could be the epoch related file name change, they will be fixed later.
if [ "$names_from_git" = "yes" ] ; then
diffs=real
elif OnlyEpochDiffs ; then
diffs=epoch # because of github
else
diffs=real
fi
if [ $diffs = real ] ; then
local tmpdir_local=$(mktemp -d /tmp/local.XXX)
local tmpdir_remote=$(mktemp -d /tmp/remote.XXX)
touch $(echo "$local_files" | sed "s|^|$tmpdir_local/|")
touch $(echo "$remote_files" | sed "s|^|$tmpdir_remote/|")
LANG=C diff $tmpdir_local $tmpdir_remote | sed -E \
-e "s|^Only in /tmp/remote[^:]+: |Only in REMOTE: |" \
-e "s|^Only in /tmp/local[^:]+: |Only in LOCAL: |"
rm -rf $tmpdir_local $tmpdir_remote
fi
fi
case "$diffs" in
none) return 1 ;; # no diffs ==> local
epoch) return 1 ;; # only epoch no diffs ==> local
real) return 0 ;; # real diffs ==> remote
esac
}
OnlyEpochDiffs() {
# input: $local_files and $remote_files
local count_ll=$(echo "$local_files" | wc -l)
local count_rr=$(echo "$remote_files" | wc -l)
local loc rem
local ll rr ix
local epoch_diff_count=0
[ "$count_ll" != "$count_rr" ] && return 1
readarray -t loc <<< $(echo "$local_files")
readarray -t rem <<< $(echo "$remote_files")
# epoch test: change first colon in local to dot and compare to remote
for ((ix=0; ix < count_ll; ix++)) ; do
ll="${loc[$ix]}"
rr="${rem[$ix]}"
[ "${ll}" = "$rr" ] && continue # local = remote
[ "${ll/:/.}" = "$rr" ] && {
((epoch_diff_count++))
continue # only epoch diff, will be fixed later
}
return 1 # real diff found
done
if [ $epoch_diff_count -gt 0 ] ; then
echo2 "Local and remote file names have only epoch diffs (because of github limitations) and they will be fixed automatically."
echo2 ""
fi
return 0
}
Assets_clone()
{
local names_from_git=no
if [ "$cmd" = "dryrun-local" ] && [ "$REPONAME" != "endeavouros_calamares" ] ; then
return
fi
if [ "$use_release_assets" = "no" ] ; then
if [ -n "$GITREPOURL" ] && [ -n "$GITREPODIR" ] ; then
AskFetchingFromGithub || return 0
echo2 "==> Copying files from the git repo to local dir."
local tmpdir=$(mktemp -d)
Pushd $tmpdir
git clone "$GITREPOURL" >& /dev/null || DIE "cloning '$GITREPOURL' failed"
rm -f "$ASSETSDIR"/*.{db,files,zst,xz,sig,txt,old} # $asset_file_endings
cp "$GITREPODIR"/*.{db,files,zst,xz,sig} "$ASSETSDIR" # $asset_file_endings
sync
Popd
rm -rf $tmpdir
else
DIE "GITREPOURL and/or GITREPODIR missing for $REPONAME while USE_RELEASE_ASSETS = '$use_release_assets'"
fi
return
fi
local xx yy hook
# It is possible that your local release assets in folder $ASSETSDIR
# are not in sync with github.
# If so, you can delete your local assets and fetch assets from github now.
case "$REPONAME" in
endeavouros_calamares) ;; # many maintainers, so make sure we have the same assets!
*)
if [ "$repoup" = "1" ] ; then
echo2 "==> Using local assets."
return
fi
AskFetchingFromGithub || return 0
;;
esac
Pushd "$ASSETSDIR"
local tag
local remotes remote
local waittime=30
for tag in "${RELEASE_TAGS[@]}" ; do
remotes="$(HubReleaseShow -f %as%n $tag | sed 's|^.*/||')"
for remote in $remotes ; do
[ -r $remote ] || break
done
break
done
DebugBreak "remote asset checking"
if [ -r $remote ] ; then
read2 -p "Asset names at github are the same as here, fetch anyway (y/N)? " -t $waittime
case "$REPLY" in
[yY]*) ;;
*) Popd ; return ;;
esac
fi
save_folder=$(mktemp -d "$PWD"/SAVED.XXX)
echo2 "==> Saving current local assets to '$save_folder' ..."
# $pkgname in PKGBUILD may not be the same as values in $PKGNAMES,
# so delete all packages and databases.
# rm -f *.{db,files,zst,xz,sig,txt,old} # $asset_file_endings
mv *.{db,files,zst,xz,sig,txt,old} "$save_folder"/ 2>/dev/null # $asset_file_endings
local leftovers="$(command ls *.{db,files,zst,xz,sig,old} 2>/dev/null)" # $asset_file_endings
test -z "$leftovers" || DIE "removing local assets failed!"
echo2 "==> Fetching all github assets..."
hook="${ASSET_PACKAGE_HOOKS[assets_mirrors]}"
for xx in "${RELEASE_TAGS[@]}" ; do
if [ "$names_from_git" = "yes" ] ; then
local cpdir=""
case "$REPONAME" in
endeavouros) cpdir="$GITDIR/$REPONAME/$ARCH" ;;
endeavouros-testing-dev) cpdir="$GITDIR/$REPONAME" ;;
*) cpdir="$GITDIR/repo" ;;
esac
[ -n "$cpdir" ] || DIE "git dir is empty, cannot copy files"
echo2 "==> Copying files from '$cpdir' ..."
cp "$cpdir"/* .
else
HubRelease download $xx
sleep 1
# Unfortunately github release assets cannot contain a colon (epoch mark) in file name, so rename those packages locally
# after fetching them above.
local oldname newname Pkgname
for oldname in *.pkg.tar.{zst,xz} ; do
case "$oldname" in
"*.pkg."*) continue ;;
esac
Pkgname=$(pkg-name-components N "$oldname")
IsListedPackage "$Pkgname" || continue
HandlePossibleEpoch "$Pkgname" "$oldname" newname
if [ "$newname" != "$oldname" ] ; then
echo2 "==> Fix: $oldname --> $newname"
echo2 "==> Fix: $oldname.sig --> $newname.sig"
mv $oldname $newname
mv $oldname.sig $newname.sig
fi
done
fi
test -n "$hook" && { $hook && break ; } # we need assets from only one tag since assets in other tags are the same
done
Popd
}
PkgbuildExists() {
local Pkgname="$1" # a name from "${PKGNAMES[@]}"
local special="$2"
local yy=$(JustPkgname "$Pkgname")
if [ -r "$PKGBUILD_ROOTDIR/$yy/PKGBUILD" ] ; then
return 0
else
((no_pkgbuild_count++))
if [ "$special" != "" ] ; then
local files=$(ls -l "$PKGBUILD_ROOTDIR/$yy" 2>/dev/null)
printf2 "$WARNING (${PROGNAME}, $special): no PKGBUILD!\n"
if [ -n "$files" ] ; then
printf2 "File listing:\n"
echo2 "$files" | sed 's|^| ==> |'
fi
fi
return 1
fi
}
IsEmptyString() {
local name="$1"
local value="${!name}"
test -n "$value" || DIE "value of variable '$name' is empty"
}
DirExists() {
local name="$1"
local docreate="$2"
local value="${!name}"
case "$docreate" in
yes) mkdir -p "$value" ;;
*) test -d "$value" || {
DIE "variable '$name' has folder name value '$value' - the folder does not exist"
} ;;
esac
}
ShowIndented() {
# shows the "head" of a listed value, possibly indented
local txt="$1"
local indent_level="$2" # optional number >= 0
local xx
local ind=""
case "$indent_level" in
"") ;;
*)
for ((xx=0; xx < indent_level; xx++)) ; do
ind+=" "
done
;;
esac
printf2 "%s%-35s : " "$ind" "$1"
}
RationalityTests()
{
ShowIndented "Checking values in $ASSETS_CONF"
IsEmptyString ASSETSDIR
IsEmptyString PKGBUILD_ROOTDIR
IsEmptyString GITDIR
IsEmptyString PKGNAMES
IsEmptyString REPONAME
IsEmptyString RELEASE_TAGS
IsEmptyString SIGNER
DirExists ASSETSDIR
DirExists PKGBUILD_ROOTDIR yes # silently create the dir
DirExists GITDIR
if [ -z "$REPO_COMPRESSOR" ] ; then
REPO_COMPRESSOR=xz
fi
echo2 "done."
}
Constructor()
{
# make sure proper .git symlink exists; create new or change existing if necessary
if [ ! "$GITDIR"/.git -ef "$ASSETSDIR"/.git ] ; then
echo2 "Warning: '$ASSETSDIR/.git' ($(ls -l $ASSETSDIR/.git)) does not refer to proper place, fixing..."
rm -f "$ASSETSDIR"/.git || DIE "failed to remove: '$ASSETSDIR/.git'"
ln -s "$GITDIR"/.git "$ASSETSDIR"/.git || DIE "failed to symlink: '$ASSETSDIR/.git' -> '$GITDIR/.git'"
fi
}
Destructor()
{
[ -n "$save_folder" ] && rm -rf "$save_folder"
test -n "$buildsavedir" && rm -rf "$buildsavedir"
}
ShowOldCompressedPackages() {
# If we have *both* .zst and .xz package, show the .xz package.
local pkg pkgdir Pkgname
local pkg2 pkg22
for pkg in $(ls "$ASSETSDIR"/*.pkg.tar.zst 2>/dev/null) ; do
Pkgname=${pkg##*/}
pkgdir=${pkg%/*}
pkg2="$pkgdir/$(echo "$Pkgname" | sed 's|\-[0-9].*$||')"
pkg22="$(ls "$pkg2"-*.pkg.tar.xz 2>/dev/null)"
if [ -n "$pkg22" ] ; then
for pkg2 in $pkg22 ; do
printf2 "Remove old packages:\n %s\n %s\n" "$pkg2" "$pkg2.sig"
rm -i "$pkg2" "$pkg2.sig"
done
fi
done
}
_ASSERT_() {
local ret=0
"$@" &> /dev/null || ret=$?
if [ $ret -ne 0 ] ; then
echo2 "'$*' failed"
exit $ret
fi
}
_pkgbuilds_alt_hook() {
if [ -d "$ASSETSDIR/.$REPONAME/.git" ] ; then
_ASSERT_ pushd "$ASSETSDIR/.$REPONAME"
printf2 "git pull... "
_ASSERT_ git pull
else
_ASSERT_ pushd "$ASSETSDIR"
_ASSERT_ rmdir "$PKGBUILD_ROOTDIR"
_ASSERT_ rm -f "${PKGBUILD_ROOTDIR##*/}"
printf2 "git clone... "
_ASSERT_ git clone "$GITREPOURL" ".$REPONAME"
_ASSERT_ ln -s ".$REPONAME/${PKGBUILD_ROOTDIR##*/}"
fi
_ASSERT_ popd
echo2 "done."
}
PkgAdjusted() { printf2 "$pkg: planned adjustment. "; }
Fix_PKGBUILD_if_changed() {
local out=$(/bin/git diff) # used for detecting local changes in PKGBUILD files
local pkg
local changed_pkgs # list of package names that have a changed PKGBUILD
local left # number of changed packages that have no "fix" yet
changed_pkgs="$(echo "$out" | grep -E "^... b/.*/PKGBUILD$" | sed -E 's|^... b/(.*)/PKGBUILD$|\1|')" # which PKGBUILDs have changed
if [ "$changed_pkgs" ] ; then
left=$(echo "$changed_pkgs" | wc -l)
else
left=0
fi
case "$REPONAME" in
endeavouros-testing-dev)
for pkg in $changed_pkgs ; do
case "$pkg" in
calamares-git)
# Special handling for calamares-git in repo endavouros-testing-dev because its PKGBUILD has line:
# pkgver=.
((left--)) # this is a known thing, we fix it here
if [ "$(echo "$out" | grep "^-pkgver=\.$")" ] ; then # line 'pkgver=.' replaced?
sed -i calamares-git/PKGBUILD -e "s|^pkgver=.*$|pkgver=.|" # set it back to 'pkgver=.' before 'git pull'
PkgAdjusted
fi
;;
# add possible other 'endeavouros-testing-dev' package PKGBUILD management here
esac
done
;;
endeavouros)
for pkg in $changed_pkgs ; do
case "$pkg" in
eos-lightdm-gtk-theme) # the package was copied from ARM, just accept it here
((left--))
PkgAdjusted
;;
# add possible other 'endeavouros' package PKGBUILD management here
esac
done
;;