X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fpakfire%2Fpakfire;h=6c77695c815f0127f6b50541a588b6101d76a011;hb=66c3619872bcf723d7bac550165ad5658de95644;hp=da68454dc6646600cb401be62398734727f7bf59;hpb=388f903e9e83a7013824fd858dbda23ba55bb9f8;p=ipfire-2.x.git diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index da68454dc6..6c77695c81 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -2,7 +2,7 @@ ############################################################################### # # # IPFire.org - A linux based firewall # -# Copyright (C) 2007-2015 IPFire Team # +# Copyright (C) 2007-2021 IPFire Team # # # # 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 # @@ -24,13 +24,16 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)}; $< = $>; + # Store keys here + $ENV{"GNUPGHOME"} = "/opt/pakfire/etc/.gnupg"; + require "/opt/pakfire/lib/functions.pl"; - + my $interactive = 1; my $force = "noforce"; - + my $locked; + &Pakfire::logger("PAKFIRE INFO: IPFire Pakfire $Conf::version started!"); - &Pakfire::checkcryptodb; ### Check if we are running as root # @@ -40,12 +43,27 @@ &Pakfire::message("PAKFIRE ERROR: You must run pakfire as user root!"); exit 1; } - + unless ( -e "/var/ipfire/red/active" ) { &Pakfire::message("PAKFIRE ERROR: You need to be online to run pakfire!"); exit 2; } - + + # Check if a lockfile already exists. + if (-e "$Pakfire::lockfile") { + &Pakfire::message("PAKFIRE ERROR: Another instance of pakfire is already running!"); + exit 1; + } + + # Write lockfile. + open(LOCK, ">$Pakfire::lockfile"); + + # Pakfire has locked in this session set locket to "1". + $locked = "1"; + + # Close filehandle. + close(LOCK); + ### Check if we are started by another name # if ( $0 =~ /pakfire-update$/ ) { @@ -63,20 +81,20 @@ $ARGV[0] = "upgrade"; $interactive = 0; } - + unless (@ARGV) { &Pakfire::usage; } - + foreach (@ARGV) { if ("$_" =~ "^-") { # Turn off interactive mode $interactive = 0 if ("$_" eq "--non-interactive"); $interactive = 0 if ("$_" eq "-y"); - + # Turn off shell colors - Bad for displaying in webinterface $Pakfire::enable_colors = 0 if ("$_" eq "--no-colors"); - + # Turn on force mode $force = "force" if ("$_" eq "-f" ); $force = "force" if ("$_" eq "--force" ); @@ -85,14 +103,14 @@ if ("$ARGV[0]" eq "install") { shift; - - ### Make sure that the list is not outdated. + + ### Make sure that the list is not outdated. &Pakfire::dbgetlist("noforce"); open(FILE, "<$Conf::dbdir/lists/packages_list.db"); my @db = ; close(FILE); - + my $dep; my @deps; my $pak; @@ -107,7 +125,7 @@ $return = &Pakfire::isinstalled($pak); if ($return eq 0) { &Pakfire::message("PAKFIRE INFO: $pak is already installed"); - next; + next; } $found = 0; foreach (@db) { @@ -130,7 +148,7 @@ } } } - + unless (@paks) { &Pakfire::message("PAKFIRE ERROR: No packages to install. Exiting..."); exit 1; @@ -156,7 +174,7 @@ $size = &Pakfire::beautifysize($size); &Pakfire::message("PAKFIRE INFO: $pak \t - $size"); } - + my $totalsize; foreach $pak (@all) { $totalsize = ($totalsize + &Pakfire::getsize("$pak")); @@ -165,7 +183,7 @@ &Pakfire::message(""); &Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize"); &Pakfire::message(""); - + if ($interactive) { &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]"); my $ret = ; @@ -178,7 +196,7 @@ } else { &Pakfire::logger("PAKFIRE INFO: Interaction skipped."); } - + # my %sort = map{ $_, 1 } @all; # @all = sort keys %sort; @@ -192,16 +210,16 @@ foreach $pak (@deps) { &Pakfire::setuppak("$pak") if ($pak ne ""); } - + foreach $pak (@paks) { &Pakfire::setuppak("$pak") if ($pak ne ""); } - + } elsif ("$ARGV[0]" eq "remove") { shift; - + my @paks; my $pak; foreach $pak (@ARGV) { @@ -214,12 +232,12 @@ push(@paks, $pak); } } - + unless (@paks) { &Pakfire::message("PAKFIRE ERROR: No packages to remove. Exiting..."); exit 1; } - + &Pakfire::message(""); &Pakfire::message(""); &Pakfire::message("PAKFIRE INFO: Packages to remove:"); @@ -228,7 +246,7 @@ $size = &Pakfire::beautifysize($size); &Pakfire::message("PAKFIRE INFO: $pak \t - $size"); } - + if ($interactive) { &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]"); my $ret = ; @@ -239,15 +257,14 @@ exit 1; } } - + foreach $pak (@paks) { &Pakfire::removepak("$pak"); } - - + + } elsif ("$ARGV[0]" eq "update") { &Pakfire::makeuuid(); - &Pakfire::senduuid(); &Pakfire::getmirrors("$force"); &Pakfire::dbgetlist("$force"); &Pakfire::getcoredb("$force"); @@ -274,7 +291,7 @@ } } } - + # Download packages foreach $pak (@upgradepaks) { &Pakfire::getpak("$pak", ""); @@ -294,15 +311,15 @@ foreach $pak (@upgradepaks) { &Pakfire::upgradepak("$pak"); } - + } elsif ("$ARGV[0]" eq "list") { if ("$ARGV[1]" =~ /installed|notinstalled/) { &Pakfire::dblist("$ARGV[1]", "noweb"); } else { - &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); + &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); &Pakfire::dblist("all", "noweb"); } - + } elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { next if ("$_" eq "resolvedeps"); @@ -321,10 +338,20 @@ } elsif ("$ARGV[1]" eq "upgrades") { system("rm -f /etc/fcron.daily/pakfire-upgrade"); } + } elsif ("$ARGV[0]" eq "status") { + &Pakfire::status; } else { &Pakfire::usage; } &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing."); + END { + # Check if pakfire has been locked in this session. + if ($locked) { + # Remove lockfile. + unlink($Pakfire::lockfile); + } + } + exit 0;