optimizing the code by removing the varius ifs/else's and setting the value on the last moment based on a hash
This commit is contained in:
parent
3b47cc53cb
commit
7a4f292d80
@ -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;
|
Loading…
x
Reference in New Issue
Block a user