From 3224209ff77c8bae095c4fd11430b5b8076d039a Mon Sep 17 00:00:00 2001 From: John McQuah Date: Wed, 29 Nov 2023 01:14:31 +0000 Subject: [PATCH] pkg-get.pl: support the -fr (force reinstall) option --- scripts/pkg-get.pl | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/scripts/pkg-get.pl b/scripts/pkg-get.pl index 941ab7e..5375aca 100755 --- a/scripts/pkg-get.pl +++ b/scripts/pkg-get.pl @@ -30,15 +30,15 @@ my $curraction = ""; my %deps; my @dependencies; my %missingdeps; my %locked; my %installed; # 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=""; +my $download_only; my $pre_install; my $post_install; my $root=""; +my $install_scripts; my $all; my $filter = ""; my $unused; +my $aargs=""; my $ignore_md5sum; my $force; my $force_reinst; GetOptions("do"=>\$download_only, "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); + "fr"=>\$force_reinst, "rargs=s"=>\$unused, "r=s"=>\$root); # use compression-mode defined in pkgmk.conf our $compress = "gz"; @@ -395,28 +395,19 @@ sub getdependencies { # Download given package (if needed), check md5sum sub downloadpkg { my %pkg = @_; + my $url = $pkg{'url'}; $url =~ s/\#/\%23/; 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) { + return 0 if (($url eq "") and (! -f $fullpath)); # repo is local and pkg does not exist + my $downloadcmd = "curl --retry 3 --retry-delay 3 -o $fullpath $url"; + (! $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 "required : $pkg{'md5sum'}\n"; print STDERR "found : $md5\n"; 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; } @@ -832,7 +823,9 @@ sub upinst { if (not %pkg) { push(@failtasks, "not found,$pkgname"); } 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"); } elsif (downloadpkg(%pkg)) { ($download_only) or installpkg($aa, %pkg) or $failed=1;