forked from keenerd/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packer
804 lines (727 loc) · 23.7 KB
/
packer
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
#!/bin/bash
# Copyright Matthew Bruenig <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
[[ $PACMAN ]] || PACMAN="pacman"
# set tmpfile stuff, clean tmpdir
tmpdir="${TMPDIR:-/tmp}/packertmp-$UID"
rm -rf "$tmpdir" &>/dev/null
mkdir -p "$tmpdir"
makepkgconf='/etc/makepkg.conf'
usermakepkgconf="$HOME/.makepkg.conf"
pacmanconf='/etc/pacman.conf'
RPCURL="https://aur.archlinux.org/rpc.php?type"
PKGURL="https://aur.archlinux.org"
if [[ -t 1 && ! $COLOR = "NO" ]]; then
COLOR1='\e[1;39m'
COLOR2='\e[1;32m'
COLOR3='\e[1;35m'
COLOR4='\e[1;36m'
COLOR5='\e[1;34m'
COLOR6='\e[1;33m'
COLOR7='\e[1;31m'
ENDCOLOR='\e[0m'
S='\\'
fi
_WIDTH="$(stty size | cut -d ' ' -f 2)"
trap ctrlc INT
ctrlc() {
echo
exit
}
err() {
echo -e "$1"
exit 1
}
usage() {
echo 'usage: packer [option] [package] [package] [...]'
echo
echo ' -S - installs package'
echo ' -Syu|-Su - updates all packages, also takes -uu and -yy options'
echo ' -Ss|-Ssq - searches for package'
echo ' -Si - outputs info for package'
echo ' -G - download and extract aur tarball only'
echo
echo ' --quiet - only output package name for searches'
echo ' --ignore - takes a comma-separated list of packages to ignore'
echo ' --noconfirm - do not prompt for any confirmation'
echo ' --noedit - do not prompt to edit files'
echo ' --quickcheck - check for updates and exit'
echo ' --auronly - only do actions for aur'
echo ' --devel - update devel packages during -Su'
echo ' --skipinteg - when using makepkg, do not check md5s'
echo ' --preview - edit pkgbuild before sourcing'
echo ' -h - outputs this message'
exit
}
# Called whenever anything needs to be run as root ($@ is the command)
runasroot() {
if [[ $UID -eq 0 ]]; then
"$@"
elif sudo -v &>/dev/null && sudo -l "$@" &>/dev/null; then
sudo -E "$@"
else
echo -n "root "
su -c "$(printf '%q ' "$@")"
fi
}
# Source makepkg.conf file
sourcemakepkgconf() {
. "$makepkgconf"
[[ -r "$usermakepkgconf" ]] && . "$usermakepkgconf"
}
# Parse IgnorePkg and --ignore, put in globally accessible ignoredpackages array
getignoredpackages() {
IFS=',' read -ra ignoredpackages <<< "$ignorearg"
ignoredpackages+=( $(grep '^ *IgnorePkg' "$pacmanconf" | cut -d '=' -f 2-) )
}
# Checks to see if $1 is an ignored package
isignored() {
[[ " ${ignoredpackages[@]} " =~ " $1 " ]]
}
# Tests whether $1 exists on the aur
existsinaur() {
rpcinfo "$1"
[[ "$(jshon -Qe resultcount -u < "$tmpdir/$1.info")" != "0" ]]
}
# Tests whether $1 exists in pacman
existsinpacman() {
pacman -Si -- "$1" &>/dev/null
}
# Tests whether $1 is provided in pacman, sets globally accessibly providepkg var
providedinpacman() {
unset providepkg
IFS=$'\n' read -rd '' -a providepkg < <(pacman -Ssq -- "^$1$")
[[ -n $providepkg ]]
}
# Tests whether $1 exists in a pacman group
existsinpacmangroup() {
[[ $(pacman -Sgq "$1") ]]
}
# Tests whether $1 exists locally
existsinlocal() {
pacman -Qq -- "$1" &>/dev/null
}
# Scrapes the aur deps from PKGBUILDS and puts in globally available dependencies array
scrapeaurdeps() {
pkginfo "$1" "$preview"
. "$tmpdir/$1.PKGBUILD"
IFS=$'\n'
dependencies=( $(echo -e "${depends[*]}\n${makedepends[*]}" | sed -e 's/=.*//' -e 's/>.*//' -e 's/<.*//'| sort -u) )
unset IFS
}
# Finds dependencies of package $1
# Sets pacmandeps and aurdeps array, which can be accessed globally after function runs
finddeps() {
# loop through dependencies, if not installed, determine if pacman or aur deps
pacmandeps=()
aurdeps=()
scrapeaurdeps "$1"
missingdeps=( $(pacman -T "${dependencies[@]}") )
while [[ $missingdeps ]]; do
checkdeps=()
for dep in "${missingdeps[@]}"; do
if [[ " $1 ${aurdeps[@]} ${pacmandeps[@]} " =~ " $dep " ]]; then
continue
fi
if existsinpacman "$dep"; then
pacmandeps+=("$dep")
elif existsinaur "$dep"; then
if [[ $aurdeps ]]; then
aurdeps=("$dep" "${aurdeps[@]}")
else
aurdeps=("$dep")
fi
checkdeps+=("$dep")
elif providedinpacman "$dep"; then
pacmandeps+=("$providepkg")
else
[[ $option = "install" ]] && err "Dependency \`$dep' of \`$1' does not exist."
echo "Dependency \`$dep' of \`$1' does not exist."
return 1
fi
done
missingdeps=()
for dep in "${checkdeps[@]}"; do
scrapeaurdeps "$dep"
for depdep in "${dependencies[@]}"; do
[[ $(pacman -T "$depdep") ]] && missingdeps+=("$depdep")
done
done
done
return 0
}
# Displays a progress bar ($1 is numerator, $2 is denominator, $3 is candy/normal)
aurbar() {
# Delete line
printf "\033[0G"
# Get vars for output
beginline=" aur"
beginbar="["
endbar="] "
perc="$(($1*100/$2))"
width="$(stty size)"
width="${width##* }"
charsbefore="$((${#beginline}+${#1}+${#2}+${#beginbar}+3))"
spaces="$((51-$charsbefore))"
barchars="$(($width-51-7))"
hashes="$(($barchars*$perc/100))"
dashes="$(($barchars-$hashes))"
# Print output
printf "$beginline %${spaces}s$1 $2 ${beginbar}" ""
# ILoveCandy
if [[ $3 = candy ]]; then
for ((n=1; n<$hashes; n++)); do
if (( (n==($hashes-1)) && ($dashes!=0) )); then
(($n%2==0)) && printf "\e[1;33mc\e[0m" || printf "\e[1;33mC\e[0m"
else
printf "-"
fi
done
for ((n=1; n<$dashes; n++)); do
N=$(( $n+$hashes ))
(($hashes>0)) && N=$(($N-1))
(($N%3==0)) && printf "o" || printf " "
done
else
for ((n=0; n<$hashes; n++)); do
printf "#"
done
for ((n=0; n<$dashes; n++)); do
printf "-"
done
fi
printf "%s%3s%%\r" ${endbar} ${perc}
}
rpcinfo() {
if ! [[ -f "$tmpdir/$1.info" ]]; then
curl -LfGs --data-urlencode "arg=$1" "$RPCURL=info" > "$tmpdir/$1.info"
fi
}
pkglink() {
rpcinfo $1
echo "${PKGURL}$(jshon -Q -e results -e URLPath -u < "$tmpdir/$1.info")"
}
# downloads pkgbuild ($1), edits if $2 is set
pkginfo() {
if ! [[ -f "$tmpdir/$1.PKGBUILD" ]]; then
pkgpath=$(pkglink $1)
curl -Lfs "${pkgpath%/*}/PKGBUILD" > "$tmpdir/$1.PKGBUILD"
if [[ $2 ]]; then
# rename for syntax highlighting
cp "$tmpdir/$1.PKGBUILD" "$tmpdir/PKGBUILD"
confirm_edit "${COLOR6}Edit $1 PKGBUILD with \$EDITOR? [Y/n]${ENDCOLOR} " "$tmpdir/PKGBUILD"
mv "$tmpdir/PKGBUILD" "$tmpdir/$1.PKGBUILD"
fi
fi
}
# Checks if package is newer on aur ($1 is package name, $2 is local version)
aurversionisnewer() {
rpcinfo "$1"
unset aurversion
if existsinaur "$1"; then
aurversion="$(jshon -Q -e results -e Version -u < "$tmpdir/$1.info")"
if [[ "$(LC_ALL=C vercmp "$aurversion" "$2")" -gt 0 ]]; then
return 0
fi
fi
return 1
}
isoutofdate() {
rpcinfo "$1"
[[ "$(jshon -Q -e results -e OutOfDate -u < "$tmpdir/$1.info")" = "1" ]]
}
# $1 is prompt, $2 is file
confirm_edit() {
if [[ (! -f "$2") || "$noconfirm" || "$noedit" ]]; then
return
fi
echo -en "$1"
if proceed; then
${EDITOR:-vi} "$2"
fi
}
# Installs packages from aur ($1 is package, $2 is dependency or explicit)
aurinstall() {
dir="${TMPDIR:-/tmp}/packerbuild-$UID/$1"
sourcemakepkgconf
# Prepare the installation directory
# If there is an old directory and aurversion is not newer, use old directory
if . "$dir/$1/PKGBUILD" &>/dev/null && ! aurversionisnewer "$1" "$pkgver-$pkgrel"; then
cd "$dir/$1"
else
[[ -d "$dir" ]] && rm -rf "$dir"
mkdir -p "$dir"
cd "$dir"
curl -Lfs "$(pkglink $1)" > "$1.tar.gz"
mkdir "$1"
tar xf "$1.tar.gz" -C "$1" --strip-components=1
cd "$1"
if [[ $preview && -s "$tmpdir/$1.PKGBUILD" ]]; then
cp "$tmpdir/$1.PKGBUILD" PKGBUILD
fi
# customizepkg
if [[ -f "/etc/customizepkg.d/$1" ]] && type -t customizepkg &>/dev/null; then
echo "Applying customizepkg instructions..."
customizepkg --modify
fi
fi
# check for missing arch
if [[ ! " ${arch[@]} " =~ " any " ]]; then
if [[ ! " ${arch[@]} " =~ " ${CARCH} " ]]; then
echo -e "${COLOR6}warning:$ENDCOLOR $CARCH missing from arch array"
fi
fi
# Allow user to edit PKGBUILD
confirm_edit "${COLOR6}Edit $1 PKGBUILD with \$EDITOR? [Y/n]${ENDCOLOR} " PKGBUILD
if ! [[ -f PKGBUILD ]]; then
err "No PKGBUILD found in directory."
fi
# Allow user to edit .install
unset install
. PKGBUILD
confirm_edit "${COLOR6}Edit $install with \$EDITOR? [Y/n]${ENDCOLOR} " "$install"
# Installation (makepkg and pacman)
rm -f *$PKGEXT
if [[ $UID -eq 0 ]]; then
makepkg $MAKEPKGOPTS --asroot -f
else
makepkg $MAKEPKGOPTS -f
fi
[[ $? -ne 0 ]] && echo "The build failed." && return 1
pkgtarfiles=""
for i in "${pkgname[@]}"; do
pkgtarfiles="$pkgtarfiles $i-*$PKGEXT"
done
if [[ $2 = dependency ]]; then
runasroot $PACMAN ${PACOPTS[@]} --asdeps -U $pkgtarfiles
elif [[ $2 = explicit ]]; then
runasroot $PACMAN ${PACOPTS[@]} -U $pkgtarfiles
fi
}
# Goes through all of the install tests and execution ($@ is packages to be installed)
installhandling() {
packageargs=("$@")
getignoredpackages
sourcemakepkgconf
# Figure out all of the packages that need to be installed
for package in "${packageargs[@]}"; do
# Determine whether package is in pacman repos
if ! [[ $auronly ]] && existsinpacman "$package"; then
pacmanpackages+=("$package")
elif ! [[ $auronly ]] && existsinpacmangroup "$package"; then
pacmanpackages+=("$package")
elif existsinaur "$package"; then
if finddeps "$package"; then
# here is where dep dupes are created
aurpackages+=("$package")
aurdepends=("${aurdeps[@]}" "${aurdepends[@]}")
pacmandepends+=("${pacmandeps[@]}")
fi
else
err "Package \`$package' does not exist."
fi
done
# Check if any aur target packages are ignored
for package in "${aurpackages[@]}"; do
if isignored "$package"; then
echo -ne "${COLOR5}:: ${COLOR1}$package is in IgnorePkg/IgnoreGroup. Install anyway?${ENDCOLOR} [Y/n] "
if ! [[ $noconfirm ]]; then
proceed || continue
else
echo
fi
fi
aurtargets+=("$package")
done
# Check if any aur dependencies are ignored
for package in "${aurdepends[@]}"; do
if isignored "$package"; then
echo -ne "${COLOR5}:: ${COLOR1}$package is in IgnorePkg/IgnoreGroup. Install anyway?${ENDCOLOR} [Y/n] "
if ! [[ $noconfirm ]]; then
if ! proceed; then
echo "Unresolved dependency \`$package'"
unset aurtargets
break
fi
else
echo
fi
fi
done
# First install the explicit pacman packages, let pacman prompt
if [[ $pacmanpackages ]]; then
runasroot $PACMAN "${PACOPTS[@]}" -S -- "${pacmanpackages[@]}"
fi
if [[ -z $aurtargets ]]; then
exit
fi
# Test if aurpackages are already installed; echo warning if so
for pkg in "${aurtargets[@]}"; do
if existsinlocal "$pkg"; then
localversion="$(pacman -Qs "$pkg" | grep -F "local/$pkg" | cut -d ' ' -f 2)"
if ! aurversionisnewer "$pkg" "$localversion"; then
echo -e "${COLOR6}warning:$ENDCOLOR $pkg-$localversion is up to date -- reinstalling"
fi
fi
done
# Echo warning if packages are out of date
for pkg in "${aurtargets[@]}" "${aurdepends[@]}"; do
if isoutofdate "$pkg"; then
echo -e "${COLOR6}warning:$ENDCOLOR $pkg is flagged out of date"
fi
done
# Prompt for aur packages and their dependencies
echo
if [[ $aurdepends ]]; then
num="$((${#aurdepends[@]}+${#aurtargets[@]}))"
echo -e "${COLOR6}Aur Targets ($num):${ENDCOLOR} ${aurdepends[@]} ${aurtargets[@]}"
else
echo -e "${COLOR6}Aur Targets ($((${#aurtargets[@]}))):${ENDCOLOR} ${aurtargets[@]}"
fi
if [[ $pacmandepends ]]; then
IFS=$'\n' read -rd '' -a pacmandepends < \
<(printf "%s\n" "${pacmandepends[@]}" | sort -u)
echo -e "${COLOR6}Pacman Targets (${#pacmandepends[@]}):${ENDCOLOR} ${pacmandepends[@]}"
fi
# Prompt to proceed
echo -en "\nProceed with installation? [Y/n] "
if ! [[ $noconfirm ]]; then
proceed || exit
else
echo
fi
# Install pacman dependencies
if [[ $pacmandepends ]]; then
runasroot $PACMAN --noconfirm --asdeps -S -- "${pacmandepends[@]}" || err "Installation failed."
fi
# Install aur dependencies
if [[ $aurdepends ]]; then
for dep in "${aurdepends[@]}"; do
aurinstall "$dep" "dependency"
done
fi
# Install the aur packages
for package in "${aurtargets[@]}"; do
scrapeaurdeps "$package"
if pacman -T "${dependencies[@]}" &>/dev/null; then
aurinstall "$package" "explicit"
else
echo "Dependencies for \`$package' are not met, not building..."
fi
done
}
run_quick_check() {
bigurl="https://aur.archlinux.org/rpc.php?type=multiinfo"
for p in $(pacman -Qqm); do
bigurl="$bigurl&arg\[\]=$p"
done
parsed_aur="$(curl -s "$bigurl" | \
jshon -e results -a -e Name -u -p -e Version -u | \
sed 's/^$/-/' | paste -s -d '\t\n' | sort)"
packages="$(expac -Q '%n\t%v' | sort)"
comm -23 <(echo "$parsed_aur") <(echo "$packages") | cut -f 1
if [[ $auronly == 1 ]]; then
return
fi
# see https://mailman.archlinux.org/pipermail/pacman-dev/2011-October/014673.html
# (note to self, get that merged already...)
if [[ -z $CHECKUPDATE_DB ]]; then
CHECKUPDATE_DB="${TMPDIR:-/tmp}/checkup-db-${USER}/"
fi
eval $(awk '/DBPath/ {print $1$2$3}' $pacmanconf)
DBPath="${DBPath:-/var/lib/pacman/}"
mkdir -p "$CHECKUPDATE_DB"
ln -s "${DBPath}/local" "$CHECKUPDATE_DB" &> /dev/null
fakeroot pacman -Sqy --dbpath "$CHECKUPDATE_DB" &> /dev/null
pacman -Qqu --dbpath "$CHECKUPDATE_DB" 2> /dev/null
}
# proceed with installation prompt
proceed() {
read -n 1
echo
case "$REPLY" in
'Y'|'y'|'') return 0 ;;
*) return 1 ;;
esac
}
# process busy loop
nap() {
while (( $(jobs | wc -l) >= 8 )); do
jobs > /dev/null
done
}
# Argument parsing
[[ $1 ]] || usage
packageargs=()
while [[ $1 ]]; do
case "$1" in
'-S') option=install ;;
'-Ss') option=search ;;
'-Ssq'|'-Sqs') option=search ; quiet='1' ;;
'-Si') option=info ;;
-S*u*) option=update ; pacmanarg="$1" ;;
'-G') option=download ;;
'-h'|'--help') usage ;;
'--quiet') quiet='1' ;;
'--ignore') ignorearg="$2" ; PACOPTS+=("--ignore" "$2") ; shift ;;
'--noconfirm') noconfirm='1' PACOPTS+=("--noconfirm");;
'--noedit') noedit='1' ;;
'--auronly') auronly='1' ;;
'--quickcheck') quickcheck='1' ;;
'--devel') devel='1' ;;
'--skipinteg') MAKEPKGOPTS="--skipinteg" ;;
'--preview') preview='1' ;;
'--') shift ; packageargs+=("$@") ; break ;;
-*) echo "packer: Option \`$1' is not valid." ; exit 5 ;;
*) packageargs+=("$1") ;;
esac
shift
done
# check for new packages
if [[ $quickcheck == 1 ]]; then
run_quick_check
exit
fi
# Sanity checks
[[ $option ]] || option="searchinstall"
[[ $option != "update" && -z $packageargs ]] && err "Must specify a package."
# Install (-S) handling
if [[ $option = install ]]; then
installhandling "${packageargs[@]}"
exit
fi
# Update (-Su) handling
if [[ $option = update ]]; then
getignoredpackages
sourcemakepkgconf
# Pacman update
if ! [[ $auronly ]]; then
runasroot $PACMAN "${PACOPTS[@]}" "$pacmanarg"
fi
# Aur update
echo -e "${COLOR5}:: ${COLOR1}Synchronizing aur database...${ENDCOLOR}"
IFS=$'\n' read -rd '' -a packages < <(pacman -Qm)
newpackages=()
checkignores=()
total="${#packages[@]}"
grep -q '^ *ILoveCandy' "$pacmanconf" && bartype='candy' || bartype='normal'
if [[ $devel ]]; then
for ((i=0; i<$total; i++)); do
aurbar "$((i+1))" "$total" "$bartype"
pkg="${packages[i]%% *}"
if isignored "$pkg"; then
checkignores+=("${packages[i]}")
continue
fi
pkginfo "$pkg" &
nap
done
wait
for ((i=0; i<$total; i++)); do
pkg="${packages[i]%% *}"
ver="${packages[i]##* }"
if [[ ! -s "$tmpdir/$pkg.PKGBUILD" ]]; then
continue
fi
if isignored "$pkg"; then
continue
fi
unset _darcstrunk _cvsroot _gitroot _svntrunk _bzrtrunk _hgroot
. "$tmpdir/$pkg.PKGBUILD"
if [[ "$(LC_ALL=C vercmp "$pkgver-$pkgrel" "$ver")" -gt 0 ]]; then
newpackages+=("$pkg")
elif [[ ${_darcstrunk} || ${_cvsroot} || ${_gitroot} || ${_svntrunk} || ${_bzrtrunk} || ${_hgroot} ]]; then
newpackages+=("$pkg")
fi
done
else
for ((i=0; i<$total; i++)); do
aurbar "$((i+1))" "$total" "$bartype"
pkg="${packages[i]%% *}"
rpcinfo "$pkg" &
nap
done
wait
for ((i=0; i<$total; i++)); do
pkg="${packages[i]%% *}"
ver="${packages[i]##* }"
if isignored "$pkg"; then
checkignores+=("${packages[i]}")
elif aurversionisnewer "$pkg" "$ver"; then
newpackages+=("$pkg")
fi
done
fi
echo
echo -e "${COLOR5}:: ${COLOR1}Starting full aur upgrade...${ENDCOLOR}"
# Check and output ignored package update info
for package in "${checkignores[@]}"; do
if aurversionisnewer "${package%% *}" "${package##* }"; then
echo -e "${COLOR6}warning:${ENDCOLOR} ${package%% *}: ignoring package upgrade (${package##* } => $aurversion)"
fi
done
# Now for the installation part
if [[ $newpackages ]]; then
auronly='1'
installhandling "${newpackages[@]}"
fi
echo " local database is up to date"
fi
# Download (-G) handling
if [[ $option = download ]]; then
for package in "${packageargs[@]}"; do
if existsinaur "$package"; then
pkglist+=("$package")
else
err "Package \`$package' does not exist on aur."
fi
done
for package in "${pkglist[@]}"; do
curl -Lfs "$(pkglink $package)" > "$package.tar.gz"
mkdir "$package"
tar xf "$package.tar.gz" -C "$package" --strip-components=1
done
fi
# Search (-Ss) handling
if [[ $option = search || $option = searchinstall ]]; then
# Pacman searching
if ! [[ $auronly ]]; then
if [[ $quiet ]]; then
results="$(pacman -Ssq -- "${packageargs[@]}")"
else
results="$(pacman -Ss -- "${packageargs[@]}")"
results="$(sed -r "s|^[^ ][^/]*/|$S${COLOR3}&$S${COLOR1}|" <<< "$results")"
results="$(sed -r "s|^([^ ]+) ([^ ]+)(.*)$|\1 $S${COLOR2}\2$S${ENDCOLOR}\3|" <<< "$results")"
fi
if [[ $option = search ]]; then
echo -e "$results" | fmt -"$_WIDTH" -s
else # interactive
echo -e "$results" | fmt -"$_WIDTH" -s | nl -v 0 -w 1 -s ' ' -b 'p^[^ ]'
fi | sed '/^$/d'
pacname=( $(pacman -Ssq -- "${packageargs[@]}") )
pactotal="${#pacname[@]}"
else
pactotal=0
fi
# Aur searching and tmpfile preparation
for package in "${packageargs[@]}"; do
curl -LfGs --data-urlencode "arg=$package" "$RPCURL=search" | \
jshon -Q -e results -a -e Name -u -p -e Version -u -p -e NumVotes -u -p -e Description -u | \
sed 's/^$/-/' | paste -s -d "\t\t\t\n" | sort -nr -k 3 > "$tmpdir/$package.search" &
done
wait
cp "$tmpdir/${packageargs[0]}.search" "$tmpdir/search.results"
for ((i=1 ; i<${#packageargs[@]} ; i++)); do
grep -xFf "$tmpdir/search.results" "$tmpdir/${packageargs[$i]}.search" > "$tmpdir/search.results-2"
mv "$tmpdir/search.results-2" "$tmpdir/search.results"
done
sed -i '/^$/d' "$tmpdir/search.results"
# Prepare tmp file and arrays
IFS=$'\n' read -rd '' -a aurname < <(cut -f 1 "$tmpdir/search.results")
aurtotal="${#aurname[@]}"
alltotal="$(($pactotal+$aurtotal))"
# Echo out the -Ss formatted package information
IFS=$'\t\n'
if [[ $option = search ]]; then
if [[ $quiet ]]; then
printf "%s\n" ${aurname[@]}
elif [[ -s "$tmpdir/search.results" ]]; then
printf "${COLOR3}aur/${COLOR1}%s ${COLOR2}%s${ENDCOLOR} (%s)\n %s\n" $(cat "$tmpdir/search.results")
fi
else
# interactive
if [[ $quiet ]]; then
nl -v ${pactotal:-0} -w 1 -s ' ' <(cut -f 1 "$tmpdir/search.results")
elif [[ -s "$tmpdir/search.results" ]]; then
printf "%d ${COLOR3}aur/${COLOR1}%s ${COLOR2}%s${ENDCOLOR} (%s)\n %s\n" $(nl -v ${pactotal:-0} -w 1 < "$tmpdir/search.results")
fi
fi | fmt -"$_WIDTH" -s
unset IFS
# Prompt and install selected numbers
if [[ $option = searchinstall ]]; then
pkglist=()
allpackages=( "${pacname[@]}" "${aurname[@]}" )
# Exit if there are no matches
[[ $allpackages ]] || exit
# Prompt for numbers
echo
echo -e "${COLOR2}Type numbers to install. Separate each number with a space.${ENDCOLOR}"
echo -ne "${COLOR2}Numbers: ${ENDCOLOR}"
read -r
# Parse answer
if [[ $REPLY ]]; then
for num in $REPLY; do
if [[ $num -lt $alltotal ]]; then
pkglist+=("${allpackages[$num]}")
else
err "Number \`$num' is not assigned to any of the packages."
fi
done
fi
# Call installhandling to take care of the packages chosen
installhandling "${pkglist[@]}"
fi
# Remove the tmpfiles
rm -f "$tmpdir/*search" &>/dev/null
rm -f "$tmpdir/search.result" &>/dev/null
exit
fi
# Info (-Si) handling
if [[ $option = info ]]; then
# Pacman info check
sourcemakepkgconf
for package in "${packageargs[@]}"; do
if ! [[ $auronly ]] && existsinpacman "$package"; then
results="$(pacman -Si -- "$package")"
results="$(sed -r "s|^(Repository[^:]*:)(.*)$|\1$S${COLOR3}\2$S${ENDCOLOR}|" <<< "$results")"
results="$(sed -r "s|^(Name[^:]*:)(.*)$|\1$S${COLOR1}\2$S${ENDCOLOR}|" <<< "$results")"
results="$(sed -r "s|^(Version[^:]*:)(.*)$|\1$S${COLOR2}\2$S${ENDCOLOR}|" <<< "$results")"
results="$(sed -r "s|^(URL[^:]*:)(.*)$|\1$S${COLOR4}\2$S${ENDCOLOR}|" <<< "$results")"
results="$(sed -r "s|^[^ ][^:]*:|$S${COLOR1}&$S${ENDCOLOR}|" <<< "$results")"
echo -e "$results"
exit
else # Check to see if it is in the aur
pkginfo "$package" "$preview"
[[ -s "$tmpdir/$package.PKGBUILD" ]] || err "${COLOR7}error:${ENDCOLOR} package '$package' was not found"
. "$tmpdir/$package.PKGBUILD"
# Echo out the -Si formatted package information
# Retrieve each element in order and echo them immediately
echo -e "${COLOR1}Repository : ${COLOR3}aur"
echo -e "${COLOR1}Name : $pkgname"
echo -e "${COLOR1}Version : ${COLOR2}$pkgver-$pkgrel"
echo -e "${COLOR1}URL : ${COLOR4}$url"
echo -e "${COLOR1}Licenses : ${ENDCOLOR}${license[@]}"
echo -e "${COLOR1}Groups : ${ENDCOLOR}${groups[@]:-None}"
echo -e "${COLOR1}Provides : ${ENDCOLOR}${provides[@]:-None}"
echo -e "${COLOR1}Depends On : ${ENDCOLOR}${depends[@]}"
echo -e "${COLOR1}Make Depends : ${ENDCOLOR}${makedepends[@]}"
echo -e -n "${COLOR1}Optional Deps : ${ENDCOLOR}"
len="${#optdepends[@]}"
if [[ $len -eq 0 ]]; then
echo "None"
else
for ((i=0 ; i<$len ; i++)); do
if [[ $i = 0 ]]; then
echo "${optdepends[$i]}"
else
echo -e " ${optdepends[$i]}"
fi
done
fi
echo -e "${COLOR1}Conflicts With : ${ENDCOLOR}${conflicts[@]:-None}"
echo -e "${COLOR1}Replaces : ${ENDCOLOR}${replaces[@]:-None}"
echo -e "${COLOR1}Architecture : ${ENDCOLOR}${arch[@]}"
echo -e "${COLOR1}Description : ${ENDCOLOR}$pkgdesc"
echo
fi
done
fi