#!/usr/bin/perl
require './oci-lib.pl';
require '../webmin/webmin-lib.pl'; #for OS detection
foreign_require('software', 'software-lib.pl');
sub get_packages_yum{
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("yum search php", undef, \$cmd_out, \$cmd_err, 0, 0);
if($out != 0){
&error("Error: yum: $cmd_err");
return 1;
}
my %pkgs;
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^(php[a-z0-9_\.-]+)\.(noarch|x86_64)+ : (.*)/i){
$pkgs{$1} = $3;
}
}
return %pkgs;
}
sub get_installed_yum{
my $href = $_[0];
my $pkg_list = "";
foreach my $pkg (keys %$href){
$pkg_list .= " $pkg";
}
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("rpm -q --queryformat \"%{NAME}\n\" $pkg_list", undef, \$cmd_out, \$cmd_err, 0, 0);
my %pkgs;
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^package\s+([a-z0-9_\.-]+)\s/i){ #package php is not installed
$pkgs{$1} = 0;
}else{
$pkgs{$line} = 1;
}
}
return %pkgs;
};
sub get_packages_apt{
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("apt-cache search '^php'", undef, \$cmd_out, \$cmd_err, 0, 0);
if($cmd_err ne ""){
&error("Error: apt-cache: $cmd_err");
return 1;
}
my %pkgs;
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^(php.*) - (.*)/i){
$pkgs{$1} = $2;
}
}
return %pkgs;
}
sub get_installed_apt{
my $href = $_[0]; #package names
my %pkgs;
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("dpkg -l 'php*'", undef, \$cmd_out, \$cmd_err);
if($cmd_err ne ""){
&error("Error: dpkg: $cmd_err");
return %pkgs;
}
#set all packages to not installed, since dpkg won't list them
foreach my $name (keys %$href){
$pkgs{$name} = 0;
}
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^(..)\s+(php[a-z0-9_\.-]+)\s+/i){
my $pkg = $2;
if($1 =~ /[uirph]i/){
$pkgs{$pkg} = 1;
}
}
}
return %pkgs;
};
sub update_packages{
my $pkgs_install = $_[0];
my $pkgs_remove = $_[1]; #\@lref
if($pkgs_install ne ""){
software::update_system_install($pkgs_install, undef);
}
if(@$pkgs_remove){
print "
Removing packages
"; my %opts = ('depstoo'=>1); my $error = ""; if (defined(&delete_packages)) { $error = software::delete_packages($pkgs_remove, \%opts, undef); }else{ foreach my $pkg (@$pkgs_remove){ $error .= software::delete_package($pkg, \%opts, undef) } } if($error ne ""){ &error($error); }else{ foreach my $pkg (@$pkgs_remove){ print "Deleted $pkg