Add support for user not willing to overwrite config file

It's a good practice to let a already existent configuration file untouched,
letting the user to decide if the new tool should or not overwrite. This patch
adds this option via a command line flag specific to the "install" option:

$ ./nipe.pl install -f
...
[.] Overwriting system Tor's config file
[.]   .configs/fedora-torrc -> /etc/tor/torrc

Otherwise, he's notified about the possibility to use one of the configuration
files present in the project's home dir.

$ ./nipe.pl install
...
[.] Refer to our custom Tor config files in project home

NOTE: It can be further enhanced in future version of the tool.
master
Bruno Meneguele 2020-01-15 16:25:54 -03:00
parent fb800ded74
commit 7bc34e8467
3 changed files with 20 additions and 3 deletions

View File

@ -9,6 +9,7 @@ sub new {
\r\tCommand Description
\r\t------- -----------
\r\tinstall Install dependencies
\r\t -f Overwrite Tor config file in /etc/tor/torrc
\r\tstart Start routing
\r\tstop Stop routing
\r\trestart Restart the Nipe process

View File

@ -5,6 +5,8 @@ package Nipe::Install;
use Nipe::Device;
sub new {
shift; # ignore class name
my $force_cfg = shift;
my $operationalSystem = Nipe::Device -> getSystem();
if ($operationalSystem eq "debian") {
@ -23,8 +25,16 @@ sub new {
system ("sudo pacman -S tor iptables");
}
system ("sudo cp .configs/$operationalSystem-torrc /etc/tor/torrc");
system ("sudo chmod 644 /etc/tor/torrc");
if (defined($force_cfg)) {
print "[.] Overwriting system Tor's config file\n";
print "[.] .configs/$operationalSystem-torrc -> /etc/tor/torrc\n";
system ("sudo cp .configs/$operationalSystem-torrc /etc/tor/torrc");
system ("sudo chmod 644 /etc/tor/torrc");
}
else {
print "[.] Refer to our custom Tor config files in project home\n";
}
if (-e "/etc/init.d/tor") {
system ("sudo /etc/init.d/tor stop > /dev/null");

View File

@ -27,7 +27,13 @@ sub main {
Nipe::Restart -> new();
}
case "install" {
Nipe::Install -> new();
my $force_cfg = undef;
if ($ARGV[1] eq "-f") {
$force_cfg = 1;
}
Nipe::Install -> new($force_cfg);
}
Nipe::Helper -> new();