-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaurch.sh
More file actions
executable file
·1048 lines (921 loc) · 43.7 KB
/
aurch.sh
File metadata and controls
executable file
·1048 lines (921 loc) · 43.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# aurch 2026-02-21
# Dependencies: base-devel pacman-contrib pacutils git jshon mc less
# Optional deps: aurch '-Cc' operation, aurutils to build in clean chroot. Automated install offered upon running '-Cc'
# Optional deps: aurch '-B' operation, optional 'Details of pkg' selection enabled after installing: lua-http lua-dkjson
# Optional: AURFM setup to detect an appropriate file browser in either tty console, or GUI terminal env.
# To print all the variables expanded that are set below, run aurch -Lv.
### Note: "### Safety additions" comments in script refer to additions consisting of:
### 'find' command addition of '-mindepth 1'
### Parameter Expansion Error Checking: :?
### Path Normalization : ./
# shellcheck disable=SC2016 disable=SC2028 disable=SC1012 # Explicitly do not want expansion on 'echo' lines in 'print_vars'.
set -euo pipefail
session=$(tty|awk -F"/" '{print $3}')
AURFM=mc # File browser used for git cloned/pulled repos
[[ -n ${2-} ]] && package="${2,,}" || package="" # Convert <package> input to all lower case
[[ ! -v BASEDIR ]] && BASEDIR=/usr/local/aurch/base # HOST Set BASEDIR to default if unset
[[ ! -v AURREPO ]] && AURREPO=/usr/local/aurch/repo # HOST Set AURREPO to default if unset
[[ ! -v REPONAME ]] && REPONAME=aur # HOST Set REPONAME to default if unset
[[ ! -v CleanChroot ]] && CleanChroot=/var/lib/aurbuild/x86_64/ # Set CleanChroot path if unset
# [[ ${session} == pts ]] && AURFM='thunar &>/dev/null' # Opt Set AURFM for GUI file manager
# CleanChroot=${HOME}/.cache/aurch-chroot # Opt Set CleanChroot path in HOME
chroot="${BASEDIR}"/chroot-$(< "${BASEDIR}"/.#ID) # HOST path to chroot root
chrbuilduser="/home/builduser" # CHROOT builduser home directory (same destination 1)
homebuilduser="${chroot}"/home/builduser # HOST builduser home directory (same destination 1)
tmpc="/var/tmp/aurch" # CHROOT path to tmp dir (same destination 2)
tmph="${chroot}${tmpc}" # HOST path to tmp dir (same destination 2)
logfile=/var/log/aurch.log # Set logfile destination
acp=$(echo -e "\033[1;96m:: aurch ==>\033[00m") # Aurch color pointer
error=$(echo -e "\033[1;91m ERROR:\033[00m") # Red 'ERROR' text
warn=$(echo -e "\033[1;33m WARNING:\033[00m") # Yellow 'WARNING' text
note=$(echo -e "\033[1;92m Note:\033[00m") # Green 'Note' text
dt=$(printf '%s' "[$(date '+%Y-%m-%d %r')]") # Date time in format: [2024-11-23 12:35:22 PM]
prep_line() { line2=$(printf %"$(tput cols)"s | tr " " "-"); } # Set line '---' dynamically to terminal width
if [[ ! -e ${logfile} ]]; then
printf '%s\n' "${acp} First aurch run, '${logfile}' is needed. Creating it now."
sudo touch "${logfile:?}" ; sudo chown "${USER}":"${USER}" "${logfile:?}"
fi
if [[ ! -d /var/tmp/aurch ]]; then
mkdir /var/tmp/aurch
fi
#========================================================================================================================#
: "${session:?}" # Exit script early if any of these variables
: "${AURFM:?}" # are unset or empty. ### Safety additions
: "${BASEDIR:?}"
: "${AURREPO:?}"
: "${REPONAME?}"
: "${CleanChroot:?}"
: "${chroot:?}"
: "${chrbuilduser:?}"
: "${homebuilduser:?}"
: "${tmpc:?}"
: "${tmph:?}"
: "${logfile:?}"
#========================================================================================================================#
print_vars(){
prep_line
local width=$(( $(tput cols) - 6 ))
cat <<-EOF | sudo tee "${BASEDIR}/.#aurch-vars"
package=${package}
BASEDIR=${BASEDIR}
AURREPO=${AURREPO}
REPONAME=${REPONAME}
chroot=${chroot}
chrbuilduser=${chrbuilduser}
homebuilduser=${homebuilduser}
tmpc=${tmpc}
tmph=${tmph}
CleanChroot=${CleanChroot}
logfile=${logfile}
session=${session}
AURFM=${AURFM}
EOF
printf '\n' | sudo tee -a "${BASEDIR}/.#aurch-vars"
cat <<-'EOF' | sudo tee -a "${BASEDIR}/.#aurch-vars"
acp=$(echo -e "\033[1;96m:: aurch ==>\033[00m")
error=$(echo -e "\033[1;91m ERROR:\033[00m")
warn=$(echo -e "\033[1;33m WARNING:\033[00m")
note=$(echo -e "\033[1;92m Note:\033[00m")
dt=$(printf "%s" "[$(date "+%Y-%m-%d %r")]")
line2=$(printf %"$(tput cols)"s |tr " " "-")
EOF
printf '\n%s\n' "Last six lines expanded:"
cat << EOF | awk '{$1=$1};1'
acp=${acp}
error=${error}
warn=${warn}
note=${note}
dt=${dt}
line2=$(printf %"${width}"s | tr " " "-")
EOF
}
#========================================================================================================================#
help(){
prep_line
cat << EOF
${line2}
NAME
aurch - Isolates the host system when building AUR packages from potential errors or malicious content.
DESCRIPTION
Aurch builds AUR packages in an nspawn container implemented for build isolation.
Not to be confused with building packages in a clean chroot. ie: devtools package scripts.
Upon completing AUR builds, aurch places copies of the packages in the host AURREPO directory.
Keeps a copy of AUR packages and dependencies in the nspawn container for future use.
Automatically installs required pgp keys in the nspawn container.
Automatically maintains a set package count in the nspawn container via automated cleanup.
The nspawn container is intended to be reused rather than recreated for each package.
USAGE
aurch [operation[options]] [package | pgp key]
OPERATIONS
-B* --build Build new or update an existing AUR package.
-G --gitclone Git clones AUR package to ${homebuilduser}/<aur-package>.
-C --compile Build an AUR package on existing PKGBUILD. Useful for implementing changes to PKGBUILD.
-Cc* --cchroot Build package in clean chroot using aurutils.
-Rh Remove AUR pkg from host. Removes: ${AURREPO}/<aur-package>, if installed <aur-package> and database entry.
-Rc Remove AUR pkg from container. Removes: /build/<package>, ${chrbuilduser}/<aur-package>, database entry.
-Lah* --lsaurh List all host AUR sync database contents/status.
-Lac* --lsaurc List all container AUR sync database contents/status.
-Luh* --lsudh List update info for AUR packages installed in host.
-Luc* --lsudc List update info for AUR packages/AUR dependencies in container.
-Lv List set variables in console and print to ${BASEDIR}/.#aurch-vars.
-Syu --update Update container system. ie: Runs 'pacman -Syu' inside container.
--login Login to nspawn container for maintenance.
--clean Manually clean up nspawn container and host AUR pkg cache.
--pgp Manually import pgp key into nspawn container.
--log Display '/var/log/aurch.log'.
-h, --help Prints help in 'less' pager. Press [q] to quit. Optionally, pipe into cat: 'aurch -h | cat'
-V, --version Prints aurch <version>.
*OPTIONS
-B, Build:
Append 'i' to build operation '-B' to install package in host.
Example: aurch '-Bi <aurpkg>'
Do not mix order or attempt to use 'i' other than described.
-L, List:
Append 'q' to '-L' list operations for quiet mode.
Example: 'aurch -Lahq'
Do not mix order or attempt to use 'q' other than described.
-Cc, Clean Chroot:
Append 'b' to '-Cc' operation for both host and container(1).
Example: 'aurch -Ccb <aurpkg>'
Do not mix order or attempt to use 'b' other than described.
(1) aurch '-Cc' builds and sets up pkg for host install only.
IE: Use '-Ccb' to copy and register package in both host and
container AUR cache and database.
Usage: Python2 is a dependency of several AUR packages, that must
be built in a clean chroot to successfully pass tests.
Use '-Ccb' to have it available as a prebuilt dependency
in the aurch container when needed.
OVERVIEW
Run aurch-setup before using aurch.
Aurch is designed to handle AUR packages individually, one at a time.
IE: No group updates or multiple packages per operation capability.
The aurch nspawn container must be manually updated 'aurch -Syu'
and pacman cache maintained 'aurch --login' or manually via filesystem.
Best results obtained with container updated before buiding packages.
EXAMPLES
SETUP FOR AURCH:
Set up nspawn container: sudo aurch-setup --setupcontainer
Set up local AUR repo: sudo aurch-setup --setuphost
USING AURCH:
Build an AUR package(+): aurch -B <aur-package>
Build and install AUR package: aurch -Bi <aur-package>
Git clone an AUR package: aurch -G <aur-package>
Compile (build) a git cloned AUR pkg: aurch -C <aur-package>
Remove host AUR package: aurch -Rh <aur-package>
Remove container AUR package: aurch -Rc <aur-package>
List all host AUR packages: aurch -Lah
List all container packages: aurch -Lac
List host updates, AUR packages: aurch -Luh
List container updates, AUR packages: aurch -Luc
pgp key import in container: aurch --pgp <short or long key id>
Clean unneeded packages in container: aurch --clean
Login to container for maintenance: aurch --login
(+) Package is placed into host AUR repo and entry made in pacman AUR database.
Install with 'pacman -S <aur-package>'
VARIABLES
AURFM = AUR file manager,editor Default: AURFM=mc (midnight commander)
Note: Untested, possibly use vifm.
MISC
Aurch runtime messages will be proceeded with this: ${acp}
Aurch runtime warnings will be proceeded with this: ${acp}${warn}
Aurch runtime errors will be proceeded with this: ${acp}${error}
${line2}
EOF
}
#========================================================================================================================#
fetch_pkg(){
rm -f "${tmph}"/rebuilt-pkg.logfile
rm -f "${tmpc}"/cloned-pkgs.logfile
[[ -z ${package} ]] && { printf '%s\n\n' "${acp}${error} Need to specify a package."; exit ; }
is_it_available
if [[ ! -d "${chroot}${tmpc}" ]]; then
sudo systemd-nspawn -a -q -D "${chroot}" --pipe << EOF
mkdir "${tmpc}"
EOF
sudo systemd-nspawn -a -q -D "${chroot}" chmod -R 777 "${tmpc}"
fi
# Deleted bld dir if PKGBUILD NA
if [[ -d "${homebuilduser}/${package}" ]] && [[ ! -s "${homebuilduser}/${package}/PKGBUILD" ]]; then
sudo rm -rd "${homebuilduser:?}/${package:?}" ### Safety additions
fi
if cd "${homebuilduser}/${package}" 2>/dev/null ;then
# 'sudo printf' prevents printed msg before sudo prompt.
if git pull | grep -q 'up to date'; then
sudo printf '%s\n' "${acp} Git repo current, rebuilding...."
printf '%s\n' "Git repo current, rebuilding ${package}." >> "${tmph}"/rebuilt-pkg.logfile
fi
fi
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --chdir="${chrbuilduser}" --pipe << EOF
aur depends -r "${package}" | tsort | aur fetch -S - --results="${tmpc}"/cloned-pkgs.logfile
EOF
if [[ -s ${tmph}/cloned-pkgs.logfile ]]; then
printf '%s\n' "${acp} Git cloned/pulled ${package} and/or it's AUR dependencies in container:"
cut -d'/' -f3- "${tmph}"/cloned-pkgs.logfile | pr -To 13
printf '%s\n' "${acp} Build dir: ${homebuilduser}/${package}"
fi
}
#========================================================================================================================#
is_it_available(){
check=$(curl --compressed -s "https://aur.archlinux.org/rpc?v=5&type=info&arg=${package}" \
| jshon -e results -a -e Name \
| awk -F\" '{print $2}')
if [[ ${package} != "${check}" ]] ; then
printf '%s\n' "${acp}${error}\"${package}\" not available. See: https://aur.archlinux.org/packages/" |& tee -a "${logfile}"
exit 1
fi
}
#========================================================================================================================#
build_pkg(){
# Refresh sudo credentials and keep sudo alive
sudo -v # Long-lived job; use caution using a plain 'wait'.
while true; do sleep 60; sudo -n true; done 2>/dev/null & # Consider 'disown' command for future issues.
SUDO_KEEPALIVE=$!
rm -f "${tmph}"/*.file
find "${AURREPO}"/ -name '*pkg.tar*' 2>/dev/null >"${tmph}"/host-aurrepo-before.file
if [[ ! -d "${homebuilduser}/${package}" ]]; then
printf '%s\n' "${acp}${error} Package build directory missing in container." ; cat <<-EOF | pr -to 5
If running '-C --compile', run '-G --gitclone' first to fetch requirements."
EOF
exit
fi
find "${chroot}"/build/ -name '*pkg.tar*' 2>/dev/null >"${tmph}"/cont-aurrepo-before.file
cd "${homebuilduser}" || { echo "[line ${LINENO}]" ; exit 1 ; }
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --chdir="${chrbuilduser}" --pipe bash << EOF
aur depends -r "${package}" | tsort >"${tmpc}"/buildorder.file
aur depends -n -r "${package}" | tsort | grep -v "^${package}$" >"${tmpc}"/dependencies.file \
|| printf '%s\n' "None" >"${tmpc}"/dependencies.file
EOF
printf '%s\n' "${acp} Buildorder list for ${package}:"
nl -w12 -s" " "${tmph}"/buildorder.file
printf '%s\n' "${acp} AUR dependencies list for ${package}:"
deps=$(< "${tmph}"/dependencies.file)
if [[ ${deps} != "None" ]]; then
nl -w12 -s" " "${tmph}"/dependencies.file
else
pr -To 13 "${tmph}"/dependencies.file
fi
readarray -t -O1 buildorder <"${tmph}"/buildorder.file
depi=$(( ${#buildorder[*]} - 1 ))
pkgi="${#buildorder[*]}"
for dependency in "${buildorder[@]:0:${depi}}"
do
cd "${homebuilduser}/${dependency}" || { echo "[line ${LINENO}]" ; exit 1 ; }
package="${dependency}"
fetch_pgp_key
printf '%s\n' "${acp} Building ${dependency} , a dependency of: ${buildorder[${pkgi}]}"
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --chdir="${chrbuilduser}/${dependency}" --pipe bash << EOF
aur build -fns --margs -C --results=aur-build.log | tee aurch-container-build.log
cut -d '/' -f5 aur-build.log >>"${tmpc}"/total.file
EOF
done
printf '%s\n' "${acp} Building: ${buildorder[${pkgi}]}"
cd "${homebuilduser}/${buildorder[${pkgi}]}" || { echo "[line ${LINENO}]" ; exit 1 ; }
package="${buildorder[${pkgi}]}"
fetch_pgp_key
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --chdir="${chrbuilduser}/${buildorder[pkgi]}" --pipe bash << EOF
aur build -fnsr --margs -C --results=aur-build.log | tee aurch-container-build.log
cut -d '/' -f5 aur-build.log >>"${tmpc}"/total.file
EOF
#------------------------------### Move packages to host, print results ###------------------------------#
find "${chroot}"/build/*pkg.tar* 2>/dev/null >"${tmph}"/cont-aurrepo-after.file
comm -23 <(sort "${tmph}"/cont-aurrepo-after.file) <(sort "${tmph}"/cont-aurrepo-before.file) >"${tmph}"/cont-aurrepo-add.file
for pkg in $(< "${tmph}"/cont-aurrepo-add.file)
do
cp "${pkg}" "${AURREPO}" || { echo "cp err [line ${LINENO}]"; exit 1 ; }
basename "${pkg}" >> "${tmph}"/moved-tohost.file
done
cleanup_chroot
if [[ -s ${tmph}/moved-tohost.file ]] ; then
find "${AURREPO}"/ -name '*pkg.tar*' 2>/dev/null > "${tmph}"/host-aurrepo-after.file
comm -23 <(sort "${tmph}"/host-aurrepo-after.file) <(sort "${tmph}"/host-aurrepo-before.file) >>"${tmph}"/host-added-pkgs.file
upd_aur_db
sudo pacsync "${REPONAME}" >/dev/null
printf '%s\n\n' "${acp} Copied and registered the following pkgs to host AUR repo: ${AURREPO}"
awk -F '-x86|-any' '{print $1}' "${tmph}"/moved-tohost.file | pr -To 13
printf '\n'
else #------------------------------### For rebuilt packages ###------------------------------#
readarray -t movepkgs < "${tmph}"/total.file
if [[ -s "${tmph}"/rebuilt-pkg.logfile ]] && [[ -v movepkgs ]]; then
for package in "${movepkgs[@]}"
do
cp "${chroot}"/build/"${package}" "${AURREPO}"
done
upd_aur_db
sudo pacsync "${REPONAME}" >/dev/null
printf '%s\n\n' "${acp} Copied and registered the following rebuilt pkgs to host AUR repo: ${AURREPO}"
printf '%s\n' "${movepkgs[@]}" | awk -F '-x86|-any' '{print $1}' | pr -To 13
printf '\n' # Note: 'repad-ver.file' created in 'upd_aur_db' funct above.
if [[ -s "${tmph}"/repad-ver.file ]]; then
if ! diff <(sort "${tmph}"/total.file) <(sort "${tmph}"/repad-ver.file); then
printf '%s\n' "${acp}${error} Copy and register packages to host verification failed."
printf '%s\n' "${tmph} /total.file and /repad-ver.file do not match."
fi
fi
fi
fi
#------------------------------### Optionally install package ###------------------------------#
if [[ "${opt-}" == -Bi ]]; then
if [[ -s "${tmph}"/repad-ver.file ]]; then
printf '%s\n' "${acp} Installing in host:"
sudo pacsync "${REPONAME}" & syncpid="$!" ; wait "${syncpid}"
sudo pacman -S - < <(sed -e's/-[0-9].*//g' -e's/-[a-z][0-9].*//g' "${tmph}"/repad-ver.file) ### SC2024 Irrelevant in this case.
else
printf '%s\n' "${acp} Installing ${buildorder[${pkgi}]} in host."
sudo pacsync "${REPONAME}" & syncpid="$!" ; wait "${syncpid}"
sudo pacman -S "${buildorder[${pkgi}]}"
fi
fi
kill "${SUDO_KEEPALIVE}"
}
#========================================================================================================================#
fetch_pgp_key(){
printf '%s\n' "${acp} Checking pgp key for ${package}."
if [[ -e .SRCINFO ]]; then
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --chdir="${chrbuilduser}/${package}" --pipe \
awk '/validpgpkeys/ {print $3}' .SRCINFO >pgp-keys.file ### SC2024: Not ran as sudo. https://github.com/koalaman/shellcheck/issues/2358
else
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --chdir="${chrbuilduser}/${package}" --pipe \
makepkg --printsrcinfo | awk '/validpgpkeys/ {print $3}' >pgp-keys.file
fi
if [[ -s pgp-keys.file ]] ; then
for key in $(< pgp-keys.file); do
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --chdir="${chrbuilduser}/${package}" --pipe bash << EOF
if ! gpg -k "${key}" &>/dev/null ; then
gpg --keyserver hkps://keyserver.ubuntu.com:443 --recv-key "$key" \
|| gpg --keyserver hkps://keys.openpgp.org --recv-key "$key"
else
printf '%s\n' "gpg aurch chroot local key data:"
gpg -k "${key}" |& grep -v 'insecure memory'
fi
EOF
done
else
printf '%s\n' "pgp key not used" | pr -To 13
rm pgp-keys.file
fi
}
#========================================================================================================================#
upd_aur_db(){
if find "${AURREPO}"/*.db.tar.gz &>/dev/null && [[ -s "${tmph}"/host-added-pkgs.file ]]; then
printf '%s\n' "${acp} Adding package/s to host 'AURREPO' database."
udb=alldone
while IFS= read -r pkg; do
repo-add "${AURREPO}"/"${REPONAME}".db.tar.gz "${pkg}"
done < "${tmph}"/host-added-pkgs.file
fi
if [[ ${udb-} == alldone ]]; then
return
else
if find "${AURREPO}"/*.db.tar.gz &>/dev/null && [[ -s "${tmph}"/rebuilt-pkg.logfile ]]; then
printf '%s\n' "${acp} Adding package/s to host 'AURREPO' database"
while IFS= read -r pkg; do
repo-add --nocolor "${AURREPO}"/"${REPONAME}".db.tar.gz "${AURREPO}"/"${pkg}" \
| tee >(awk -F/ '/Adding package/{print $NF}'|sed -e "s/'//g" >> "${tmph}"/repad-ver.file)
done < "${tmph}"/total.file
fi
fi
}
#========================================================================================================================#
remove(){
# Note: pkg variable is set in option parsing.
if [[ -n ${pkg} ]]; then
if [[ ${1} == -Rc ]]; then
if pacman -b "${chroot}/var/lib/pacman/" \
--config "${chroot}/etc/pacman.conf" \
-Slq aur \
| grep -q "${pkg}"; then
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --pipe bash << EOF
printf '%s\n' "${acp} Removing ${pkg} from container aur database."
repo-remove /build/aur.db.tar.gz "${pkg}"
EOF
printf '%s\n' "${acp} Removing from container aur package cache:"
### find "${chroot}"/build -name "${pkg}*.pkg.tar*" -delete -print ### Safety additions
find "${chroot:?}/build/./" -mindepth 1 -name "${pkg:?}*.pkg.tar*" -delete -print
if [[ -d "${homebuilduser}"/"${pkg}" ]]; then
printf '%s\n' "${acp} Removing container build directory:"
printf '%s\n' "${chrbuilduser}/${pkg}"
sudo rm -rd "${homebuilduser:?}/${pkg:?}" ### Safety additions
fi
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --pipe bash << EOF
printf '%s\n' "${acp} Syncing container aur database:"
sudo 2>/dev/null pacsync aur
EOF
else
printf '%s\n' "${acp} ${pkg} not present in container AUR database."
if [[ -d "${homebuilduser}"/"${pkg}" ]]; then
printf '%s\n' "${acp} Removing container build directory:"
printf '%s\n' "${chrbuilduser}/${pkg}"
sudo rm -rd "${homebuilduser:?}/${pkg:?}" ### Safety additions
cd "${chroot}"/build/
if find "${pkg}*.pkg.tar*" &>/dev/null; then
printf '%s\n' "${acp} Removing from container aur package cache:"
### find "${chroot}"/build/ -name "${pkg}*.pkg.tar*" -delete -print ### Safety additions
find "${chroot:?}/build/./" -mindepth 1 -name "${pkg:?}*.pkg.tar*" -delete -print
else
printf '%s\n' "${acp} Container ${pkg} not present in AUR package cache."
fi
else
printf '%s\n' "${acp} Container ${pkg} build directory not present."
fi
fi
fi
if [[ ${1} == -Rh ]]; then
if pacman -Q "${pkg}" &>/dev/null ; then
sudo pacman -Rns "${pkg}"
fi
printf '%s\n' "${acp} Removing pkg from host ${REPONAME} package cache:"
### sudo find "${AURREPO}" -name "${pkg}*.pkg.tar*" -delete -print ### Safety additions
sudo find "${AURREPO:?}/./" -mindepth 1 -name "${pkg:?}*.pkg.tar*" -delete -print
if pacman -Slq "${REPONAME}" | grep -q "${pkg}"; then
repo-remove "${AURREPO}"/"${REPONAME}".db.tar.gz "${pkg}"
sudo pacsync "${REPONAME}" >/dev/null
else
printf '%s\n' "${acp} Package ${pkg} is not present in host AUR repo."
fi
fi
else
printf '%s\n\n' "${acp} Need to specify package."
fi
}
#========================================================================================================================#
check_chroot_updates(){
cd "${homebuilduser}" || { echo "[line ${LINENO}]" ; exit 1 ; }
rm -f /tmp/check-ud-updates
readarray -t dirs < <(find "${homebuilduser}" -maxdepth 1 -mindepth 1 -type d -name "[!.]*" -printf '%f\n'|sort)
if [[ $1 != -Lucq ]]; then
printf '%s\n' "${acp} Checking for updates on:"
printf '%s\n' "${dirs[@]}" | nl
printf '%s' "${acp} Checking " # start progress line
fi
# update progress
max_jobs=2 # max_jobs=5 # limit parallel jobs
running=0 # track running jobs
tmpdir=$(mktemp -d) # per-job temp directory
progress_counter=0 # progress mark counter
progress_wrap=50 # wrap progress line every N marks
trap 'rm -rf "$tmpdir"' EXIT
for pkg in "${dirs[@]}"
do
( # start run in backgrounded subshell
cd "${homebuilduser}/${pkg}" || { echo "[line ${LINENO}]" ; exit 1 ; }
if [[ -d .git ]]; then
localHEAD=$(git rev-parse HEAD)
remoteHEAD=$(git ls-remote --symref -q | head -1 | cut -f1) # fetch remote
if [[ ${localHEAD} != "${remoteHEAD}" ]]; then
jobfile=$(mktemp "${tmpdir}/update.XXXXXX") # unique temp file per job
printf '%s\n' " ${pkg}" > "$jobfile" # write package name safely
fi
fi
if [[ $1 != -Lucq ]]; then
printf '#' >&2 # print progress bar '#' to stderr
fi
) &
running=$((running + 1))
# end run in backgrounded subshell
if (( running >= max_jobs )); then
wait -n # wait for one job to finish
running=$((running - 1)) # subtract one running job
fi
if [[ $1 != -Lucq ]]; then # wrap progress line every N marks
progress_counter=$((progress_counter + 1))
if (( progress_counter % progress_wrap == 0 )); then
printf '\n' >&2
fi
fi
done
wait # wait for all jobs
if [[ $1 != -Lucq ]]; then # ensure final newline after progress bar
printf '\n' >&2
fi
readarray -t update_files < <(find "${tmpdir}" -maxdepth 1 -type f -name 'update.*')
if (( ${#update_files[@]} > 0 )); then # No updates, 'set -e' safe from exiting
cat "${update_files[@]}" >> "${tmpdir}"/check-ud-updates
fi
if [[ -s "${tmpdir}"/check-ud-updates ]]; then
if [[ $1 != -Lucq ]]; then
echo >> "${tmpdir}"/check-ud-updates
printf '%s\n' "${acp} Updates available:"
fi
cat "${tmpdir}/check-ud-updates"
else
if [[ $1 != -Lucq ]]; then
printf '%s\n' "${acp} No updates available."
fi
fi
}
#========================================================================================================================#
check_host_updates(){
rm -f /tmp/aurch-updates /tmp/aurch-updates-newer /tmp/aur-ck_list
declare -A local_aur
# Create associative array of installed '[pkg] ver'
while read -r name ver; do
local_aur[$name]="${ver}"
done < <(pacman --color=never -Slq aur | \
pacman -Q - 2>/dev/null; pacman --color=never -Qm 2>/dev/null)
pkg_names=("${!local_aur[@]}")
max_size=100
count="${#pkg_names[@]}"
declare -A rem_aur
# Be polite with the AUR RPC via a batch requests
for (( i=0; i<count; i+=max_size )); do # for i in $(seq 0 "${max_size}" $((count - 1))); do
current_query=("${pkg_names[@]:i:max_size}")
rpc_query=$(printf "&arg[]=%s" "${current_query[@]}")
# Make AUR rpc request, save reply as var
if ! response=$(curl -f -s "https://aur.archlinux.org/rpc?v=5&type=info${rpc_query}"); then
printf '\n%s\n\n' "${error} AUR RPC reply failure."
return 1 # Include graceful exit upon failed curl command.
fi
# Create associative array of AUR '[pkg] ver'
while read -r name ver; do
[[ -z "$name" ]] && continue
rem_aur[$name]="$ver"
done < <(jshon -e results -a -e Name -u -p -e Version -u <<< "$response" | paste -d ' ' - -)
done
for key in "${!rem_aur[@]}"; do
printf '%-30s %s\n' "$key" "${local_aur[$key]}" >> /tmp/aur-ck_list
done
# Version Comparison
for pkg in "${!rem_aur[@]}"; do
# Use RPC filtered 'rem_aur' pkg list
compare=$(vercmp "${local_aur[$pkg]}" "${rem_aur[$pkg]}")
# Send version compare results to file
if [[ ${compare} == -1 ]]; then
printf '%s\n' "${pkg} ${local_aur[$pkg]} -> ${rem_aur[$pkg]}" >>/tmp/aurch-updates
elif [[ ${compare} == 1 ]]; then
printf '%s\n' "${pkg} ${local_aur[$pkg]} <- ${rem_aur[$pkg]}" >>/tmp/aurch-updates-newer
fi
done
if [[ $1 == -Luhq ]]; then
[[ -f /tmp/aurch-updates ]] && awk '{print $1}' /tmp/aurch-updates
exit
fi
printf '\n%s\n' "${acp} Checking the following pkgs for updates." # Print list of 'pkgs ver' to be checked
sleep 1
column -t /tmp/aur-ck_list |sort | nl -w 3
if [[ -s /tmp/aurch-updates ]]; then # Print results
printf '\n%s\n' "${acp} Updates available:"
column -t /tmp/aurch-updates | sort
else
printf '\n%s\n' "${acp} No Updates available"
fi
if [[ -s /tmp/aurch-updates-newer ]]; then
printf '\n%s\n' "${acp} VCS Packages newer than AUR rpc version. Run 'aurch -Luc' to check them for updates."
column -t /tmp/aurch-updates-newer | sort
echo
fi
}
#========================================================================================================================#
list_pkgs_host(){
sudo pacsync "${REPONAME}" >/dev/null
if [[ ${1} == -Lahq ]]; then
pacman --color=always -Slq "${REPONAME}"
else
pacman --color=always -Sl "${REPONAME}" | awk '{$1="" ; print}' | nl | column -t
fi
}
#========================================================================================================================#
list_pkgs_chroot(){
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --pipe sudo 2>/dev/null pacsync aur
# sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --pipe sudo pacsync aur
if [[ ${1} == -Lacq ]]; then
pacman --color=always -b "${chroot}/var/lib/pacman/" --config "${chroot}/etc/pacman.conf" --noconfirm -Slq aur
else
pacman --color=always -b "${chroot}/var/lib/pacman/" --config "${chroot}/etc/pacman.conf" --noconfirm -Sl aur \
| awk '{$1="" ; print}' | nl | column -t
fi
}
#========================================================================================================================#
update_chroot(){
sudo systemd-nspawn -a -q -D "${chroot}" --pipe pacman -Syu
}
#========================================================================================================================#
login_chroot(){
sudo systemd-nspawn --background=0 -a -q -D "${chroot}" su root
}
#========================================================================================================================#
manual_pgp_key(){
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --pipe \
gpg --keyserver keyserver.ubuntu.com --recv-key "${key}"
exit
}
#========================================================================================================================#
yes_no(){
while true; do
local dpdd=no
local Dop="Details of pkg"
local If="Inspect files"
local Bp="Build pkg"
printf '\n%s\n' "${acp} ${Dop} | ${If}* | ${Bp}* (*)= Git cloned/pulled package/s listed above."
if command -v pbs.lua >/dev/null && pacman -Qi lua-http lua-dkjson >/dev/null; then
local dpdd=yes
fi
if [[ ${dpdd} == yes ]]; then
local det='Details [d] ' sel=' Enter [d/i/b]:'
else
local det='Not Available' sel=' Enter [i/b]:'
fi
printf '%s\n' "${acp} ${det} | Inspect [i] | Build [b]"
read -n1 -rp " ${sel}
" dib
tput ind
case $dib in
[Dd]* ) printf '%s\n' "${acp} ${Dop}:" ; [[ ${dpdd} == yes ]] && pbs.lua "${package}" ;;
[Ii]* ) printf '%s\n\n' "${acp} ${If}:" ; inspect_files "${1-}" ;;
[Bb]* ) printf '%s\n\n' "${acp} ${Bp}:" ; opt="${1-}" ; build_pkg ; break ;;
* ) printf '%s\n' "${acp}${error}${sel} -or- [Ctrl]+[c] to exit." ;;
esac
done
}
#========================================================================================================================#
inspect_files(){
awk -F/ '{print $NF}' "${tmph}"/cloned-pkgs.logfile >"${tmph}"/inspect_files.file
if [[ -s ${tmph}/inspect_files.file ]]; then
while IFS= read -r pkg; do
dbus-run-session -- "${AURFM}" "${homebuilduser}"/"${pkg}" 2>/dev/null
done < "${tmph}"/inspect_files.file
else
dbus-run-session -- "${AURFM}" "${homebuilduser}"/"${package}" 2>/dev/null
fi
}
#===================================================================================# # aurch -Cc*' Depends : aurutils paccat devtools
### C L E A N C H R O O T B U I L D ### # aurutils scripts : aur-build, aur-chroot use: -->
# devtools scripts : checkpkg mkarchroot arch-nspawn
build_clean_chroot(){
### BUG FIX ###
### Prevent nspawn builduser dir deletion on "no pkg" entered. ###
if [[ -z $package ]]; then
printf '\n%s\n\n' "${acp}${error} Need to provide an AUR package name.
ie: aurch -Cc <pkg name>"
exit
fi
is_it_available
printf '\n%s\n' "${acp}${warn} Informing as a courtesy:" ; cat <<-EOF | pr -to 5
Clean chroot adds, then removes a sudo config file '/etc/sudoers.d/aurch-sudo' as a convenience workaround.
Review the code in 'build_clean_chroot' function and the contents of '/etc/sudoers.d/' before proceeding.
EOF
while read -n1 -srp " Proceed? [y/n] " reply
do
if [[ ${reply} == y ]]; then printf "yes" ; echo ; break ; fi
if [[ ${reply} == n ]]; then printf "no" ; echo ; exit ; fi
unset reply
done
if [[ ! -d ${CleanChroot}/root ]]; then
printf '%s\n' "${acp} First run clean chroot setup required...."
fi
# Check for deps, confirm to install
if ! type -P aur bash paccat checkpkg mkarchroot arch-nspawn &>/dev/null ; then
printf '%s\n' "${acp} Clean chroot building dependencies not installed. Installing now."
while read -n1 -srp " Proceed? [y/n] " reply
do
if [[ ${reply} == y ]]; then printf "yes"
printf '\n'
if pacman -Ssq aurutils &>/dev/null ; then
sudo pacman -S --noconfirm aurutils paccat devtools
pacman -Q --color=always aurutils paccat devtools | column -t
printf '\n%s\n\n' "${acp} Dependencies installed. Proceeding with setting up clean chroot....."
sleep 4
else
moveit=$(find "${chroot}"/build/ -name 'aurutils*')
# Fetch containers aurutils
if [[ -n ${moveit} ]]; then
cp "${moveit}" "${AURREPO}"
repo-add "${AURREPO}"/"${REPONAME}".db.tar.gz "${moveit}"
sudo pacsync aur
fi
sudo pacman -S --noconfirm aurutils paccat devtools
pacman -Q --color=always aurutils paccat devtools | column -t
printf '\n%s\n\n' "${acp} Dependencies installed. Proceeding with setting up clean chroot....."
sleep 4
fi
break
fi
if [[ ${reply} == n ]]; then printf "no"
echo
printf '%s\n' " Exiting script."
exit
fi
unset reply
done
else
printf '%s\n' "${acp} $(pacman -Q --color=always aurutils) and all other dependencies installed."
fi # Create log dir if needed
#----------------------------------------- M A K E A U R - C H R O O T ---------------------------# # Create clean chroot if needed
if [[ ! -d ${CleanChroot}/root ]]; then
sudo paccat pacman -- pacman.conf | sudo tee /etc/aurutils/pacman-x86_64.conf &>/dev/null
sudo paccat pacman -- makepkg.conf | sudo tee /etc/aurutils/makepkg-x86_64.conf &>/dev/null
sudo sed -i 's/#ParallelDownloads = 5/ParallelDownloads = 5/g' /etc/aurutils/pacman-x86_64.conf
sudo sed -i 's/ debug / !debug /g' /etc/aurutils/makepkg-x86_64.conf
aur chroot --create -D "${CleanChroot}"
if ! grep -q 'aurch' /etc/aurutils/pacman-x86_64.conf ; then
# Config shared local AUR repo/cache
cat <<-EOF | sudo tee -a /etc/aurutils/pacman-x86_64.conf &>/dev/null
#
# aurch config for 'aur build'.
#
[options]
CacheDir = /usr/local/aurch/repo
CleanMethod = KeepInstalled
[aur]
SigLevel = Never TrustAll
Server = file:///usr/local/aurch/repo
EOF
printf '\n%s\n' "${acp} Configured '/etc/aurutils/pacman-x86_64.conf' to share aurch local AUR repo."
printf '%s\n\n' "${acp} Clean chroot environment set up completed. Start building pkg....."
sleep 3
fi
fi
#----------------------------------------- S T A R T B U I L D ---------------------------------# # Remove any existing log files
rm -f /var/tmp/aurch/*
cd "${homebuilduser}"
### BUG FIX FAILSAFE ###
### Prevents builduser dir deletion on "no pkg" entered. ###
: "${package:?}"
### Safety additions
[[ -d "${homebuilduser}/${package}" ]] && sudo rm -rd "${homebuilduser:?}/${package:?}"
aur depends -r "${package}" | tsort |
tee /var/tmp/aurch/cloned-pkgs.log |
aur fetch -S -
printf '%s\n' "${acp} Git cloned ${package} and AUR dependencies."
pr -To 13 /var/tmp/aurch/cloned-pkgs.log
if [[ ! -d ${HOME}/.gnupg/ ]]; then
gpg --list-keys &>/dev/null
fi
while read -n1 -srp "${acp} Inspect git cloned files? [y/n] " reply
do
if [[ ${reply} == y ]]; then printf "yes" ; dbus-run-session -- "${AURFM}" "${homebuilduser}"/"${package}" ; break ; fi
if [[ ${reply} == n ]]; then printf "no" ; echo && break ; fi
unset reply
done
# Beginning build packages in cloned-pkgs.log
while read -r build
do
cd "${homebuilduser}/${build}" || exit
awk '/validpgpkeys/ {print $3}' .SRCINFO >pgp-keys.file
printf '%s\n' "${acp} Checking pgp keys."
# Check/install pgp keys
if [[ ! -s pgp-keys.file ]]; then
printf '%s\n' " Not used for ${build}."
else
while read -r key
do
gpg --keyserver hkps://keyserver.ubuntu.com:443 --recv-key "$key" \
|| gpg --keyserver hkps://keys.openpgp.org --recv-key "$key"
done < pgp-keys.file
fi
# Fix successive pacman sudo prompts
printf '%s\n' "${USER} ALL=(ALL) NOPASSWD: /usr/bin/pacman" |
sudo tee /etc/sudoers.d/aurch-sudo &>/dev/null
printf '%s\n' "${acp} Checking clean chroot '${CleanChroot}/root' for updates."
aur chroot -U -D "${CleanChroot}" # Check clean chroot for updates
printf '%s\n' "${acp} Building ${build} in clean chroot."
# BUILD INDIVIDUAL CHROOT PACKAGES
aur build -cfnsr --results=aur-build.log --cargs="-c,-u,-r${CleanChroot}"
# Remove sudo config and restore permissions
### Safety additions
sudo rm /etc/sudoers.d/./aurch-sudo
awk -F'/' '{print $NF}' aur-build.log >> /var/tmp/aurch/aurch-build.log
done < /var/tmp/aurch/cloned-pkgs.log
cleanup_host
# If 'b' option, copy/register pkgs to cont.
if [[ ${1} == -Ccb ]]; then
while read -r transfer
do
cp "${AURREPO}/${transfer}" "${chroot}/build/"
sudo systemd-nspawn -a -q -D "${chroot}" -u builduser --pipe bash << EOF
repo-add /build/"${REPONAME}".db.tar.gz /build/"${transfer}"
sudo 2>/dev/null pacsync aur
EOF
done < /var/tmp/aurch/aurch-build.log
fi
printf '%s\n' "${acp} Clean chroot build location: $(aur chroot --path | sed "s/root/${USER}/g")"
printf '%s\n' "${acp} Copied and registered the following pkgs to host AUR repo: ${AURREPO}"
if [[ ${1} == -Ccb ]]; then
printf '%s\n' "${acp} Copied and registered the following pkgs to container AUR repo: ${chroot}/build"
fi
echo # Print build results to screen
awk -F'/' '{print $NF}' /var/tmp/aurch/aurch-build.log | nl -w3 -s" " | pr -To 11
echo
}
#========================================================================================================================#
cleanup_chroot(){ # REMINDER: Change both dates below if heredoc script is modified.
if [[ ! -e ${tmph}/orig-pkgs.log ]]; then
awk '{print $2}' "${BASEDIR}"/.#orig-pkgs.log | sort >"${tmph}"/orig-pkgs.log
fi
sudo rm -f /etc/sudoers.d/./aurch-sudo # Added so 'trap' will remove 'aurch-sudo' file if
### Safety additions
# 'build_clean_chroot' function is interrupted.
printf '%s\n' "${acp} Cleaning aurch nspawn container."
if [[ $(grep '^#202*' 2>/dev/null "${chroot}"/bin/aurch-cleanup) != '#2025-07-25' ]]; then
printf '%s\n' "${acp}${note} Updating container 'aurch-cleanup' script."
# Install cleanup script in container if needed
#---------------------------------------------- START Heredoc Script -----------------------------------------#
cat << "EOF" | sudo tee "${chroot}"/usr/bin/aurch-cleanup &>/dev/null
#!/bin/bash
#2025-07-25
acp=$(echo -e '\033[1;96m'":: aurch ==>"'\033[00m')
pacman -S --noconfirm pacman-contrib 1>/dev/null
printf '%s\n' "${acp} Paccache output from cleaning both container package caches:"
paccache -v --cachedir /var/cache/pacman/pkg/ --remove --keep 0 | awk 'NF' | grep -v '==>'
paccache -v --cachedir /build/ --remove --keep 1 | awk 'NF' | grep -v '==>'
printf '%s\n' "Note: 'pacman-contrib' was '--clean' requirement."
printf '%s\n' "${acp} Pacman output from container: "
comm -23 <(pacman -Qq) <(sort /var/tmp/aurch/orig-pkgs.log) | xargs pacman -Rns --noconfirm 2>/dev/null
### find /build /var/cache/pacman/pkg -maxdepth 1 -type d -name "download-*" -exec sudo rm -rd "{}" + ### Safety additions
find /build/ /var/cache/pacman/pkg/ -mindepth 1 -maxdepth 1 -type d -name "download-*" -exec sudo rm -rf -- "{}" +
pkgcount=$(pacman -Qq | wc -l)
aurcache=$(find /build -maxdepth 1 -type f -name "*pkg.tar*" | wc -l)
printf '%s\n' "${acp} Container clean report :"
printf '%s\n' " Official pkg cache count : $(ls -1 /var/cache/pacman/pkg | wc -l)"
printf '%s\n' " AUR pkg cache count : ${aurcache}"
printf '%s\n\n' " Installed package count : ${pkgcount}"
EOF
#---------------------------------------------- END Heredoc Script --------------------------------------# # Run cleanup script in container
sudo chmod +x "${chroot}"/usr/bin/aurch-cleanup
fi
if [[ -e ${tmph}/orig-pkgs.log ]]; then
sudo systemd-nspawn -a -q -D "${chroot}" --pipe \
/usr/bin/aurch-cleanup
fi
sudo rm "${tmph:?}/orig-pkgs.log" ### Safety additions
}
#========================================================================================================================#
cleanup_host(){
sudo true
sudo rm -f /etc/sudoers.d/./aurch-sudo # Added so 'trap' will remove 'aurch-sudo' file if
### Safety additions
# 'build_clean_chroot' function is interrupted.
printf '%s\n' "${acp} Cleaning official packages from local AUR cache: "
aurch -Lahq > /var/tmp/aurch/aurch-keeppkgs
aurch -Lacq >> /var/tmp/aurch/aurch-keeppkgs
keeppkgs=$(sort -u /var/tmp/aurch/aurch-keeppkgs | grep -v 'aur.db' | xargs | sed 's/ /,/g')
sudo paccache -v -rk0 -i "${keeppkgs}" -c /usr/local/aurch/repo/ |& awk NF
printf '%s\n' "${acp} Cleaning leftover directories from local AUR cache:"
### find "${AURREPO}" -maxdepth 1 -type d -name "download-*" -exec sudo rm -rd "{}" + ### Safety additions
find "${AURREPO:?}/./" -mindepth 1 -maxdepth 1 -type d -name "download-*" -exec sudo rm -rf -- "{}" +
printf '%s\n' "==> no directories list indicate nothing to remove"
}
#=======================================### Aurch called with no args ###================================================#
if [[ -z ${*} ]]; then
printf '\033[0;96m'
cat << EOF
╔══════════════════════════════════════════════════════════════════════════════════╗
║ Aurch, an AUR helper script. USAGE: $ aurch [operation[*opt]] [package] ║
╟─────────────────────────────────────────┬────────────────────────────────────────╢
║ -B* build AUR package in container │ -Luc* list updates container ║
║ -G git clone package │ -Luh* list updates host ║
║ -C build on existing git clone │ -Lac* list AUR sync db container ║
║ -Cc* build AUR pkg in clean chroot │ -Lah* list AUR sync db host ║
║ -Rc remove AUR pkg from container │ -Lv list expanded variables ║
║ -Rh remove AUR pkg from host │ --pgp import pgp key in container ║
║ -Syu update container │ --clean cleanup host & container ║
║ -V print version │ --login log into container ║
║ -h help, Press [q] to quit │ --log display aurch.log ║