You are not logged in.

#226 2010-01-23 14:17:33

Meyithi
Member
From: Wirral, UK
Registered: 2009-06-21
Posts: 550
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

[meyithi@158NET ~]$ sudo pacman -Syyu
Password: 
:: Synchronising package databases...
 core                      36.0K  419.1K/s 00:00:00 [#################################################################################] 100%
 extra                    441.9K  796.2K/s 00:00:01 [#################################################################################] 100%
 xyne-any                   5.4K   32.1K/s 00:00:00 [#################################################################################] 100%
 community                370.7K  785.7K/s 00:00:00 [#################################################################################] 100%
:: Starting full system upgrade...
warning: transmission-gtk: local (1.81-1) is newer than extra (1.80-1)
 local database is up to date
[meyithi@158NET ~]$ sudo powerpill -Syyu
--> Rebasing...
--> updated [core] +0 ^0 -0

--> updated [extra] +0 ^0 -0

--> updated [xyne-any] +0 ^0 -0

--> updated [community] +0 ^0 -0

:: Starting full system upgrade...
warning: transmission-gtk: local (1.81-1) is newer than extra (1.80-1)
 local database is up to date
[meyithi@158NET ~]$ sudo bauerbill -Syyu
--> Rebasing...
--> updated [core] +0 ^0 -0

--> updated [extra] +0 ^0 -0

--> updated [xyne-any] +0 ^0 -0

--> updated [community] +0 ^0 -0

error: failed to unlock database (Permission denied)

It's just Bauerbill for some reason, was fine until I pulled in perl-xyne-arch 1.0.46-1.

EDIT/ bauerbill.conf @ http://www.meyithi.com/dots/bauerbill.conf

Last edited by Meyithi (2010-01-23 14:20:40)


The mind roams more freely in empty rooms.
dwm - colours - ncmpcpp - system
irc://irc.freenode.net:meyithi

Offline

#227 2010-01-23 14:32:37

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Please post the output of running this script (with sudo). It might help me localize the problem.

#!/usr/bin/perl
use strict;
use warnings;

use Xyne::Arch::Bauerbill;


my $bb = Xyne::Arch::Bauerbill->new({autoload=>1});

print "first test\n";
print "\tlocking database\n";
$bb->lock_db();
print "\tunlocking database\n";
$bb->unlock_db();
print "\n";

print "second test\n";
$bb->drop_root_privileges_or_exit();
&Xyne::Arch::Bauerbill::unsu();
print "\tlocking database\n";
$bb->lock_db();
print "\tunlocking database\n";
$bb->unlock_db();
print "\n";

print "third test\n";
$bb->maybe_lock_and_rebase(1);
print "\n";

My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#228 2010-01-23 14:36:38

Meyithi
Member
From: Wirral, UK
Registered: 2009-06-21
Posts: 550
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

sudo xynetest
Password: 
first test
    locking database
    unlocking database

second test
    locking database
    unlocking database

third test
--> Rebasing...
--> updated [core] +0 ^0 -0


^ extra/transmission-cli 1.81-1 -> 1.80-1
^ extra/transmission-gtk 1.81-1 -> 1.80-1
--> updated [extra] +0 ^2 -0

--> updated [xyne-any] +0 ^0 -0


^ community/apvlv 0.0.9.2-1 -> 0.0.9-1
^ community/mathomatic 15.0.4-1 -> 15.0.3-1
--> updated [community] +0 ^2 -0

error: failed to unlock database (Permission denied)

Wish I could help more but my knowledge isn't up to it smile


The mind roams more freely in empty rooms.
dwm - colours - ncmpcpp - system
irc://irc.freenode.net:meyithi

Offline

#229 2010-01-23 15:41:59

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

If this doesn't work, I'm out of ideas.

#!/usr/bin/perl
use strict;
use warnings;

use Xyne::Arch::Bauerbill;


sub maybe_lock_and_rebase
{
  my ($self,$definitely,$reponames,$arch) = @_;
  &Xyne::Arch::Bauerbill::unsu();
  print "locking as $>\n";
  $self->lock_db;
  my $r;
  if ($definitely)
  {
    $r = $self->rebase({'keep'=>1},$reponames,$arch);
  }
  else
  {
    $r = $self->maybe_rebase({'keep'=>1},$reponames,$arch);
  }
  $self->display_rebase_results($r);
  &Xyne::Arch::Bauerbill::unsu();
  print "unlocking as $>\n";
  $self->unlock_db;
}


my $bb = Xyne::Arch::Bauerbill->new({autoload=>1});
&maybe_lock_and_rebase($bb, 1);

My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#230 2010-01-23 16:00:24

Meyithi
Member
From: Wirral, UK
Registered: 2009-06-21
Posts: 550
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

[meyithi@158NET ~]$ sudo xynetest2
Password: 
locking as 0
--> Rebasing...
--> updated [core] +0 ^0 -0

--> updated [extra] +0 ^0 -0

--> updated [xyne-any] +0 ^0 -0


^ community/python-matplotlib 0.99.1.1-4 -> 0.99.1.2-1
--> updated [community] +0 ^1 -0

unlocking as 0

Seems OK.


The mind roams more freely in empty rooms.
dwm - colours - ncmpcpp - system
irc://irc.freenode.net:meyithi

Offline

#231 2010-01-23 16:21:27

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Try perl-xyne-arch 1.0.47 and let me know if that works (available from the repo on my site).

Please post the output of the following as well (with and without sudo, and as root). I'm still trying to understand how it loses permissions.

#!/usr/bin/perl
use strict;
use warnings;

use Xyne::Arch::Bauerbill;


sub maybe_lock_and_rebase
{
  my ($self,$definitely,$reponames,$arch) = @_;
  my @foo = getpwuid($>);
  my $group = (getgrgid($foo[3]))[0];
  print "locking as $foo[0]:$group\n";
  
  $self->lock_db;
  my $r;
  if ($definitely)
  {
    $r = $self->rebase({'keep'=>1},$reponames,$arch);
  }
  else
  {
    $r = $self->maybe_rebase({'keep'=>1},$reponames,$arch);
  }
  $self->display_rebase_results($r);
  @foo = getpwuid($>);
  $group = (getgrgid($foo[3]))[0];
  print "unlocking as $foo[0]:$group\n";
  $self->unlock_db;
}


my $bb = Xyne::Arch::Bauerbill->new({autoload=>1});
&maybe_lock_and_rebase($bb, 1);

My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#232 2010-01-23 16:22:10

Meyithi
Member
From: Wirral, UK
Registered: 2009-06-21
Posts: 550
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Just pulled in perl-xyne-arch-1.0.47-1 and everything is working again!

Thanks very much for your work and time Xyne - I for one would find it hard to do without Reflector, Rebase, Powerpill and Bauerbill smile

EDIT/ You beat me to it, output of script below:

[meyithi@158NET ~]$ sudo xynetest3
Password: 
locking as root:root
--> Rebasing...
--> updated [core] +0 ^0 -0

--> updated [extra] +0 ^0 -0

--> updated [xyne-any] +0 ^0 -0

--> updated [community] +0 ^0 -0

unlocking as meyithi:users
error: failed to unlock database (Permission denied)
[meyithi@158NET ~]$ xynetest3
locking as meyithi:users
error: failed to lock database (Permission denied)
[meyithi@158NET ~]$ su - root
Password: 
[root@158NET ~]# /store/Documents/Scripts/xynetest3
locking as root:root
--> Rebasing...
--> updated [core] +0 ^0 -0

--> updated [extra] +0 ^0 -0

--> updated [xyne-any] +0 ^0 -0

--> updated [community] +0 ^0 -0

unlocking as meyithi:users
error: failed to unlock database (Permission denied)
[meyithi@158NET ~]$ sudo bauerbill -Syyu
Password: 
--> Rebasing...
--> updated [core] +0 ^0 -0

--> updated [extra] +0 ^0 -0

--> updated [xyne-any] +0 ^0 -0

--> updated [community] +0 ^0 -0

--> Searching for upgradable repo packages...
--> Searching for upgradable AUR packages...
--> Loading AUR taurball data...
--> Switching to pacman: /usr/bin/pacman -S -u
:: Starting full system upgrade...
 local database is up to date

Last edited by Meyithi (2010-01-23 16:30:13)


The mind roams more freely in empty rooms.
dwm - colours - ncmpcpp - system
irc://irc.freenode.net:meyithi

Offline

#233 2010-01-23 16:53:09

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Thanks for posting the output.

I also found the problem and realized that I'm an idiot. When I fixed the logging permissions bug, I added code to regain privileges to make sure that the running process had write permissions to the log. I also added code to drop root privileges after the write because I was being lazy and didn't want to check the permissions context of every call to the logging function (which is also slightly complicated due to the way bauerbill inherits from powerpill).

Of course I couldn't reproduce the unlocking error because I didn't think to enable logging and didn't even consider the connection (again, partly a consequence of the complexity of Perl inheritance, but mostly because I just wasn't thinking).

Yeah, I realize that this is probably about as interesting as a layman's detailed description of paint drying, in real time.


Anyway, I've updated the code again. Let me know if it still works.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#234 2010-01-23 16:54:36

Meyithi
Member
From: Wirral, UK
Registered: 2009-06-21
Posts: 550
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Still fine with perl-xyne-arch-1.0.49-1, glad it's all sorted!


The mind roams more freely in empty rooms.
dwm - colours - ncmpcpp - system
irc://irc.freenode.net:meyithi

Offline

#235 2010-01-23 16:56:35

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Me too, cheers!


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#236 2010-01-24 02:54:25

gav616
Member
Registered: 2008-01-16
Posts: 182

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

love the work, yaourt is gone. big_smile

BTW,
I was a bit confused with powerpill specific options in the bauerbill config, so i deleted all the PP specifics and enabled 'PowerpillConf = /etc/powerpill.conf'

is this ok to do? if so, i recommend doing this as default...

or at least providing this bauerbill only config, that links to powerpill with your package. (which I'm guessing you would like to promote anyway)

Last edited by gav616 (2010-01-24 02:59:45)

Offline

#237 2010-01-24 03:08:48

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

It's fine if you remove them completely. There are two reasons that I've left them in the config file. The first is that the file is auto-generated by my OptionHandler module with the default options and it would be a pain to add custom code just to differentiate the Powerpill options. The second is that it might not always "depend" on Powerpill so I want to leave bauerbill.conf completely independent and not have to worry about detecting powerpill.conf in the future.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#238 2010-01-24 03:32:09

gav616
Member
Registered: 2008-01-16
Posts: 182

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

ah ok,
some other things;

'BuildAs' option, i guess that's to allow rebase to do its thing?
i.e.
sudo bauerbill -Sy wine
this would root run rebase, sync, drop permission to BuildAs user then install wine right?

Offline

#239 2010-01-24 03:54:04

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Partly, but it also requires root privileges when installing packages and removing makedepends. The BuildAs user is used for actual building (when run as root). For example, if you have to build the makedepends of a target package, it will drop root privileges, build that package, regain them, install it, then drop them again to build the target package.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#240 2010-01-24 14:23:32

tri1976
Member
Registered: 2009-09-07
Posts: 152

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

bauerbill supposed to have reflector builtin but when I ran system upgrade with bb it always said "reflecting.... retrieved 0 mirrors".  I installed reflector, then it said "reflecting... retrieve 45 mirrors".  Does it really have reflector builtin or maybe it requires reflector dependency  perl-crypt-ssleay-0.57-2?

Offline

#241 2010-01-24 14:25:57

tri1976
Member
Registered: 2009-09-07
Posts: 152

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

I confirmed it just needs perl-crypt-ssleay, can you add this dependency to bauerbill?

Offline

#242 2010-01-24 17:42:41

xilef
Member
Registered: 2009-04-22
Posts: 3

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Seems to be working fine, thanks for your work.

Just a wondering about ABS integration. It seems the old, previously built packages remain and need to be removed from the ABS tree before new ones will be rebuilt. This could just be for 'git' packages (ie. awesome-git), not sure.

What is a suggested work flow for ABS packages and updating them?

Offline

#243 2010-01-24 17:55:28

gonX
Member
From: Denmark
Registered: 2009-08-16
Posts: 112

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Xyne wrote:

I'm not forcing anything. It's open source and you can easily change it yourself. I doubt that you even need to know Perl to do it. If you really can't figure it out, I can post a patch for you, but don't blame me for whatever goes wrong.

The observations of a single person over a period of "+4 months" is quite far from a statistically significant sample. The truth is that harmful code can make it in, either through ineptitude or malicious intent. This is why the AUR server does not source the PKGBUILDs and why an AUR front-end is not allowed in the official repos.

I will not make it even easier for a simple slip on the command line (e.g. a typo) to destroy the system. I agree that it's unlikely, but the possibility exists. I also don't want to encourage users to completely disregard the potential danger of running and installing code from unknown sources. As Arch continues to attract new users, it will eventually be targeted by malicious users too. I can think of a few ways in which one could corrupt a popular package on the AUR to affect the most users at once. Not worrying about something because it hasn't happened yet is the kind of thinking that leads to catastrophes of varying scale (why invest in levies? we've never been flooded).

I really think the TrustedUsers option should be enough. Using installed packages as a critierion for trust does not take into account that packages can be orphaned and adopted by others, or that one could upload a package to the AUR to usurp a local foreign package (e.g. you've installed "foo" locally, then someone uploads "foo" to the AUR and then local "foo" gets updated from the AUR).

Exercising basic caution out of habit is hardly exigent and you can bypass it if you really want to. You should really ask yourself though if adding a few names to the config is really that much of a hassle.

I know how to make the patch myself. It is silly though, because bauerbill is still being maintained. Making a patch just for this for every single release is a huge waste of time - there is no real reason to not do it other than to pigeonhole people into security. It's the users own option to use --noconfirm. Hell, if you made a single confirm for all packages that would be fine too. Sometimes a couple of weeks can go between updates for me, and I might end up having to update +10 packages from the AUR (especially if I recompile/refetch devel packages).

The way you have it now by sourcing every single PKGBUILD before starting the install is much, much better than yaourt's implementation, though, and I applaud you for that.

-edit: clarification

Last edited by gonX (2010-01-24 17:57:42)


since 2009

Offline

#244 2010-01-24 18:47:02

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

@tri1976
Sorry, I had forgotten all about that. I've added it to the optdepends array.

@xilef
I still need to deal with moving built packages to the cache (if PKGDEST is not specified in makepkg.conf). That should also take care of problems with build packages. I might also add an option to pass arguments to makepkg (e.g. -f).

@gonX
Ok, I'm seriously considering adding a stupidly long CLI option to enable this, e.g. "--i-am-absolutely-certain-that-i-want-to-bypass-the-pkgbuild-and-install-file-inspection-for-packages-from-untrusted-users-with-no-confirm". Well, maybe not that long, but something that would probably take a lot of monkeys a lot of time to produce.

I do agree with you that I am effectively forcing people to use the application in a way which I consider secure, but I still don't understand why you can't just add trusted users to the configuration, especially for files which you update regularly. It seems like this is more about some abstract principle than practical concerns.

Bah, I have a whole "bus driver requiring passengers to wear seatbelts for parts of the journey" analogy in my head, but there's really no point to writing it all out (it was good though, e.g. telling you to maintain your own bus on the same route, no one has to ride this bus, but yeah it might be the best bus to ride, etc).


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#245 2010-01-24 19:02:09

Gumper
Member
From: U.S.A.
Registered: 2009-10-26
Posts: 132

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

I just used "bauerbill -Syu" to upgrade my system and I'm not sure if "aria2" is working. I haven't used powerpill in a while but when I did I thought I recall seeing messages about aria2 as it was downloading parts of the packages. I don't see that here and it appears that bauerbill was downloading each package completely and then moving on to the next one to download. Like pacman does.

Is there something that I'm missing here?


Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.

Offline

#246 2010-01-24 19:33:54

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Yeah, I now use filtered aria2c output instead of the nasty hack that I used to use to get information about the ongoing download in previous versions. The line in square brackets is directly from aria2c and it shows the total number of connections (CN) and the total download speed. It's still downloading everything in parallel. The other lines are just user feedback to show that a package download has finished.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#247 2010-01-24 19:49:08

Gumper
Member
From: U.S.A.
Registered: 2009-10-26
Posts: 132

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Xyne wrote:

Yeah, I now use filtered aria2c output instead of the nasty hack that I used to use to get information about the ongoing download in previous versions. The line in square brackets is directly from aria2c and it shows the total number of connections (CN) and the total download speed. It's still downloading everything in parallel. The other lines are just user feedback to show that a package download has finished.

Cool, thanks!


Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.

Offline

#248 2010-01-25 11:52:27

gav616
Member
Registered: 2008-01-16
Posts: 182

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

has bauerbill got a "yaourt -C" equivalent?

Offline

#249 2010-01-25 12:07:32

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

gav616 wrote:

has bauerbill got a "yaourt -C" equivalent?

I had to do a search to find out what "yaourt -C" does. Please post more information next time.

No, not yet, although I might add it.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#250 2010-01-25 12:14:53

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Bauerbill: Powerpill + ABS, AUR, CPAN and Hackage support + more

Bauerbill is indeed dandy. Kudos.

Two things I'd like to mention:
1) it's a tad annoying that pressing ctrl-c while rebasing leaves a db.lck,
2) I've copied /usr/share/zsh/site-functions/_pacman to /usr/share/zsh/site-functions/_bauerbill and changed all occurrences of pacman to bauerbill, except the ones with pacman.conf and /var/lib/pacman, and completion works nicely for me in zsh - perhaps you could add such a file to your package.

#compdef bauerbill 

# copy this file to /usr/share/zsh/site-functions/_bauerbill

typeset -A opt_args

# options for passing to _arguments: main bauerbill commands
_bauerbill_opts_commands=(
    '-Q[Query the package database]'
    '-R[Remove a package from the system]'
    '-S[Synchronize packages]'
    '-U[Upgrade a package]'
    '-V[Display version and exit]'
    '-h[Display usage]'
)

# options for passing to _arguments: options common to all commands
_bauerbill_opts_common=(
    '-b[Alternate database location]:database_location:_files -/'
    '-h[Display syntax for the given operation]'
    '-r[Set alternate installation root]:installation root:_files -/'
    '-v[Be more verbose]'
    '--cachedir[Alternate package cache location]:cache_location:_files -/'
    '--config[An alternate configuration file]:config file:_files'
    '--logfile[An alternate log file]:config file:_files'
    '--noconfirm[Do not ask for confirmation]'
    '--noprogressbar[Do not show a progress bar when downloading files]'
    '--noscriptlet[Do not execute the install scriptlet if one exists]'
)

# options for passing to _arguments: options for --upgrade commands
_bauerbill_opts_pkgfile=(
    '-d[Skip dependency checks]'
    '-f[Overwrite conflicting files]'
    '*:package file:_files -g "*.pkg.tar.gz(.)"'
)

# options for passing to _arguments: subactions for --query command
_bauerbill_opts_query_actions=(
    '-g[View all members of a package group]:*:package groups:->query_group'
    '-o[Query the package that owns a file]:file:_files'
    '-p[Package file to query]:*:package file:->query_file'
    '-s[Search package names and descriptions]:*:search text:->query_search'
)

# options for passing to _arguments: options for --query and subcommands
_bauerbill_opts_query_modifiers=(
    '-c[List package changelog]'
    '-d[List packages installed as dependencies]'
    '-e[List packages explicitly installed]'
    '-i[View package information]'
    '-ii[View package information including backup files]'
    '-k[Check package files]'
    '-l[List package contents]'
    '-m[List installed packages not found in sync db(s)]'
    '-t[List packages not required by any package]'
    '-u[List packages that can be upgraded]'
)

# options for passing to _arguments: options for --remove command
_bauerbill_opts_remove=(
    '-c[Remove all dependent packages]'
    '-d[Skip dependency checks]'
    '-k[Only remove database entry, do not remove files]'
    '-n[Remove protected configuration files]'
    '-s[Remove dependencies not required by other packages]'
    '*:installed package:_bauerbill_completions_installed_packages'
)

# options for passing to _arguments: options for --sync command
_bauerbill_opts_sync_actions=(
    '*-c[Remove old packages from cache]:*:clean:->sync_clean'
    '*-cc[Remove all packages from cache]:*:clean:->sync_clean'
    '-g[View all members of a package group]:*:package groups:->sync_group'
    '-s[Search package names and descriptions]:*:search text:->sync_search'
)

# options for passing to _arguments: options for --sync command
_bauerbill_opts_sync_modifiers=(
    '-d[Skip dependency checks]'
    '-f[Overwrite conflicting files]'
    '-i[View package information]'
    '-l[List all packages in a repository]'
    '-p[Print download URIs for each package to be installed]'
    '-u[Upgrade all out-of-date packages]'
    '-w[Download packages only]'
    '-y[Download fresh package databases]'
    '*--ignore[Ignore a package upgrade]:package:
        _bauerbill_completions_all_packages'
    '*--ignoregroup[Ignore a group upgrade]:package group:
        _bauerbill_completions_all_groups'
    '--asdeps[Install packages as non-explicitly installed]'
    '--asexplicit[Install packages as explicitly installed]'
)

# handles --help subcommand
_bauerbill_action_help() {
    _arguments -s : \
        "$_bauerbill_opts_commands[@]"
}

# handles cases where no subcommand has yet been given
_bauerbill_action_none() {
    _arguments -s : \
        "$_bauerbill_opts_commands[@]"
}

# handles --query subcommand
_bauerbill_action_query() {
    local context state line
    typeset -A opt_args
    
#    _arguments -s : \
#        "$_bauerbill_opts_common[@]" \
#        "$_bauerbill_opts_query_actions[@]" \
#        "$_bauerbill_opts_query_modifiers[@]"
        
    case $state in
        query_file)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:package file:_files -g "*.pkg.tar.gz"'
                ;;
        query_group)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:groups:_bauerbill_completions_installed_groups'
                ;;
        query_owner)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:file:_files'
                ;;
        query_search)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:search text: '
                ;;
        *)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_actions[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:package:_bauerbill_completions_installed_packages'
                ;;
    esac
}

# handles --remove subcommand
_bauerbill_action_remove() {
    _arguments -s : \
        "$_bauerbill_opts_common[@]" \
        "$_bauerbill_opts_remove[@]"
}

# handles --sync subcommand
_bauerbill_action_sync() {
    local context state line
    typeset -A opt_args
    
#    _arguments -s : \
#        "$_bauerbill_opts_common[@]" \
#        "$_bauerbill_opts_sync_actions[@]" #\
#        #"$_bauerbill_opts_sync_modifiers[@]"
        
    case $state in
        sync_clean)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_sync_modifiers[@]" \
                '*-c[Remove old packages from cache]' \
                ;;
        sync_group)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_sync_modifiers[@]" \
                '*:package group:_bauerbill_completions_all_groups'
                ;;
        sync_search)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_sync_modifiers[@]" \
                '*:search text: '
                ;;
        *)
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_sync_modifiers[@]" \
                '*:package:_bauerbill_completions_all_packages'
                ;;
        esac
}

# handles --upgrade subcommand
_bauerbill_action_upgrade() {
    _arguments -s : \
        "$_bauerbill_opts_common[@]" \
        "$_bauerbill_opts_pkgfile[@]"
}

# handles --version subcommand
_bauerbill_action_version() {
    # no further arguments
    return 0
}

# provides completions for package groups
_bauerbill_completions_all_groups() {
    local -a cmd groups
    _bauerbill_get_command
    groups=( $(_call_program groups $cmd[@] -Sg) )
    compadd "$@" -a groups
}

# provides completions for packages available from repositories
# these can be specified as either 'package' or 'repository/package'
_bauerbill_completions_all_packages() {
    local -a cmd packages repositories packages_long

    repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
    typeset -U repositories
    packages_long=(/var/lib/pacman/sync/${^repositories}/*(/))
    packages=(${(o)${${packages_long/\/var\/lib\/pacman\/sync\//}#*/}%-*-*} )
    typeset -U packages
    _wanted packages expl "packages" compadd - "${(@)packages}"
    if [[ $PREFIX != */* ]] ; then
        repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
        typeset -U repositories
        _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
    else
        compset -P '*/'
        packages_long=(/var/lib/pacman/sync/$IPREFIX*(/))
        packages=(${(o)${${packages_long/\/var\/lib\/bauerbill\/sync\//}#*/}%-*-*} )
        typeset -U packages
        _wanted repo_packages expl "repository/package" compadd ${(@)packages}
    fi
}

# provides completions for package groups
_bauerbill_completions_installed_groups() {
    local -a cmd groups
    _bauerbill_get_command
    groups=(${(o)${(f)"$(bauerbill -Qg)"}% *})
    typeset -U groups
    compadd "$@" -a groups
}

# provides completions for installed packages
_bauerbill_completions_installed_packages() {
    local -a cmd packages packages_long
    packages_long=(/var/lib/pacman/local/*(/))
    packages=( ${${packages_long/\/var\/lib\/pacman\/local\//}%-*-*} )
    compadd "$@" -a packages
}

# provides completions for repository names
_bauerbill_completions_repositories() {
    local -a cmd repositories
    repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
    # Uniq the array
    typeset -U repositories
    compadd "$@" -a repositories
}

# builds command for invoking bauerbill in a _call_program command - extracts
# relevant options already specified (config file, etc)
# $cmd must be declared by calling function
_bauerbill_get_command() {
    # this is mostly nicked from _perforce
    cmd=( "bauerbill" )
    integer i
    for (( i = 2; i < CURRENT - 1; i++ )); do
        if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
            cmd+=( ${words[i,i+1]} )
        fi
    done
}

# main dispatcher
_bauerbill() {
    case $words[2] in
        -Q*g*) # ipkg groups
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:groups:_bauerbill_completions_installed_groups'
                ;;
        -Q*o*) # file
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:package file:_files'
                ;;
        -Q*p*) # file *.pkg.tar.gz
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_query_modifiers[@]" \
                '*:package file:_files -g "*.pkg.tar.gz"'
                ;;
        -Q*)  _bauerbill_action_query    ;;
        -R*)  _bauerbill_action_remove   ;;
        -S*c*) # no completion
            return 0
            ;;
        -S*l*) # repos
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_sync_modifiers[@]" \
                '*:package repo:_bauerbill_completions_repositories' \
                ;;
        -S*g*) # pkg groups
            _arguments -s : \
                "$_bauerbill_opts_common[@]" \
                "$_bauerbill_opts_sync_modifiers[@]" \
                '*:package group:_bauerbill_completions_all_groups'
                ;;
        -S*)  _bauerbill_action_sync     ;;
        -U*)  _bauerbill_action_upgrade  ;;
        -V*)  _bauerbill_action_version  ;;
        -h*)  _bauerbill_action_help     ;;
        -  )  _bauerbill_action_none     ;;
        *  )  return 1                ;;
    esac
}

# run the main dispatcher
_bauerbill "$@"

Last edited by lucke (2010-01-25 12:17:46)

Offline

Board footer

Powered by FluxBB