prt-auf: respect --install-root when running pre- and post-install scripts

This commit is contained in:
2023-06-02 15:17:14 -04:00
parent 99d51f625d
commit a76248a9cb
2 changed files with 61 additions and 37 deletions

View File

@@ -12,10 +12,10 @@ use strict;
################### Initialize global variables #######################
my $title="prt-auf"; my $version=0.51; my $cache_ver="V5.1";
my $CONFDIR = "/var/lib/pkg"; my $prtalias="/etc/prt-get.aliases";
my $CONFDIR="/var/lib/pkg"; my $prtalias="/etc/prt-get.aliases";
my $pkgdb="$CONFDIR/db"; my $prtlocker="$CONFDIR/prt-get.locker";
my $prtcache="$CONFDIR/prt-get.cache"; my %LOCKED; my %ALIASES; my %DEPENDS;
my @allports; my %V_REPO; my %V_INST; my %DESC; my %SOFTDEPS;
my $prtcache="$CONFDIR/prt-get.cache"; my $altroot=""; my %LOCKED; my %ALIASES;
my @allports; my %V_REPO; my %V_INST; my %DESC; my %DEPENDS; my %SOFTDEPS;
my @results; my $strf; my $ind; my $hh; my $portpath; my $built_pkg;
my %osearch = ( cache=>0, regex=>0, path=>0, exact=>0, verbose=>0 );
my %odepends = ( inject=>1, soft=>0, tree=>0, recursive=>0, all=>0 );
@@ -47,7 +47,7 @@ if (($action !~ /^(fsearch|isinst|current)$/) and ($osearch{cache}==0)) {
if ($osearch{cache}==1) { fill_hashes_from_cache(); }
if ($action !~ /^(search|dsearch|fsearch|info|dup|ls|readme|cat)$/) {
open (DB, $pkgdb) or die "Could not open package database!\n";
open (DB, "$altroot$pkgdb") or die "Could not open package database!\n";
local $/="";
while (<DB>) { $V_INST{$1} = $2 if m/^(.*)\n(.*)\n/; }
close (DB);
@@ -147,11 +147,9 @@ if (($action =~ /^(listinst|listorphans|dependent)/) and
"Readme", "PreInstall", "PostInstall");
for (my $i=0; $i<9; $i++) { printf $strf, $fields[$i], $results[$i] unless ($results[$i] =~ /^\s*$/); }
} elsif ($action eq "remove") {
my %removed = %$ind;
my @successes = grep { $removed{$_}==1 } keys %removed;
my @failures = grep { $removed{$_}==0 } keys %removed;
print "Ports removed:\n" if (@successes);
foreach my $p (@successes) { print "$p\n"; }
my @removed = @$ind;
print "Ports removed:\n" if (@removed);
foreach my $p (@removed) { print "$p\n"; }
} elsif ($action =~ /^(install|sysup)$/) {
my @ok = @{$results[0]}; my %ok_pre = %{$results[1]}; my %ok_post = %{$results[2]};
my @ok_readme = @{$results[3]}; my @not_ok = @{$results[4]}; my $note;
@@ -215,8 +213,11 @@ sub parse_args {
} elsif ($arg eq "-fi") { $opkg{aargs} .= " -f";
} elsif ($arg =~ /^(-uf|-if|-us|-is|-ns|-kw)$/) { $opkg{margs} .= " $1";
} elsif ($arg =~ /^--margs=(.+)/) { $opkg{margs} .= $1;
} elsif ($arg =~ /^--aargs=(-r|--root)=(.+)/) { $opkg{aargs} .= "$1 $2";
} elsif ($arg =~ /^--rargs=(-r|--root)=(.+)/) { $opkg{rargs} .= "$1 $2";
} elsif (($arg =~ /^--install-root=(.+)$/) and (-d $1)) { $altroot=$1;
} elsif (($arg =~ /^--aargs=(-r|--root)=(.+)/) and (-d $2)) { $altroot=$2;
} elsif (($arg =~ /^--rargs=(-r|--root)=(.+)/) and (-d $2)) { $altroot=$2;
} elsif ($arg =~ /^--aargs=(.+)/) { $opkg{aargs} .= " $1";
} elsif ($arg =~ /^--rargs=(.+)/) { $opkg{rargs} .= " $1";
} elsif ($arg =~ /^-/) {
print "'$arg' is not a recognized option.\n";
} else { push (@query, $arg); }
@@ -309,13 +310,13 @@ sub find_dups {
}
sub get_locked_and_aliased {
if (-f $prtalias) {
open (AL, $prtalias);
if (-f "$altroot$prtalias") {
open (AL, "$altroot$prtalias");
while (<AL>) { $ALIASES{$1} = $2 if m/^\s*(.*)\s*:\s*(.*)/; }
close (AL);
}
if (-f $prtlocker) {
open (LK, $prtlocker);
if (-f "$altroot$prtlocker") {
open (LK, "$altroot$prtlocker");
while (<LK>) { chomp; $LOCKED{$_}=1 unless /^\s*$/; }
close (LK);
}
@@ -491,12 +492,16 @@ sub uninstall {
my @rubbish = grep { ! defined $V_INST{$_} } @_;
foreach my $r (@rubbish) { print "$r not installed; ignoring.\n"; }
my %removed = map { $_ => 0 } @targets;
if (($altroot ne "") and ($opkg{rargs} !~ m/(-r|--root)/)) {
$opkg{rargs} .= " -r $altroot";
}
foreach my $t (@targets) {
($opkg{test} eq "no") ? system($PKGRM,$opkg{rargs},$t) : print "$PKGRM $opkg{rargs} $t\n";
$removed{$t}=1 if ($?>>8 == 0);
if (($LOCKED{$t}) and ($opkg{test} eq "no")) { port_unlock($t); }
}
return \%removed;
my @successes = grep { $removed{$_} == 1 } keys %removed;
return @successes;
}
sub port_lock {
@@ -764,7 +769,10 @@ sub up_inst { # returns scalar references to five arrays
$builtpkg{$t} =~ s/uuiVer/$pvars{'%v'}/g;
$builtpkg{$t} =~ s/uuiRel/$pvars{'%r'}/g;
$mkcmd{$t} = "$PKGMK -d $opkg{$t}";
$addcmd{$t} = "$PKGADD -u $builtpkg{$t}";
if (($altroot ne "") and ($opkg{aargs} !~ m/(-r|--root)/)) {
$opkg{aargs} .= " -r $altroot";
}
$addcmd{$t} = "$PKGADD -u $opkg{aargs} $builtpkg{$t}";
if ($olog{write} eq "enabled") {
$logfile{$t} = $olog{file};
$logfile{$t} =~ s/(%n|%v|%r|%p)/$pvars{$1}/g;
@@ -788,8 +796,12 @@ sub up_inst { # returns scalar references to five arrays
next BUILDLOG;
}
if ($mkcmd{$t} ne "") {
if ((-f "$pdirs{$t}/pre-install") and ($opkg{runscripts} eq "yes")) {
system("sh","$pdirs{$t}/pre-install");
if (($opkg{runscripts} eq "yes") and (-f "$pdirs{$t}/pre-install")) {
if ($altroot ne "") {
system("chroot",$altroot,"sh","$pdirs{$t}/pre-install");
} else {
system("sh","$pdirs{$t}/pre-install");
}
( $?>>8 == 0 ) ? $ok_pre{$t} = 1 : delete $ok_pre{$t};
}
chdir $pdirs{$t}; system("$mkcmd{$t}"); $status=( $?>>8 == 0 );
@@ -811,9 +823,13 @@ sub up_inst { # returns scalar references to five arrays
} elsif ( ($not_ok{$t}) and (-f "$builtpkg{$t}") ) {
system("mv $builtpkg{$t} $builtpkg{$t}.CHECKME");
}
if (($ok{$t}) and (-f "$pdirs{$t}/post-install")
and ($opkg{runscripts} eq "yes")) {
system("sh","$pdirs{$t}/post-install");
if (($ok{$t}) and ($opkg{runscripts} eq "yes")
and (-f "$pdirs{$t}/post-install")) {
if ($altroot ne "") {
system("chroot",$altroot,"sh","$pdirs{$t}/post-install");
} else {
system("sh","$pdirs{$t}/post-install");
}
( $?>>8 == 0 ) ? $ok_post{$t}=1 : delete $ok_post{$t};
}
}