7 my @curl_args = ('-A', 'aurutils', '-fgLsSq');
9 # environment variables
10 my $aur_location = $ENV{AUR_LOCATION
} // 'https://aur.archlinux.org';
11 my $aur_rpc = $ENV{AUR_QUERY_RPC
} // $aur_location . "/rpc";
12 my $aur_rpc_ver = $ENV{AUR_QUERY_RPC_VERSION
} // 5;
13 my $aur_splitno = $ENV{AUR_QUERY_RPC_SPLITNO
} // 5000;
15 # https://code.activestate.com/recipes/577450-perl-url-encode-and-decode/#c6
18 $s =~ s/([^A-Za-z0-9])/sprintf("%%%2.2X", ord($1))/ge;
28 GetOptions
('t|type=s' => \
$opt_type,
30 'n|dry-run' => \
$opt_dry_run)
33 if ($opt_type eq "search" or $opt_type eq "suggest") {
37 # process package names from stdin or the command-line
38 if (not scalar(@ARGV)) {
39 say STDERR
"$argv0: at least one argument required";
42 if ($ARGV[0] eq "-" or $ARGV[0] eq "/dev/stdin") {
43 while (my $arg = <STDIN
>) {
54 # URI/URI::QueryParam is extremely slow for large inputs. Build the form data
55 # by hand and use sprintf to encode the package names.
56 for my $target (@ARGV) {
57 if ($NR % $aur_splitno == 0) {
58 # Create new form element
61 # Set fields and values
62 $forms[$#forms] .= '&v=' . $aur_rpc_ver;
63 $forms[$#forms] .= '&type=' . $opt_type;
64 $forms[$#forms] .= '&by=' . $opt_by if defined($opt_by);
66 $forms[$#forms] .= '&arg[]=' . urlencode
($target);
70 # Output as JSON lines
71 for my $form (@forms) {
72 my @cmd = ('curl', @curl_args, $aur_rpc, '--data-raw', $form);
75 say join(" ", map(qq/'$_'/, @cmd));
77 my $child_pid = open(my $fh, "-|", @cmd) or die $!;
79 if ($child_pid) { # parent process
81 die "$argv0: response error (multi-line output)" if defined(<$fh>);
83 waitpid($child_pid, 0);
85 # Return a generic error code on `curl` failure, to avoid overlap with
86 # codes from other tools which use pipelines (`aur-repo`, `aur-vercmp`).
87 # 2 is the same code returned if `curl` is not found in `open` above.