optimizing the code by removing the varius ifs/else's and setting the value on the last moment based on a hash

master
htrgouvea 2021-05-18 23:29:36 -03:00
parent 3b47cc53cb
commit 7a4f292d80
1 changed files with 11 additions and 20 deletions

View File

@ -6,36 +6,27 @@ package Nipe::Utils::Install {
sub new {
my %device = Nipe::Utils::Device -> new();
my $stopTor = "systemctl stop tor";
my %install = (
"debian" => "apt-get install -y tor iptables",
"fedora" => "dnf install -y tor iptables",
"centos" => "yum -y install epel-release tor iptables",
"void" => "xbps-install -y tor iptables",
"arch" => "pacman -S --noconfirm tor iptables"
);
if ($device{distribution} eq "debian") {
system ("apt-get install -y tor iptables");
}
elsif ($device{distribution} eq "fedora") {
system ("dnf install -y tor iptables");
}
elsif ($device{distribution} eq "centos") {
system ("yum -y install epel-release tor iptables");
}
elsif ($device{distribution} eq "void") {
system ("xbps-install -y tor iptables");
if ($device{distribution} eq "void") {
$stopTor = "sv stop tor > /dev/null";
}
else {
system ("pacman -S --noconfirm tor iptables");
}
if (-e "/etc/init.d/tor") {
$stopTor = "/etc/init.d/tor stop > /dev/null";
}
system ($stopTor);
system("$install{$device{distribution}} && $stopTor");
return 1;
}
}
1;
1;