Jo, you suggest that supporting version-less packages would be a 
bad idea.  As I said in the original post I am not a big FreeBSD user 
and I don't have enough understanding of the package system to refute 
that claim.

   Having said that I don't think it's unreasonable to want to install 
"whatever version of $PACKAGE is available" and if my DefaultPkgMgr 
is, say, RPM I can do exactly that.  The cfengine reference manual on 
the web gives two examples.  One with explicit versioning as you 
suggest and another without:

     # install new package from FreeBSD ports tree
     control:
       DefaultPkgMgr = ( freebsd )
       FreeBSDInstallCommand = ( "/usr/sbin/pkg_add -r %s" )

     packages:
       bsdsar action=install

   Even assuming that version-less packages are indeed a bad idea and 
that the manual should be changed, attempting to install a package 
without a version number causes a segfault.  That's a bug.

   Looking at the code again I understand why you say that removing 
the pkgversion lines would break things for versioned packages.  So 
how about this.

     pkgversion = strrchr(pkgname, '-');
     if (pkgversion)
        {
        *pkgversion = '\0';
        pkgversion += 1;
        }

   This seems to work if I set PACKAGESITE to .../Latest/:

*********************************************************************
  Main Tree Sched: packages pass 1 @ Thu Mar 13 10:56:39 2008
*********************************************************************

FreeBSDPackageCheck(): Running /usr/sbin/pkg_info -qE 'bash>0'
FreeBSDPackageCheck(): bash gt 0 is installed on this system.
FreeBSDPackageCheck(): Running /usr/sbin/pkg_info -qE 'zsh>0'
FreeBSDPackageCheck(): zsh gt 0 is not installed on this system.
Package manager will be invoked as /usr/bin/env 
ftp_proxy=http://socks:1082 
PACKAGESITE=ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/Latest/
 
/usr/sbin/pkg_add -r
BuildCommandLine(): Adding package 'zsh' to the list.
cfengine:freebsd6: Installing package(s) using '/usr/bin/env 
ftp_proxy=http://socks:1082 
PACKAGESITE=ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/Latest/
 
/usr/sbin/pkg_add -r zsh'
cfengine:freebsd6: Fetching 
ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/Latest/zsh.tbz...Updating
 
/etc/shells
cfengine:freebsd6:  Done.
cfengine:freebsd6: Packages installed: /usr/bin/env 
ftp_proxy=http://socks:1082 
PACKAGESITE=ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/Latest/
 
/usr/sbin/pkg_add -r zsh

   And if I set PACKAGESITE to .../All/ and use a versioned package name:

*********************************************************************
  Main Tree Sched: packages pass 1 @ Thu Mar 13 11:03:45 2008
*********************************************************************

FreeBSDPackageCheck(): Running /usr/sbin/pkg_info -qE 'zsh>0'
FreeBSDPackageCheck(): zsh gt 0 is not installed on this system.
Package manager will be invoked as /usr/bin/env 
ftp_proxy=http://socks:1082 
PACKAGESITE=ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/All/
 
/usr/sbin/pkg_add -r
BuildCommandLine(): Adding package 'zsh-4.3.4_2' to the list.
cfengine:freebsd6: Installing package(s) using '/usr/bin/env 
ftp_proxy=http://socks:1082 
PACKAGESITE=ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/All/
 
/usr/sbin/pkg_add -r zsh-4.3.4_2'
cfengine:freebsd6: Fetching 
ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/All/zsh-4.3.4_2.tbz...Updating
 
/etc/shells
cfengine:freebsd6:  Done.
cfengine:freebsd6: Packages installed: /usr/bin/env 
ftp_proxy=http://socks:1082 
PACKAGESITE=ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/amd64/6.3-RELEASE/packages/All/
 
/usr/sbin/pkg_add -r zsh-4.3.4_2

   However a version-less action=remove fails:

*********************************************************************
  Main Tree Sched: packages pass 1 @ Thu Mar 13 11:05:14 2008
*********************************************************************

FreeBSDPackageCheck(): Running /usr/sbin/pkg_info -qE 'zsh>0'
FreeBSDPackageCheck(): zsh gt 0 is installed on this system.
FreeBSDPackageList(): Running /usr/sbin/pkg_info -E 'zsh=0'
FreeBSDPackageList(): zsh eq 0 is not installed on this system.
Package manager will be invoked as /usr/sbin/pkg_delete
BuildCommandLine(): Adding package 'zsh' to the list.
cfengine:freebsd6: Removing package(s) using '/usr/sbin/pkg_delete zsh'
cfengine:freebsd6: pkg_delete: no such package 'zsh' installed
cfengine:freebsd6:
cfengine:freebsd6: Could not execute package removal command 
/usr/sbin/pkg_delete zsh

   A versioned action=remove does work:

*********************************************************************
  Main Tree Sched: packages pass 1 @ Thu Mar 13 11:06:49 2008
*********************************************************************

FreeBSDPackageCheck(): Running /usr/sbin/pkg_info -qE 'zsh>0'
FreeBSDPackageCheck(): zsh gt 0 is installed on this system.
FreeBSDPackageList(): Running /usr/sbin/pkg_info -E 'zsh=0'
FreeBSDPackageList(): zsh eq 0 is not installed on this system.
Package manager will be invoked as /usr/sbin/pkg_delete
BuildCommandLine(): Adding package 'zsh-4.3.4_2' to the list.
cfengine:freebsd6: Removing package(s) using '/usr/sbin/pkg_delete 
zsh-4.3.4_2'
cfengine:freebsd6: Updating /etc/shells
cfengine:freebsd6:
cfengine:freebsd6: Package removal succeeded (/usr/sbin/pkg_delete 
zsh-4.3.4_2)

   So it's not perfect but better than crashing.  We could always add 
"else /* print some error */" after the check for validity of the 
pkgversion pointer.
_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine

Reply via email to