PHANTOM
🇮🇳 IN
Skip to content

Commit 6fb0cc9

Browse files
author
trizen
committed
- Switched to git clone. (#7)
1 parent 643662c commit 6fb0cc9

File tree

4 files changed

+96
-70
lines changed

4 files changed

+96
-70
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Base Options:
2525
-Su : upgrades installed packages
2626
-Sc : clears the cache directory
2727
-C : outputs AUR comments only
28-
-G : download and extract AUR tarball only
28+
-G : clones the package metadata
2929
-R : remove packages (see pacman -Rh)
3030
-Q : for installed packages (see pacman -Qh)
3131
-U : installs local packages from /tmp or `pwd`

archlinux/.SRCINFO

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Generated by mksrcinfo v8
2-
# Thu Jan 26 16:48:54 UTC 2017
2+
# Thu Mar 23 23:23:47 UTC 2017
33
pkgbase = trizen
44
pkgdesc = Trizen's AUR Package Manager: A lightweight wrapper for AUR.
5-
pkgver = 148.39e3e03
5+
pkgver = 159.643662c
66
pkgrel = 1
77
url = https://github.com/trizen/trizen
88
arch = any
99
license = GPL3
10-
makedepends = git
10+
depends = git
11+
depends = diffutils
1112
depends = perl>=5.10.0
1213
depends = perl-libwww
1314
depends = perl-term-ui

archlinux/PKGBUILD

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
# Maintainer: Trizen <echo dHJpemVueEBnbWFpbC5jb20K | base64 -d>
22

33
pkgname=trizen
4-
pkgver=148.39e3e03
4+
pkgver=159.643662c
55
pkgrel=1
66
pkgdesc="Trizen's AUR Package Manager: A lightweight wrapper for AUR."
77
arch=('any')
88
url="https://github.com/trizen/trizen"
99
license=('GPL3');
1010

11-
makedepends=('git')
1211
depends=(
12+
'git'
13+
'diffutils'
1314
'perl>=5.10.0'
1415
'perl-libwww'
1516
'perl-term-ui'
1617
'pacman'
1718
'perl-json'
1819
'perl-data-dump'
1920
'perl-lwp-protocol-https'
20-
)
21+
)
2122

2223
optdepends=(
2324
'perl-json-xs: faster JSON deserialization'

trizen

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# First created on: 07 July 2010
2222
# Rewritten on: 16 February 2011
2323
# Second rewrite on: 24 March 2012
24-
# Latest edit on: 26 January 2017
24+
# Latest edit on: 24 March 2017
2525
# http://github.com/trizen/trizen
2626

2727
eval 'exec perl -S $0 ${1+"$@"}'
@@ -40,11 +40,11 @@ use autouse 'Text::ParseWords' => qw(quotewords);
4040
use autouse 'File::Path' => qw(make_path rmtree);
4141
use autouse 'File::Basename' => qw(basename dirname);
4242
use autouse 'URI::Escape' => qw(uri_escape_utf8 uri_unescape);
43-
use autouse 'File::Copy' => qw(move);
43+
use autouse 'File::Copy' => qw(move copy);
4444

4545
use File::Spec::Functions qw(catdir catfile tmpdir curdir rel2abs);
4646

47-
my $version = '1.12';
47+
my $version = '1.13';
4848
my $execname = 'trizen';
4949

5050
my $AUR_V = "5"; # current version of AurJson
@@ -248,7 +248,7 @@ sub help () {
248248
-Su : upgrades installed packages
249249
-Sc : clears the cache directory
250250
-C : outputs AUR comments only
251-
-G : download and extract AUR tarball only
251+
-G : clones the package metadata
252252
-R : remove packages (see pacman -Rh)
253253
-Q : for installed packages (see pacman -Qh)
254254
-U : installs local packages from $lconfig{cache_dir} or `pwd`
@@ -424,12 +424,10 @@ if ($lconfig{h}) {
424424
# Run-time loaded modules
425425
require Term::UI;
426426
require Term::ReadLine;
427-
require Archive::Tar;
428427
require LWP::UserAgent;
429428
require HTTP::Message;
430429

431430
# Initializing module objects
432-
my $tar = Archive::Tar->new();
433431
my $term = Term::ReadLine->new("$execname $version");
434432

435433
my $lwp = LWP::UserAgent->new(
@@ -644,52 +642,93 @@ sub indent_array (@) {
644642
return "$first\n$rest";
645643
}
646644

647-
sub get_tgz_package ($$) {
648-
my ($url, $output) = @_;
649-
if ($lconfig{overwrite} or not -e $output or -z _) {
650-
mirror($url, $output) or return;
645+
sub info_for_package($) {
646+
my ($pkg) = @_;
647+
648+
my $info = get_rpc_info($pkg);
649+
650+
if (ref($info->{results}) ne 'ARRAY') {
651+
warn "[!] Unable to get info for package: $pkg\n" if $lconfig{debug};
652+
return;
653+
}
654+
655+
$info->{resultcount} > 0 or return;
656+
657+
if ($info->{resultcount} > 1) {
658+
print "$c{bold}** Found $c{reset}$c{bgreen}$info->{resultcount}$c{reset}$c{bold} packages.$c{reset}\n";
659+
my @packages = map { $_->{Name} } @{$info->{results}};
660+
my %table = (map { $packages[$_] => $_ } 0 .. $#packages);
661+
my $reply = $term->get_reply(
662+
print_me => "\n=>> Select which packages to install",
663+
prompt => 'Select',
664+
choices => \@packages,
665+
default => $packages[0],
666+
);
667+
$info = $info->{results}[$table{$reply}];
651668
}
652669
else {
653-
warn "[!] $output already exists. (use --overwrite to replace)\n";
670+
$info = $info->{results}[0];
654671
}
655-
return 1;
672+
673+
$info;
656674
}
657675

658-
sub get_package_tarball ($$) {
676+
sub download_package ($$) {
659677
my ($pkg, $path) = @_;
660-
my $info = get_rpc_info($pkg);
661678

662-
if (ref($info->{results}) ne 'ARRAY' and !@{$info->{results}}) {
663-
warn "[!] Unable to find $pkg in AUR!\n" if $lconfig{debug};
664-
return;
665-
}
679+
my $info = info_for_package($pkg) // return;
666680

667-
$info->{resultcount} > 0 or return;
668-
$info = {results => $info->{results}[0]};
681+
my $pkg_base = $info->{PackageBase};
682+
my $git_url = "https://aur.archlinux.org/$pkg_base.git";
683+
my $dir_name = rel2abs(catdir($path, $pkg_base));
684+
685+
if (-d $dir_name) {
686+
my $pkgbuild_prev = catfile($dir_name, '.PKGBUILD');
687+
my $pkgbuild_curr = catfile($dir_name, 'PKGBUILD');
688+
689+
my $old_pkgbuild_content = do {
690+
if (open my $fh, '<', $pkgbuild_curr) {
691+
local $/;
692+
<$fh>;
693+
}
694+
else {
695+
undef;
696+
}
697+
};
669698

670-
my $tgz_file = catfile($path, basename($info->{results}{URLPath}));
671-
my $url = "$lconfig{aur_base_url}$info->{results}{URLPath}";
699+
system('/usr/bin/git', '-C', $dir_name, 'reset', '--hard', 'HEAD', ($lconfig{_installing} ? () : ('-q'))) && return;
700+
system('/usr/bin/git', '-C', $dir_name, 'pull', '--ff', ($lconfig{_installing} ? () : ('-q'))) && return;
672701

673-
get_tgz_package($url, $tgz_file) or do { warn "[!] Unable to get the tarball for $pkg: $!"; return };
702+
if ( $lconfig{_installing}
703+
and defined($old_pkgbuild_content)
704+
and open(my $fh, '>', $pkgbuild_prev)) {
705+
print {$fh} $old_pkgbuild_content;
706+
close $fh;
674707

675-
my $dir_name = uri_unescape(catdir(dirname($tgz_file), basename($tgz_file, @package_suffices)));
708+
chomp(my $diff = `/usr/bin/diff --color=always -w -B -a -d \Q$pkgbuild_prev\E \Q$pkgbuild_curr\E`);
709+
710+
if ($diff ne '') {
711+
say "\n$c{bold}** PKGBUILD diff for$c{reset} $c{bgreen}$info->{Name}$c{reset}";
712+
say $diff;
713+
}
714+
}
715+
}
716+
else {
717+
system('/usr/bin/git', '-C', $path, 'clone', '--depth=1', ($lconfig{_installing} ? () : ('-q')), $git_url) && return;
718+
}
676719

677720
if ($lconfig{debug}) {
678721
say "** Changing directory to: $path";
679722
}
680723

681724
chdir($path) or do { warn "[!] Unable to chdir() to $path: $!"; return };
682725

683-
$info->{_localpath} = rel2abs($dir_name); # directory that contains the PKGBUILD
684-
685-
if ($lconfig{overwrite} or not -e "$dir_name/PKGBUILD" or -z _) {
686-
extract_tarball($tgz_file) or do { warn "[!] Unable to extract tarball of $pkg: $!"; return };
687-
}
688-
689726
if ($lconfig{debug}) {
690727
say "** Trying to change directory to: $dir_name";
691728
}
692729

730+
$info->{_localpath} = $dir_name; # directory that contains the PKGBUILD
731+
693732
if (-d $dir_name) {
694733
chdir $dir_name or do { warn "[!] Unable to chdir() to $dir_name: $!"; return };
695734
say "** Changed directory successfully to: $dir_name" if $lconfig{debug};
@@ -698,24 +737,13 @@ sub get_package_tarball ($$) {
698737
return $info;
699738
}
700739

701-
sub extract_tarball ($) {
702-
my ($tarball) = @_;
703-
$tar->read($tarball) or return;
704-
$tar->extract() or return;
705-
return 1;
706-
}
707-
708740
sub get_rpc_info ($) {
709741
my ($pkg) = @_;
710742
return json2perl(get("$lconfig{aur_rpc_base_url}?v=$AUR_V&type=info&arg=" . uri_escape_utf8($pkg)) // return);
711743
}
712744

713745
sub show_info ($) {
714-
my ($data) = @_;
715-
716-
ref($data->{results}) eq 'HASH' or return;
717-
718-
my $info = $data->{results};
746+
my ($info) = @_;
719747

720748
say map { sprintf $c{bold} . $_->[0], $c{reset} . $_->[1] }
721749
["Name : %s\n", "$c{bold}$info->{Name}$c{reset}"],
@@ -888,7 +916,7 @@ sub edit_text_files ($) {
888916
);
889917

890918
while (my ($key1, $key2) = each %pairs) {
891-
$info->{results}{$key1} = $data{$key2};
919+
$info->{$key1} = $data{$key2};
892920
}
893921
}
894922

@@ -1064,10 +1092,11 @@ sub install_as_explicit ($) {
10641092
sub install_package ($) {
10651093
my ($pkg) = @_;
10661094

1095+
local $lconfig{_installing} = 1;
10671096
say "** Current dir is: ", rel2abs(curdir()) if $lconfig{debug};
10681097

1069-
my $info;
1070-
if (ref($info = get_package_tarball($pkg, $lconfig{cache_dir})) eq 'HASH') {
1098+
my $info = download_package($pkg, $lconfig{cache_dir});
1099+
if (ref($info) eq 'HASH') {
10711100
say "** Package `$pkg' is found in AUR!" if $lconfig{debug};
10721101
}
10731102
elsif (not $lconfig{aur} and is_available_in_pacman_repo($pkg)) {
@@ -1079,12 +1108,12 @@ sub install_package ($) {
10791108
return;
10801109
}
10811110

1082-
ref $info->{results} eq 'HASH' or return;
1111+
length($info->{Name}) || return;
10831112

10841113
if (my $version = package_is_installed($pkg)) {
10851114
say "** Package `$pkg' is already installed!" if $lconfig{debug};
10861115
if ($lconfig{needed}) {
1087-
if (versioncmp($version, $info->{results}{Version}) >= 0) {
1116+
if (versioncmp($version, $info->{Version}) >= 0) {
10881117
return 1; # package is installed and up-to-date
10891118
}
10901119
else {
@@ -1093,8 +1122,8 @@ sub install_package ($) {
10931122
}
10941123
}
10951124

1096-
say "\n$c{bold}** Installing:$c{reset}: $c{bgreen}$info->{results}{Name}$c{reset}";
1097-
say "$c{bold}** AUR URL:$c{reset} ", sprintf($lconfig{aur_package_id_url}, $info->{results}{ID});
1125+
say "\n$c{bold}** Installing:$c{reset}: $c{bgreen}$info->{Name}$c{reset}";
1126+
say "$c{bold}** AUR URL:$c{reset} ", sprintf($lconfig{aur_package_id_url}, $info->{ID});
10981127

10991128
# When a package is already built, install it without building it again.
11001129
if ($already_built{$pkg}) {
@@ -1107,7 +1136,7 @@ sub install_package ($) {
11071136
}
11081137

11091138
if ($lconfig{show_comments}) {
1110-
foreach my $comment (get_comments($info->{results}{ID})) {
1139+
foreach my $comment (get_comments($info->{ID})) {
11111140
say $comment;
11121141
}
11131142
}
@@ -1125,10 +1154,10 @@ sub install_package ($) {
11251154
map { strip_version($_) }
11261155

11271156
# Makedepends
1128-
(exists($info->{results}{MakeDepends}) ? @{$info->{results}{MakeDepends}} : ()),
1157+
(exists($info->{MakeDepends}) ? @{$info->{MakeDepends}} : ()),
11291158

11301159
# Depends
1131-
(exists($info->{results}{Depends}) ? @{$info->{results}{Depends}} : ()),
1160+
(exists($info->{Depends}) ? @{$info->{Depends}} : ()),
11321161
) {
11331162

11341163
if (exists $ignored_packages{$dep}) { # next if $dep exists in %ignored_packages
@@ -1236,7 +1265,7 @@ sub search_aur_packages (@) {
12361265
sub list_aur_maintainer_packages ($) {
12371266
my ($maintainer) = @_;
12381267
my $results = json2perl(get("$lconfig{aur_rpc_base_url}?v=$AUR_V&type=msearch&arg=$maintainer") // return);
1239-
ref $results->{results} eq 'ARRAY' or return;
1268+
ref($results->{results}) eq 'ARRAY' or return;
12401269
my @maintainers_packages = @{$results->{results}};
12411270
print_aur_results(@maintainers_packages) or return;
12421271
return 1;
@@ -1432,8 +1461,7 @@ if ($lconfig{S}) { # -S
14321461
foreach my $pkgname (@argv_packages) {
14331462
!$lconfig{aur} && is_available_in_pacman_repo($pkgname)
14341463
? execute_pacman_command(0, qw(-Si), $pkgname)
1435-
: (my $info = get_package_tarball($pkgname, $lconfig{cache_dir}));
1436-
show_info($info);
1464+
: show_info(info_for_package($pkgname) // next);
14371465
}
14381466
}
14391467
elsif ($lconfig{u}) { # -Su
@@ -1450,9 +1478,9 @@ if ($lconfig{S}) { # -S
14501478
}
14511479
elsif ($lconfig{p}) { # -Sp
14521480
foreach my $pkgname (@argv_packages) {
1453-
get_package_tarball($pkgname, $lconfig{cache_dir}) or next;
1481+
download_package($pkgname, $lconfig{cache_dir}) or next;
14541482
open my $fh, '<:utf8', 'PKGBUILD' or do { warn "Unable to open PKGBUILD of $pkgname: $!"; next };
1455-
say "$c{bold}=>> PKGBUILD of $c{cblack}$c{byellow}$pkgname$c{reset}:$c{reset}\n", <$fh>;
1483+
say "\n$c{bold}=>> PKGBUILD of: $c{cblack}$c{bgreen}$pkgname$c{reset}$c{reset}\n\n", <$fh>;
14561484
close $fh;
14571485
}
14581486
}
@@ -1475,9 +1503,7 @@ if ($lconfig{S}) { # -S
14751503
}
14761504
elsif ($lconfig{C}) { # -C
14771505
foreach my $pkg (@argv_packages) {
1478-
my $info = get_rpc_info($pkg) or next;
1479-
ref($info->{results}) eq 'ARRAY' && @{$info->{results}} or next;
1480-
$info = $info->{results}[0];
1506+
my $info = info_for_package($pkg) // next;
14811507
say "$c{bold}** AUR comments for $c{bgreen}$pkg$c{reset}$c{bold}$c{reset}\n$c{bold}** URL:$c{reset} ",
14821508
sprintf($lconfig{aur_package_id_url}, $info->{ID}), "\n";
14831509
foreach my $comment (get_comments($info->{ID})) {
@@ -1488,9 +1514,7 @@ elsif ($lconfig{C}) { # -C
14881514
elsif ($lconfig{G}) { # -G
14891515
foreach my $pkg (@argv_packages) {
14901516
say "** Getting tarball of: $pkg" if $lconfig{debug};
1491-
get_package_tarball($pkg, q{.}) or next;
1492-
chdir q{..};
1493-
unlink "$pkg.tar.gz" or warn "[!] Unable to delete './$pkg.tar.gz': $!";
1517+
download_package($pkg, curdir()) or next;
14941518
}
14951519
}
14961520
elsif ($lconfig{U}) { # -U

0 commit comments

Comments
 (0)