optimizing the code by removing the varius ifs/else's and setting the value on the last moment based on a hash
parent
3b47cc53cb
commit
7a4f292d80
|
@ -6,36 +6,27 @@ package Nipe::Utils::Install {
|
||||||
sub new {
|
sub new {
|
||||||
my %device = Nipe::Utils::Device -> new();
|
my %device = Nipe::Utils::Device -> new();
|
||||||
my $stopTor = "systemctl stop tor";
|
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") {
|
if ($device{distribution} eq "void") {
|
||||||
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");
|
|
||||||
$stopTor = "sv stop tor > /dev/null";
|
$stopTor = "sv stop tor > /dev/null";
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
|
||||||
system ("pacman -S --noconfirm tor iptables");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-e "/etc/init.d/tor") {
|
if (-e "/etc/init.d/tor") {
|
||||||
$stopTor = "/etc/init.d/tor stop > /dev/null";
|
$stopTor = "/etc/init.d/tor stop > /dev/null";
|
||||||
}
|
}
|
||||||
|
|
||||||
system ($stopTor);
|
system("$install{$device{distribution}} && $stopTor");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
Loading…
Reference in New Issue