2006-07-12 22:21:42 -04:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# pkg-get - A binary package management utility for CRUX Linux
|
2013-08-20 07:00:26 -04:00
|
|
|
# Copyright (C) 2004-2006 Simone Rota <sip@varlock.com>
|
2023-06-18 18:25:55 -04:00
|
|
|
# Copyright (C) 2006-2023 by CRUX team (http://crux.nu)
|
2006-07-12 22:21:42 -04:00
|
|
|
#
|
|
|
|
# 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 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
2023-06-17 11:24:34 -04:00
|
|
|
use Digest::file qw(digest_file_hex);
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
my $VERSION = "0.4.8";
|
2006-07-12 22:21:42 -04:00
|
|
|
my $CFGFILE = "/etc/pkg-get.conf";
|
|
|
|
my $LOCKFILE = "/var/lib/pkg/pkg-get.locker";
|
|
|
|
my $PKGDB = "/var/lib/pkg/db" ;
|
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
$SIG{HUP} = \&trap; $SIG{INT} = \&trap;
|
|
|
|
$SIG{QUIT} = \&trap; $SIG{TERM} = \&trap;
|
2006-07-12 22:21:42 -04:00
|
|
|
|
|
|
|
# Global vars
|
|
|
|
my @repos = (); # package repositories
|
|
|
|
my @donetasks; my @failtasks; my @prevtasks; my %pptasks; my %readmetasks;
|
2023-06-17 11:24:34 -04:00
|
|
|
my $curraction = ""; my %deps; my @dependencies; my %missingdeps;
|
|
|
|
my %locked; my %installed;
|
2006-07-12 22:21:42 -04:00
|
|
|
|
|
|
|
# CL Options
|
|
|
|
my $download_only; my $pre_install; my $post_install;
|
|
|
|
my $install_scripts; my $filter = ""; my $all; my $unused;
|
|
|
|
my $aargs=""; my $ignore_md5sum; my $force; my $root;
|
|
|
|
GetOptions("do"=>\$download_only,
|
2023-06-17 11:24:34 -04:00
|
|
|
"pre-install"=>\$pre_install, "post-install"=>\$post_install,
|
|
|
|
"install-scripts"=>\$install_scripts, "all"=>\$all,
|
|
|
|
"filter=s"=>\$filter, "config=s"=>\$CFGFILE, "aargs=s"=>\$aargs,
|
|
|
|
"f"=>\$force, "im"=>\$ignore_md5sum, "margs=s"=>\$unused,
|
|
|
|
"rargs=s"=>\$unused, "r=s"=>\$root);
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2013-07-04 11:39:58 -04:00
|
|
|
# use compression-mode defined in pkgmk.conf
|
|
|
|
our $compress = "gz";
|
|
|
|
open CONFIG, "/etc/pkgmk.conf" or die "Could not open /etc/pkgmk.conf";
|
|
|
|
while (<CONFIG>) {
|
2023-06-17 11:24:34 -04:00
|
|
|
$compress = $1 if m/^PKGMK_COMPRESSION_MODE=(.*)(#|$)/;
|
2013-07-04 11:39:58 -04:00
|
|
|
}
|
|
|
|
close CONFIG;
|
2023-06-17 11:24:34 -04:00
|
|
|
$compress =~ s/['" ]//g;
|
2013-07-04 11:39:58 -04:00
|
|
|
|
2006-07-12 22:21:42 -04:00
|
|
|
if ($root) {
|
2023-06-17 11:24:34 -04:00
|
|
|
$LOCKFILE = $root.$LOCKFILE ;
|
|
|
|
$PKGDB = $root.$PKGDB;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get command, verify it's valid
|
|
|
|
my $command = getcommand(@ARGV);
|
|
|
|
if (index($command,"Error: ") eq 0 ) {
|
2023-06-17 11:24:34 -04:00
|
|
|
$command =~ s/Error\: //;
|
|
|
|
exiterr($command);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
2023-06-19 14:25:42 -04:00
|
|
|
|
2006-07-12 22:21:42 -04:00
|
|
|
readconfig();
|
2023-06-19 14:25:42 -04:00
|
|
|
get_locked() unless ($command =~
|
|
|
|
/^(info|help|readme|search|dsearch|list|path|depend|current|isinst)$/);
|
2006-07-12 22:21:42 -04:00
|
|
|
|
|
|
|
SWITCH: {
|
2023-06-17 11:24:34 -04:00
|
|
|
if ($command eq "version") { version(); last SWITCH; }
|
|
|
|
if ($command eq "sync") { sync(); last SWITCH; }
|
2023-06-21 04:59:50 -04:00
|
|
|
if ($command =~ /^(info|path|readme)$/) { info($1); last SWITCH; }
|
2023-06-17 11:24:34 -04:00
|
|
|
if ($command eq "help") { help(); last SWITCH; }
|
|
|
|
if ($command =~ /^(d|)search$/) { search(); last SWITCH; }
|
|
|
|
if ($command eq "list") { list(); last SWITCH; }
|
|
|
|
if ($command eq "remove") { remove(); last SWITCH; }
|
|
|
|
if ($command eq "listinst") { listinst(); last SWITCH; }
|
|
|
|
if ($command eq "lock") { dolock(); last SWITCH; }
|
|
|
|
if ($command eq "unlock") { unlock(); last SWITCH; }
|
|
|
|
if ($command eq "listlocked") { listlocked(); last SWITCH; }
|
|
|
|
if ($command eq "printf") { doprintf(); last SWITCH; }
|
|
|
|
if ($command =~ /^(isinst|current)$/) { current(); last SWITCH; }
|
2023-06-18 18:25:55 -04:00
|
|
|
if ($command =~ /^(diff|quickdiff|sysup)$/) { diff($1); last SWITCH; }
|
2023-06-17 11:24:34 -04:00
|
|
|
if ($command eq "dup") { dup(); last SWITCH; }
|
|
|
|
if ($command =~ /^(depends|quickdep)$/) { depends(); last SWITCH; }
|
|
|
|
if ($command =~ /^(install|update)$/) { upinst(@ARGV); last SWITCH; }
|
|
|
|
if ($command eq "dependent") { dependent(); last SWITCH; }
|
|
|
|
if ($command eq "depinst") { depinst(); last SWITCH; }
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Support functions
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
# Exit with error
|
|
|
|
sub exiterr {
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($msg) = @_;
|
|
|
|
print "pkg-get: $msg\n";
|
|
|
|
exit 1;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub trap {
|
2023-06-17 11:24:34 -04:00
|
|
|
printresults(1);
|
|
|
|
die("\npkg-get: interrupted\n");
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get command, return an error if not in the list of allowed commands
|
|
|
|
sub getcommand {
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($givencmd, $givenarg) = @_;
|
|
|
|
if (not $givenarg){$givenarg = ""};
|
|
|
|
if (not $givencmd){
|
|
|
|
return "Error: no command given. try pkg-get help for more information";
|
|
|
|
}
|
|
|
|
|
|
|
|
my @allowed = ("depinst:", "install:", "sysup", "diff", "update:",
|
|
|
|
"depends:", "info:", "sync", "version", "help",
|
|
|
|
"quickdep:", "dependent:", "list", "listinst", "isinst:",
|
|
|
|
"search:", "dsearch:", "lock:", "unlock:", "listlocked",
|
|
|
|
"quickdiff", "printf:", "remove:", "readme:", "dup",
|
|
|
|
"path:", "current:");
|
|
|
|
|
|
|
|
(grep { ($_ eq $givencmd) } @allowed)
|
|
|
|
or ((grep { ($_ eq "${givencmd}:") } @allowed) and ($givenarg ne ""))
|
|
|
|
or return "Error: improper command '$givencmd $givenarg'. Try pkg-get help for more information";
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
return $givencmd;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
# Parse the configuration file
|
2006-07-12 22:21:42 -04:00
|
|
|
sub readconfig {
|
2023-06-17 11:24:34 -04:00
|
|
|
open(CFG, $CFGFILE)
|
|
|
|
or exiterr("could not open $CFGFILE");
|
|
|
|
while (<CFG>) {
|
|
|
|
chomp;
|
|
|
|
if ( /^pkgdir\s+/ ) {
|
|
|
|
my $repo = $_;
|
|
|
|
$repo =~ s/^pkgdir\s+//;
|
|
|
|
$repo =~ s/#.*$//;
|
|
|
|
$repo =~ s/\s+$//;
|
|
|
|
push @repos, $repo;
|
|
|
|
} elsif (/^runscripts\s+/) {
|
|
|
|
my $rs = $_;
|
|
|
|
$rs =~ s/^runscripts\s+//;
|
|
|
|
$rs =~ s/#.*$//;
|
|
|
|
$rs =~ s/\s+$//;
|
|
|
|
if ($rs eq "yes") {$install_scripts = 1};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(CFG);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Populate a hash of locked packages
|
|
|
|
sub get_locked {
|
|
|
|
open (my $fL, $LOCKFILE) or return;
|
|
|
|
while (<$fL>) { $locked{$_} = 1; }
|
|
|
|
close ($fL);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Parse a line describing a package
|
|
|
|
sub parsepackage {
|
2023-06-17 11:24:34 -04:00
|
|
|
my @p = split(/\:/, $_[0]);
|
2023-06-21 04:59:50 -04:00
|
|
|
if ($#p < 6) {exiterr("$_[1]/PKGREPO appears to be in wrong format!\nAborting.")};
|
|
|
|
my %pkg = ( 'name' => $p[0], 'version' => $p[0], 'release' => $p[0] );
|
|
|
|
$pkg{'name'} =~ s/\#.*//;
|
|
|
|
$pkg{'version'} =~ s/.*\#//;
|
|
|
|
$pkg{'version'} =~ s/-\w*\.pkg\.tar.*//;
|
2023-06-19 14:25:42 -04:00
|
|
|
$pkg{'release'} =~ s/^.*-//;
|
2023-06-21 04:59:50 -04:00
|
|
|
$pkg{'release'} =~ s/\.pkg\.tar.*//;
|
2023-06-19 14:25:42 -04:00
|
|
|
if (not $_[2]) {$_[2] = $_[1]};
|
2023-06-17 11:24:34 -04:00
|
|
|
$pkg{'path'} = $_[1];
|
2023-06-19 14:25:42 -04:00
|
|
|
$pkg{'url'} = $_[2];
|
|
|
|
$pkg{'url'} =~ s/\/$//;
|
|
|
|
$pkg{'url'} .= "/$p[0]";
|
2023-06-17 11:24:34 -04:00
|
|
|
$pkg{'size'} = $p[1];
|
|
|
|
$pkg{'md5sum'} = $p[2];
|
|
|
|
$pkg{'description'} = $p[3];
|
|
|
|
$pkg{'pre_install'} = $p[4];
|
|
|
|
$pkg{'post_install'} = $p[5];
|
|
|
|
$pkg{'readme'} = $p[6];
|
|
|
|
return %pkg;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Parse a line describing a package (just the name)
|
|
|
|
sub parsepackagelight {
|
2023-06-17 11:24:34 -04:00
|
|
|
my @p = split(/\:/, $_[0]);
|
2023-06-21 04:59:50 -04:00
|
|
|
if ($#p < 6) {exiterr("$_[1]/PKGREPO appears to be in wrong format!\nAborting.")};
|
2023-06-17 11:24:34 -04:00
|
|
|
my %pkg;
|
2023-06-19 14:25:42 -04:00
|
|
|
$pkg{'name'} = $1 if ($p[0] =~ m/^(.*)\#/);
|
2023-06-17 11:24:34 -04:00
|
|
|
return %pkg;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Print info about the given package
|
|
|
|
sub printinfo {
|
2023-06-17 11:24:34 -04:00
|
|
|
my %pkg = @_;
|
|
|
|
print "Name : " . $pkg{'name'} . "\n";
|
|
|
|
print "Version : " . $pkg{'version'} . "\n";
|
|
|
|
print "Release : " . $pkg{'release'} . "\n";
|
|
|
|
print "Description : " . $pkg{'description'} . "\n";
|
|
|
|
print "URL : " . $pkg{'url'} . "\n";
|
|
|
|
print "Md5sum : " . $pkg{'md5sum'} . "\n";
|
|
|
|
print "Size : " . $pkg{'size'} . "\n";
|
|
|
|
my $deps = getdirectdeps($pkg{'name'}, $pkg{'path'});
|
|
|
|
if ($deps ne "") { print "Depends on : $deps\n";};
|
|
|
|
my $files = "";
|
|
|
|
if ($pkg{'readme'} eq "yes") {$files .= "README,"};
|
|
|
|
if ($pkg{'pre_install'} eq "yes") {$files .= "pre-install,"};
|
|
|
|
if ($pkg{'post_install'} eq "yes") {$files .= "post-install,"};
|
|
|
|
$files =~ s/\,$//;
|
|
|
|
if ($files ne "") { print "Files : $files\n";};
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get direct dependencies for package
|
|
|
|
sub getdirectdeps {
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($pkgname, $dir) = @_;
|
|
|
|
open(DEPS, "$dir/PKGDEPS")
|
|
|
|
or exiterr("could not open $dir/PKGDEPS");
|
|
|
|
while (<DEPS>) {
|
|
|
|
chomp;
|
|
|
|
if ( /^\Q$pkgname\E\s+/ ) {
|
|
|
|
my $dep = $_;
|
|
|
|
$dep =~ s/^.*\: //;
|
|
|
|
close(DEPS);
|
|
|
|
return $dep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(DEPS);
|
|
|
|
return "";
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Prints the README file to stdout
|
|
|
|
sub printreadme {
|
2023-06-17 11:24:34 -04:00
|
|
|
my %pkg = @_;
|
|
|
|
my ($found, $finished) = (0, 0);
|
|
|
|
open(READ, "$pkg{'path'}/PKGREAD")
|
|
|
|
or exiterr("could not open $pkg{'path'}/PKGREAD");
|
|
|
|
while (<READ>) {
|
|
|
|
chomp;
|
2023-06-19 14:25:42 -04:00
|
|
|
if (($found == 1) and ( /PKGREADME\:/ )) {
|
2023-06-17 11:24:34 -04:00
|
|
|
$finished = 1;
|
2023-06-19 14:25:42 -04:00
|
|
|
} elsif ($found == 1) {
|
2023-06-17 11:24:34 -04:00
|
|
|
print "$_\n";
|
2023-06-21 04:59:50 -04:00
|
|
|
} elsif ( /PKGREADME\: $pkg{'name'}$/ ) {
|
2023-06-17 11:24:34 -04:00
|
|
|
$found = 1;
|
|
|
|
}
|
2023-06-21 04:59:50 -04:00
|
|
|
last if ($finished == 1);
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
|
|
|
close(READ);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Print results for multiple package operations
|
|
|
|
sub printresults {
|
2023-06-17 11:24:34 -04:00
|
|
|
my $okaction = $curraction;
|
|
|
|
my $curr = "";
|
2023-06-19 14:25:42 -04:00
|
|
|
my $action;
|
|
|
|
my $pkg;
|
2023-06-17 11:24:34 -04:00
|
|
|
my @readme;
|
|
|
|
my $goterror = 0;
|
|
|
|
if (@donetasks) {
|
|
|
|
print "\n-- Packages $okaction\n";
|
|
|
|
foreach my $task(@donetasks) {
|
|
|
|
if ($readmetasks{$task}) {push(@readme, $task)}
|
|
|
|
print "$task" . $pptasks{$task}."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (@prevtasks) {
|
|
|
|
if ($okaction eq "installed") {
|
|
|
|
print "\n-- Packages installed before this run (ignored)\n";
|
|
|
|
} else {
|
|
|
|
print "\n-- Packages not previously installed (ignored)\n";
|
|
|
|
}
|
|
|
|
foreach my $task(@prevtasks) { print "$task\n"; }
|
|
|
|
}
|
|
|
|
if (@failtasks) {
|
|
|
|
foreach my $task(sort @failtasks) {
|
|
|
|
($action, $pkg) = split(/,/,$task);
|
|
|
|
if ($curr ne $action) {
|
|
|
|
print "\n-- Packages $action\n";
|
|
|
|
$curr = $action;
|
|
|
|
}
|
|
|
|
print "$pkg\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (@readme) {
|
|
|
|
print "\n-- $okaction packages with README file\n";
|
|
|
|
foreach my $task(@readme) {
|
|
|
|
print "$task" . $pptasks{$task}."\n";
|
|
|
|
}
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
if(@donetasks and not @failtasks and not $_[0]) {
|
2023-06-17 11:24:34 -04:00
|
|
|
print "\npkg-get: $okaction successfully\n"
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get the list of installed packages
|
|
|
|
sub getinstalled {
|
2023-06-17 11:24:34 -04:00
|
|
|
local $/ = ""; # read files paragraph-wise; see ``perldoc perlvar''
|
|
|
|
open(DB, $PKGDB)
|
|
|
|
or exiterr("could not open ".$PKGDB);
|
|
|
|
while (<DB>) {
|
|
|
|
my ($name, $version, @files) = split /\n/, $_;
|
|
|
|
$installed{$name} = $version;
|
|
|
|
}
|
|
|
|
close(DB);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
# Print formatted info for given package
|
2006-07-12 22:21:42 -04:00
|
|
|
sub formattedprint {
|
2023-06-17 11:24:34 -04:00
|
|
|
my %pkg = @_;
|
|
|
|
my $fmt = $ARGV[1];
|
|
|
|
$fmt =~ s|%n|$pkg{'name'}|;
|
|
|
|
$fmt =~ s|%p|$pkg{'path'}|;
|
|
|
|
$fmt =~ s|%v|$pkg{'version'}|;
|
|
|
|
$fmt =~ s|%r|$pkg{'release'}|;
|
|
|
|
$fmt =~ s|%d|$pkg{'description'}|;
|
|
|
|
$fmt =~ s|%u|$pkg{'url'}|;
|
|
|
|
$fmt =~ s|%R|$pkg{'readme'}|;
|
|
|
|
$fmt =~ s|%E|$pkg{'pre_install'}|;
|
|
|
|
$fmt =~ s|%O|$pkg{'post_install'}|;
|
2023-06-21 04:59:50 -04:00
|
|
|
$fmt =~ s|%M|None|; # for prt-get compatibility
|
2023-06-17 11:24:34 -04:00
|
|
|
$fmt =~ s|%P|None|; # for prt-get compatibility
|
|
|
|
$fmt =~ s|\\n|\n|;
|
|
|
|
$fmt =~ s|\\t|\t|;
|
|
|
|
if (index($fmt,"%e") >=0) {
|
|
|
|
my $deps = getdirectdeps($pkg{'name'}, $pkg{'path'});
|
|
|
|
$fmt =~ s|%e|$deps|;
|
|
|
|
}
|
|
|
|
if (index($fmt,"%l") >=0) {
|
|
|
|
my $locked = ($locked{$pkg{'name'}}) ? "yes" : "no";
|
|
|
|
$fmt =~ s|%l|$locked|;
|
|
|
|
}
|
|
|
|
if (index($fmt,"%i") >=0) {
|
2023-06-21 04:59:50 -04:00
|
|
|
(%installed) or getinstalled();
|
|
|
|
my $inst = ($installed{$pkg{'name'}}) ? "yes" : "no";
|
|
|
|
($inst eq "no") or
|
|
|
|
($installed{$pkg{'name'}} eq "$pkg{'version'}-$pkg{'release'}")
|
|
|
|
or $inst = "diff";
|
2023-06-17 11:24:34 -04:00
|
|
|
$fmt =~ s|%i|$inst|;
|
|
|
|
}
|
|
|
|
print "$fmt";
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get package from the repo(s)
|
|
|
|
sub getpackage {
|
2023-06-21 04:59:50 -04:00
|
|
|
my $pkgname = $_[0];
|
|
|
|
my $found; my @maybe; my %repver; my %res;
|
2023-06-17 11:24:34 -04:00
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = parsepackage($_, $dir, $url);
|
|
|
|
next if ($pkg{'name'} ne $pkgname);
|
|
|
|
$found = 1;
|
|
|
|
push @maybe, join("^", $pkg{'path'}, $pkg{'url'},
|
|
|
|
$pkg{'version'}, $pkg{'release'}, $pkg{'description'},
|
|
|
|
$pkg{'md5sum'}, $pkg{'size'},
|
|
|
|
$pkg{'pre_install'}, $pkg{'post_install'}, $pkg{'readme'});
|
|
|
|
( ($repver{$pkgname}) and
|
|
|
|
($repver{$pkgname} gt "$pkg{'version'}-$pkg{'release'}") )
|
|
|
|
or $repver{$pkgname} = "$pkg{'version'}-$pkg{'release'}";
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
|
|
|
close (REPO);
|
2023-06-21 04:59:50 -04:00
|
|
|
while (my $match = shift @maybe) {
|
|
|
|
my ($p,$u,$v,$r,$d,$m,$s,$E,$O,$R) = split /\^/, $match;
|
|
|
|
next if ("$v-$r" lt $repver{$pkgname});
|
|
|
|
%res = ('name' => $pkgname, 'path' => $p,
|
|
|
|
'url' => $u, 'version' => $v, 'release' => $r,
|
|
|
|
'description' => $d, 'md5sum' => $m, 'size' => $s,
|
|
|
|
'pre_install' => $E, 'post_install' => $O, 'readme' => $R);
|
|
|
|
}
|
|
|
|
last if ($found);
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
|
|
|
return %res;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get short status for package, e.g. [i]
|
2006-07-12 22:21:42 -04:00
|
|
|
sub getshortstatus {
|
2023-06-17 11:24:34 -04:00
|
|
|
my %pkg = @_;
|
2023-06-21 04:59:50 -04:00
|
|
|
($installed{$pkg{'name'}}) or return "[ ]";
|
|
|
|
($installed{$pkg{'name'}} =~ /^$pkg{'version'}-$pkg{'release'}/) or return "[u]";
|
|
|
|
return "[i]";
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get (recursive) dependencies for pkgname
|
|
|
|
sub getdependencies {
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($pkgname, $checkver, $pkgparent) = @_;
|
|
|
|
my $depstring = "";
|
2023-06-19 14:25:42 -04:00
|
|
|
|
|
|
|
# no need to continue if there's already a value for this key
|
|
|
|
return if ($deps{$pkgname});
|
|
|
|
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = getpackage($pkgname);
|
2023-06-19 14:25:42 -04:00
|
|
|
if (%pkg) {
|
|
|
|
my $ddeps = getdirectdeps($pkg{'name'}, $pkg{'path'});
|
|
|
|
my @d = split(/,/, $ddeps);
|
|
|
|
foreach my $dep(@d) {
|
|
|
|
getdependencies($dep, $checkver, $pkgname);
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-19 14:25:42 -04:00
|
|
|
$depstring = getshortstatus(%pkg)." " if ($checkver);
|
|
|
|
$depstring .= $pkgname;
|
|
|
|
$deps{$pkgname} = $depstring;
|
|
|
|
push(@dependencies, $depstring);
|
|
|
|
} else {
|
|
|
|
return 0 if ($pkgparent eq "");
|
|
|
|
$missingdeps{$pkgname} = $pkgparent;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Download given package (if needed), check md5sum
|
|
|
|
sub downloadpkg {
|
2023-06-17 11:24:34 -04:00
|
|
|
my %pkg = @_;
|
|
|
|
my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.$compress";
|
|
|
|
if (-f $fullpath) {
|
|
|
|
my $md5 = digest_file_hex($fullpath,"MD5");
|
|
|
|
if ($md5 ne $pkg{'md5sum'} and not $ignore_md5sum) {
|
|
|
|
print STDERR "=======> ERROR: md5sum mismatch for $pkg{'name'}:\n";
|
|
|
|
print STDERR "required : $pkg{'md5sum'}\n";
|
|
|
|
print STDERR "found : $md5\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} else {
|
2023-06-19 14:25:42 -04:00
|
|
|
return 1 if ($pkg{'url'} eq ""); # repo is local and pkg does not exist
|
2023-06-17 11:24:34 -04:00
|
|
|
my $url = $pkg{'url'};
|
|
|
|
$url =~ s/\#/\%23/;
|
|
|
|
system ("curl --retry 3 --retry-delay 3 -o $fullpath $url") == 0 or return 0;
|
|
|
|
my $md5 = digest_file_hex($fullpath,"MD5");
|
|
|
|
if ($md5 ne $pkg{'md5sum'} and not $ignore_md5sum) {
|
|
|
|
print STDERR "=======> ERROR: md5sum mismatch for $pkg{'name'}:\n";
|
|
|
|
print STDERR "required : $pkg{'md5sum'}\n";
|
|
|
|
print STDERR "found : $md5\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Install given package
|
|
|
|
sub installpkg {
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($upgrade, %pkg) = @_;
|
|
|
|
my $aa = $aargs." ";
|
|
|
|
if ($pkg{'readme'} eq "yes") {$readmetasks{$pkg{'name'}} = 1};
|
|
|
|
$pptasks{$pkg{'name'}} = "";
|
|
|
|
if ($download_only) {return 1;}
|
|
|
|
if ($force){$aa = $aa."-f ";}
|
2023-06-18 18:25:55 -04:00
|
|
|
if ($root) {
|
2023-06-19 14:25:42 -04:00
|
|
|
$aa = $aa."-r ".$root." ";
|
2023-06-18 18:25:55 -04:00
|
|
|
(-f "$root/$pkg{'path'}/PKGINST") or
|
|
|
|
system("install -D $pkg{'path'}/PKGINST $root/$pkg{'path'}/PKGINST")
|
2023-06-19 14:25:42 -04:00
|
|
|
or die "Failed to copy PKGINST to $root, aborting.\n";
|
2023-06-18 18:25:55 -04:00
|
|
|
}
|
2023-06-17 11:24:34 -04:00
|
|
|
if ($pkg{'pre_install'} eq "yes" and ($install_scripts or $pre_install)) {doscript("pre",%pkg);}
|
|
|
|
my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.$compress";
|
|
|
|
print "pkg-get: /usr/bin/pkgadd $upgrade $aa$fullpath\n";
|
|
|
|
system ("/usr/bin/pkgadd $upgrade $aa$fullpath") == 0 or return 0;
|
|
|
|
if ($pkg{'post_install'} eq "yes" and ($install_scripts or $post_install)) {doscript("post",%pkg);}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute pre- or post-install script
|
|
|
|
sub doscript {
|
|
|
|
my ($when, %pkg) = @_;
|
|
|
|
my $cmd = ($root) ? "chroot $root " : "";
|
2023-06-18 18:25:55 -04:00
|
|
|
$cmd .= "/bin/bash $pkg{'path'}/PKGINST $pkg{'name'} $when";
|
2023-06-17 11:24:34 -04:00
|
|
|
if (system($cmd) == 0) {
|
|
|
|
$pptasks{$pkg{'name'}} .= " [$when: ok]";
|
|
|
|
} else {
|
|
|
|
$pptasks{$pkg{'name'}} .= " [$when: failed]";
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Main functions (commands)
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
# No pun intended ##########################################################
|
|
|
|
sub version {
|
2023-06-17 11:24:34 -04:00
|
|
|
print "pkg-get $VERSION ";
|
|
|
|
print "by Simone Rota <sip\@varlock.com>\n";
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Show brief help ##########################################################
|
|
|
|
sub help {
|
2023-06-17 11:24:34 -04:00
|
|
|
print "Usage: pkg-get command <package1> [package2 ... packageN] [options]
|
2006-07-12 22:21:42 -04:00
|
|
|
|
|
|
|
Some command:
|
|
|
|
sync synchronize with the repository
|
2023-06-17 11:24:34 -04:00
|
|
|
depinst install package and its dependencies
|
2006-07-12 22:21:42 -04:00
|
|
|
info info about package
|
2023-06-17 11:24:34 -04:00
|
|
|
sysup update all outdated packages
|
2006-07-12 22:21:42 -04:00
|
|
|
diff list all outdated packages
|
|
|
|
|
|
|
|
Some option:
|
|
|
|
-do download only
|
|
|
|
--install-scripts use install scripts
|
|
|
|
-r <root> use <root> for pkgadd
|
|
|
|
|
|
|
|
Example:
|
|
|
|
pkg-get install sqlite pysqlite
|
|
|
|
|
|
|
|
For other commands and samples, see the pkg-get(8) man page\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sync with the remote server(s) ###########################################
|
|
|
|
sub sync {
|
2023-06-17 11:24:34 -04:00
|
|
|
my $dlerror = 0;
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
next if (not $url);
|
|
|
|
print "Updating collection $dir\n";
|
|
|
|
(-d $dir) or mkdir($dir) or exiterr("cannot create $dir");
|
|
|
|
for my $f ("PKGREPO", "PKGDEPS", "PKGREAD", "PKGINST") {
|
|
|
|
(! -f "$dir/$f") or rename("$dir/$f", "$dir/$f.old") or exiterr("cannot write to $dir");
|
|
|
|
if (system("curl -s --output-dir $dir -o $f $url/$f") != 0) {
|
|
|
|
print " cannot retrieve $f\n";
|
|
|
|
$dlerror=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($dlerror) { # restore backup repo
|
|
|
|
for my $f ("PKGREPO", "PKGDEPS", "PKGREAD", "PKGINST") {
|
|
|
|
(! -f "$dir/$f.old") or rename("$dir/$f.old", "$dir/$f") or exiterr("cannot write to $dir");
|
|
|
|
}
|
|
|
|
} else { # remove backup repo
|
|
|
|
for my $f ("PKGREPO", "PKGDEPS", "PKGREAD", "PKGINST") {
|
|
|
|
(! -f "$dir/$f.old") or unlink("$dir/$f.old") or exiterr("cannot write to $dir");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# Show info/path/readme for the package ####################################
|
2006-07-12 22:21:42 -04:00
|
|
|
sub info {
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($type, $arg) = @ARGV;
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = parsepackage($_, $dir, $url);
|
2023-06-17 11:24:34 -04:00
|
|
|
if ($pkg{'name'} eq $arg) {
|
2023-06-19 14:25:42 -04:00
|
|
|
($type ne "info") or printinfo(%pkg);
|
|
|
|
($type ne "readme") or printreadme(%pkg);
|
|
|
|
($type ne "path") or print $pkg{'path'} . "\n";
|
2023-06-17 11:24:34 -04:00
|
|
|
close(REPO); return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(REPO);
|
|
|
|
}
|
|
|
|
print "Package '$arg' not found\n";
|
|
|
|
}
|
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# List packages containing given string (name/description) #################
|
2006-07-12 22:21:42 -04:00
|
|
|
sub search {
|
2023-06-17 11:24:34 -04:00
|
|
|
my $arg = $ARGV[1];
|
|
|
|
my $type = ($ARGV[0] =~ /^d/) ? "desc" : "name";
|
|
|
|
my %found;
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = parsepackage($_, $dir, $url);
|
2023-06-17 11:24:34 -04:00
|
|
|
next if ($found{$pkg{'name'}});
|
2023-06-19 14:25:42 -04:00
|
|
|
(index($pkg{'name'}, $arg) < 0) or $found{$pkg{'name'}} = 1;
|
2023-06-21 04:59:50 -04:00
|
|
|
($found{$pkg{'name'}}==1) or ($type ne "desc")
|
2023-06-19 14:25:42 -04:00
|
|
|
or (index($pkg{'description'}, $arg) < 0)
|
|
|
|
or $found{$pkg{'name'}} = 1;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
|
|
|
close(REPO);
|
|
|
|
}
|
|
|
|
foreach my $key (sort keys %found) { print "$key\n"; }
|
|
|
|
if (not %found) { print "No matching packages found\n"; }
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# List all available packages ##############################################
|
|
|
|
sub list {
|
2023-06-17 11:24:34 -04:00
|
|
|
my $arg = $ARGV[1];
|
|
|
|
my %found;
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = parsepackage($_, $dir, $url);
|
2023-06-17 11:24:34 -04:00
|
|
|
$found{$pkg{'name'}} = 1;
|
|
|
|
}
|
|
|
|
close(REPO);
|
|
|
|
}
|
|
|
|
foreach my $key (sort keys %found) { print "$key\n"; }
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Remove given packages ####################################################
|
|
|
|
sub remove {
|
2023-06-17 11:24:34 -04:00
|
|
|
$curraction = "removed";
|
|
|
|
shift(@ARGV);
|
|
|
|
my $cmd = "/usr/bin/pkgrm";
|
|
|
|
$cmd .= " -r $root" if ($root);
|
|
|
|
foreach my $pkg(@ARGV) {
|
|
|
|
$pptasks{$pkg} = "";
|
|
|
|
if (system("$cmd $pkg")==0) {
|
|
|
|
push(@donetasks, $pkg);
|
|
|
|
} else {
|
|
|
|
push(@failtasks, "where removal failed,$pkg");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printresults();
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# List installed packages ##################################################
|
|
|
|
sub listinst {
|
2023-06-17 11:24:34 -04:00
|
|
|
getinstalled() if (! %installed);
|
|
|
|
foreach my $key (sort keys %installed) { print "$key\n"; }
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
# Print package version, or install status #################################
|
|
|
|
sub current {
|
|
|
|
getinstalled() if (! %installed);
|
|
|
|
my $type = shift(@ARGV); my $result;
|
|
|
|
foreach my $pkg(@ARGV) {
|
|
|
|
if ($installed{$pkg}) {
|
|
|
|
$result = ($type eq "current") ? ": version $installed{$pkg}\n"
|
|
|
|
: " is installed\n";
|
|
|
|
} else {
|
|
|
|
$result = " not installed\n";
|
|
|
|
}
|
|
|
|
print "Package " . $pkg . $result;
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Lock given packages ######################################################
|
|
|
|
sub dolock {
|
2023-06-17 11:24:34 -04:00
|
|
|
shift(@ARGV);
|
|
|
|
foreach my $arg(@ARGV) {
|
|
|
|
if ($locked{$arg}) {
|
2023-06-19 14:25:42 -04:00
|
|
|
print "Already locked: $arg\n"; next;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
|
|
|
my $found = 0;
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
|
|
|
my %pkg = parsepackagelight($_);
|
|
|
|
if ($pkg{'name'} eq $arg) {
|
|
|
|
$found = 1;
|
|
|
|
open(LCK, ">> $LOCKFILE")
|
2023-06-19 14:25:42 -04:00
|
|
|
or exiterr("could not write to lock file");
|
2023-06-17 11:24:34 -04:00
|
|
|
print LCK "$arg\n";
|
|
|
|
close(LCK);
|
|
|
|
}
|
|
|
|
last if ($found);
|
|
|
|
}
|
|
|
|
close(REPO);
|
|
|
|
last if ($found);
|
|
|
|
}
|
|
|
|
if ($found == 0) {print "Package '$arg' not found\n"};
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Unlock given packages ####################################################
|
|
|
|
sub unlock {
|
2023-06-17 11:24:34 -04:00
|
|
|
shift(@ARGV);
|
|
|
|
foreach my $arg(@ARGV) {
|
|
|
|
if (! $locked{$arg}) {
|
|
|
|
print "Not locked previously: $arg\n"; next;
|
|
|
|
} else {
|
|
|
|
delete $locked{$arg};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
open(my $fL, ">$LOCKFILE") or exiterr("could not write to lock file");
|
|
|
|
foreach (sort keys %locked) { print $fL "$_\n"; }
|
|
|
|
close($fL);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# List locked packages #####################################################
|
|
|
|
sub listlocked {
|
2023-06-17 11:24:34 -04:00
|
|
|
foreach (sort keys %locked) { print "$_\n"; }
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Print formatted info #####################################################
|
|
|
|
sub doprintf {
|
2023-06-21 04:59:50 -04:00
|
|
|
my %repver; my %found;
|
2023-06-17 11:24:34 -04:00
|
|
|
foreach my $repo(@repos) {
|
2023-06-21 04:59:50 -04:00
|
|
|
my @toprint=();
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = parsepackage($_, $dir, $url);
|
|
|
|
next if ($found{$pkg{'name'}});
|
|
|
|
(! $filter) or $filter =~ s/\*/\.\*/;
|
|
|
|
if (($filter) and ($pkg{'name'} !~ /^$filter$/)) {
|
|
|
|
$found{$pkg{'name'}} = 1; next;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-21 04:59:50 -04:00
|
|
|
|
|
|
|
push @toprint, join("^", $pkg{'name'}, $pkg{'path'}, $pkg{'url'},
|
|
|
|
$pkg{'version'}, $pkg{'release'}, $pkg{'description'},
|
|
|
|
$pkg{'md5sum'}, $pkg{'size'},
|
|
|
|
$pkg{'pre_install'}, $pkg{'post_install'}, $pkg{'readme'});
|
|
|
|
|
|
|
|
( ($repver{$pkg{'name'}}) and
|
|
|
|
($repver{$pkg{'name'}} gt "$pkg{'version'}-$pkg{'release'}") )
|
|
|
|
or $repver{$pkg{'name'}} = "$pkg{'version'}-$pkg{'release'}";
|
|
|
|
}
|
|
|
|
close(REPO);
|
|
|
|
|
|
|
|
while (my $tpp = shift @toprint) {
|
|
|
|
my ($n,$p,$u,$v,$r,$d,$m,$s,$E,$O,$R) = split /\^/, $tpp;
|
|
|
|
my %printpkg = ('name' => $n, 'path' => $p,
|
|
|
|
'url' => $u, 'version' => $v, 'release' => $r,
|
|
|
|
'description' => $d, 'md5sum' => $m, 'size' => $s,
|
|
|
|
'pre_install' => $E, 'post_install' => $O, 'readme' => $R);
|
|
|
|
next if ("$v-$r" lt $repver{$n});
|
|
|
|
formattedprint(%printpkg);
|
|
|
|
$found{$n} = 1;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# Show or resolve differences between installed and available packages #####
|
2006-07-12 22:21:42 -04:00
|
|
|
sub diff {
|
2023-06-18 18:25:55 -04:00
|
|
|
my $format = shift; my %found; my @diff;
|
2023-06-21 04:59:50 -04:00
|
|
|
my $strf= ($format =~ /^quick/) ? "%s " : "%-19s %-19s %-19s\n";
|
|
|
|
(%installed) or getinstalled();
|
2023-06-17 11:24:34 -04:00
|
|
|
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
2023-06-21 04:59:50 -04:00
|
|
|
my @multip=();
|
2023-06-17 11:24:34 -04:00
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = parsepackage($_, $dir, $url);
|
|
|
|
next if ( ($found{$pkg{'name'}}) or (! $installed{$pkg{'name'}}) );
|
|
|
|
next if ( ($locked{$pkg{'name'}}) and (! $all) );
|
|
|
|
my $lastcol = ($locked{$pkg{'name'}}) ? "locked" : "";
|
|
|
|
($lastcol eq "locked") or $lastcol = ($installed{$pkg{'name'}}
|
|
|
|
eq $pkg{'version'}."-".$pkg{'release'}) ? "uptodate" :
|
|
|
|
$pkg{'version'}."-".$pkg{'release'};
|
|
|
|
push @multip, "$pkg{'name'}^$installed{$pkg{'name'}}^$lastcol";
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
|
|
|
close(REPO);
|
2023-06-21 04:59:50 -04:00
|
|
|
while (my $mp = shift @multip) {
|
|
|
|
my ($mpname, $vinst, $mpinfo) = split /\^/, $mp;
|
|
|
|
next if ( (@multip) and ($multip[0] =~ m/^\Q$mpname\E\^/) );
|
|
|
|
|
|
|
|
$found{$mpname} = 1;
|
|
|
|
next if ($mpinfo eq "uptodate");
|
|
|
|
($format !~ /^(quick|sysup)/) or push @diff, $mpname;
|
|
|
|
($format =~ /^(quick|sysup)/) or push @diff, join("^",
|
|
|
|
$mpname, $vinst, $mpinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
($#diff < 0) or ($format =~ /^(quick|sysup)/) or
|
|
|
|
printf $strf, "Package","Installed", "Available in the repositories";
|
|
|
|
if ($format ne "sysup") {
|
|
|
|
print "\n";
|
|
|
|
foreach my $dl (@diff) { printf $strf, split /\^/, $dl; }
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-21 04:59:50 -04:00
|
|
|
($format !~ /^quick/) or ($#diff < 0) or print "\n";
|
|
|
|
($#diff >= 0) or print "No differences found\n";
|
2023-06-18 18:25:55 -04:00
|
|
|
|
|
|
|
# proceed with updates if sysup was requested
|
2023-06-21 04:59:50 -04:00
|
|
|
($#diff < 0) or ($format ne "sysup") or upinst("update", @diff);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Display duplicate packages (found in more than one repo) #################
|
|
|
|
sub dup {
|
2023-06-17 11:24:34 -04:00
|
|
|
my %found;
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(REPO, "$dir/PKGREPO") or exiterr("could not open $dir/PKGREPO");
|
|
|
|
while (<REPO>) {
|
|
|
|
chomp;
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = parsepackage($_, $dir, $url);
|
2023-06-17 11:24:34 -04:00
|
|
|
$found{$pkg{'name'}} .= "###" . $pkg{'path'}."/". $pkg{'name'}.$pkg{'version'}."-".$pkg{'release'};
|
|
|
|
}
|
|
|
|
close(REPO);
|
|
|
|
}
|
|
|
|
foreach my $key (sort keys %found) {
|
|
|
|
my $value = $found{$key};
|
|
|
|
$value =~ s/^\#\#\#//;
|
|
|
|
if (rindex($value, "###") >=0){
|
|
|
|
print "* $key\n";
|
|
|
|
my @d = split(/\#\#\#/, $value);
|
|
|
|
foreach my $dup(@d){ print " $dup\n"; }
|
|
|
|
}
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Show list of dependencies for package ####################################
|
|
|
|
sub depends {
|
2023-06-17 11:24:34 -04:00
|
|
|
my ($j, $checkver) = ($ARGV[0] =~ /^quick/) ? (" ",0) : ("\n",1);
|
2023-06-21 04:59:50 -04:00
|
|
|
($checkver == 0) or (%installed) or getinstalled();
|
2023-06-17 11:24:34 -04:00
|
|
|
getdependencies($ARGV[1], $checkver, "") or exiterr("package '$ARGV[1]' not found");
|
|
|
|
if ((@dependencies) and ($checkver)) {print "-- dependencies ([i] = installed, [u] = updatable)\n"}
|
|
|
|
print join($j, @dependencies);
|
|
|
|
if ((%missingdeps) and ($j ne " ")) {
|
|
|
|
print "\n-- missing packages\n";
|
|
|
|
foreach my $dep(sort keys %missingdeps) {
|
|
|
|
print "$dep from $missingdeps{$dep}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print "\n";
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Show packages directly depending from given package ######################
|
|
|
|
sub dependent {
|
2023-06-17 11:24:34 -04:00
|
|
|
my $arg = $ARGV[1];
|
|
|
|
my %dp;
|
|
|
|
getinstalled() unless (($all) or (%installed));
|
|
|
|
foreach my $repo(@repos) {
|
|
|
|
my ($dir, $url) = split(/\|/, $repo);
|
|
|
|
open(DEPS, "$dir/PKGDEPS")
|
|
|
|
or exiterr("could not open $dir/PKGDEPS");
|
|
|
|
while (<DEPS>) {
|
|
|
|
chomp;
|
|
|
|
my ($maybe, $deplist) = split /\:/;
|
|
|
|
# collapse trailing or leading whitespace
|
|
|
|
$maybe =~ s/\s+$//; $deplist =~ s/^\s+//;
|
|
|
|
# ensure that arg is surrounded by commas, even if appearing at
|
|
|
|
# the beginning or the end of the list
|
|
|
|
$deplist =~ s/^/\,/; $deplist =~ s/$/\,/;
|
|
|
|
$dp{$maybe} = 1 if (index($deplist,",$arg,") >= 0);
|
|
|
|
}
|
|
|
|
close(DEPS);
|
|
|
|
}
|
|
|
|
foreach my $res(keys %dp) {
|
|
|
|
print "$res\n" unless ((not $all) and (! $installed{$res}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Install or update given package ##########################################
|
|
|
|
sub upinst {
|
|
|
|
my ($cmd, @args) = @_; my $aa;
|
|
|
|
($curraction, $aa) = ($cmd =~ /^up/) ? ("updated","-u") : ("installed","");
|
|
|
|
|
|
|
|
getinstalled() if (! %installed);
|
|
|
|
foreach my $pkgname(@args) {
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = getpackage($pkgname);
|
2023-06-17 11:24:34 -04:00
|
|
|
if (not %pkg) {
|
|
|
|
push(@failtasks, "not found,$pkgname");
|
|
|
|
} elsif ( ($cmd . getshortstatus(%pkg))
|
|
|
|
=~ /^(update.i|update. |install.u|install.i)/ ) {
|
|
|
|
push(@prevtasks, "$pkgname");
|
|
|
|
} elsif (downloadpkg(%pkg) and installpkg($aa, %pkg)) {
|
|
|
|
push(@donetasks, $pkgname);
|
|
|
|
} else {
|
|
|
|
push(@failtasks, "where $cmd failed,$pkgname");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printresults();
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# Install given package, along with dependencies ###########################
|
2006-07-12 22:21:42 -04:00
|
|
|
sub depinst {
|
2023-06-17 11:24:34 -04:00
|
|
|
my @toinst; my %seen;
|
|
|
|
$curraction = "installed";
|
|
|
|
my @args = @ARGV; shift(@args);
|
|
|
|
getinstalled() if (! %installed);
|
|
|
|
foreach my $pkgname(@args) {
|
|
|
|
getdependencies($pkgname, 0, "");
|
|
|
|
foreach my $dep(@dependencies) {
|
|
|
|
next if ($seen{$dep}); $seen{$dep} = 1;
|
|
|
|
next if ($locked{$dep});
|
2023-06-21 04:59:50 -04:00
|
|
|
my %pkg = getpackage($dep);
|
2023-06-17 11:24:34 -04:00
|
|
|
if ((%pkg) and (getshortstatus(%pkg) eq "[ ]")) {
|
|
|
|
push(@toinst, $pkg{'name'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
upinst("install",@toinst) if (@toinst);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|