pkg-get.pl: support the -fr (force reinstall) option

This commit is contained in:
John McQuah 2023-11-29 01:14:31 +00:00
parent 44f3da7c5a
commit 3224209ff7
1 changed files with 15 additions and 22 deletions

View File

@ -30,15 +30,15 @@ my $curraction = ""; my %deps; my @dependencies; my %missingdeps;
my %locked; my %installed; my %locked; my %installed;
# CL Options # CL Options
my $download_only; my $pre_install; my $post_install; my $download_only; my $pre_install; my $post_install; my $root="";
my $install_scripts; my $filter = ""; my $all; my $unused; my $install_scripts; my $all; my $filter = ""; my $unused;
my $aargs=""; my $ignore_md5sum; my $force; my $root=""; my $aargs=""; my $ignore_md5sum; my $force; my $force_reinst;
GetOptions("do"=>\$download_only, GetOptions("do"=>\$download_only,
"pre-install"=>\$pre_install, "post-install"=>\$post_install, "pre-install"=>\$pre_install, "post-install"=>\$post_install,
"install-scripts"=>\$install_scripts, "all"=>\$all, "install-scripts"=>\$install_scripts, "all"=>\$all,
"filter=s"=>\$filter, "config=s"=>\$CFGFILE, "aargs=s"=>\$aargs, "filter=s"=>\$filter, "config=s"=>\$CFGFILE, "aargs=s"=>\$aargs,
"f"=>\$force, "im"=>\$ignore_md5sum, "margs=s"=>\$unused, "f"=>\$force, "im"=>\$ignore_md5sum, "margs=s"=>\$unused,
"rargs=s"=>\$unused, "r=s"=>\$root); "fr"=>\$force_reinst, "rargs=s"=>\$unused, "r=s"=>\$root);
# use compression-mode defined in pkgmk.conf # use compression-mode defined in pkgmk.conf
our $compress = "gz"; our $compress = "gz";
@ -395,28 +395,19 @@ sub getdependencies {
# Download given package (if needed), check md5sum # Download given package (if needed), check md5sum
sub downloadpkg { sub downloadpkg {
my %pkg = @_; my %pkg = @_;
my $url = $pkg{'url'}; $url =~ s/\#/\%23/;
my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.$compress"; my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.$compress";
if (-f $fullpath) { return 0 if (($url eq "") and (! -f $fullpath)); # repo is local and pkg does not exist
my $md5 = digest_file_hex($fullpath,"MD5"); my $downloadcmd = "curl --retry 3 --retry-delay 3 -o $fullpath $url";
if ($md5 ne $pkg{'md5sum'} and not $ignore_md5sum) { (! $force_reinst) or system ($downloadcmd) == 0 or return 0;
(-f $fullpath) or system ($downloadcmd) == 0 or return 0;
# by now there should be a file in the expected location
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 "=======> ERROR: md5sum mismatch for $pkg{'name'}:\n";
print STDERR "required : $pkg{'md5sum'}\n"; print STDERR "required : $pkg{'md5sum'}\n";
print STDERR "found : $md5\n"; print STDERR "found : $md5\n";
return 0; return 0;
}
return 1;
} else {
return 1 if ($pkg{'url'} eq ""); # repo is local and pkg does not exist
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; return 1;
} }
@ -832,7 +823,9 @@ sub upinst {
if (not %pkg) { if (not %pkg) {
push(@failtasks, "not found,$pkgname"); push(@failtasks, "not found,$pkgname");
} elsif ( ($cmd . getshortstatus(%pkg)) } elsif ( ($cmd . getshortstatus(%pkg))
=~ /^(update.i|update. |install.u|install.i)/ ) { =~ /^(update. |install.u|install.i)/ ) {
push(@prevtasks, "$pkgname");
} elsif ( (($cmd . getshortstatus(%pkg)) =~ /^update.i/) and (! $force_reinst) ) {
push(@prevtasks, "$pkgname"); push(@prevtasks, "$pkgname");
} elsif (downloadpkg(%pkg)) { } elsif (downloadpkg(%pkg)) {
($download_only) or installpkg($aa, %pkg) or $failed=1; ($download_only) or installpkg($aa, %pkg) or $failed=1;