App-Spoor
view release on metacpan or search on metacpan
lib/App/Spoor/Installer.pm view on Meta::CPAN
Version 0.01
=cut
our $VERSION = '0.01';
=head1 SYNOPSIS
Creates directories, config file, systemd unit files as well as the package that will be added to forward-related hooks in CPanel.
=head1 SUBROUTINES
=head2 install
my %installation_config =(
login_log_path => '/var/log/login',
access_log_path => '/var/log/access',
error_log_path => '/var/log/error',
api_identifier => 'ABC123',
api_secret => 'secret456'
);
App::Spoor::Installer::install(\%installation_config);
# Optionally, you can pass in an alternative to the root path '/' which is used when building the path
# to the config file. In the code snippet below, the method will create any directories and files relative to the
# provided root path. For example, in the snippet below, the method will create the spoor config file in
# /tmp/etc/spoor rather than /etc/spoor. This is primarily used to support testing.
App::Spoor::Installer::install(\%installation_config, '/tmp');
=cut
sub install {
my $install_parameters = shift;
my $root_path = shift @_ // '/';
mkdir("$root_path/etc/spoor", 0700);
my $config = YAML::Tiny->new({
followers => {
login => {
name => $install_parameters->{'login_log_path'},
maxinterval => 10,
debug => 1,
transformer => 'bin/login_log_transformer.pl',
},
access => {
name => $install_parameters->{'access_log_path'},
maxinterval => 10,
debug => 1,
transformer => 'bin/login_log_transformer.pl',
},
error => {
name => $install_parameters->{'error_log_path'},
maxinterval => 10,
debug => 1,
transformer => 'bin/login_log_transformer.pl',
},
},
transmission => {
credentials => {
api_identifier => $install_parameters->{'api_identifier'},
api_secret => $install_parameters->{'api_secret'},
},
host => 'https://spoor.capefox.co',
endpoints => {
report => '/api/reports',
}
}
});
$config->write("$root_path/etc/spoor/spoor.yml");
chmod(0600, "$root_path/etc/spoor/spoor.yml");
mkdir("$root_path/var/lib/spoor", 0700);
mkdir("$root_path/var/lib/spoor/parsed", 0700);
mkdir("$root_path/var/lib/spoor/transmitted", 0700);
mkdir("$root_path/var/lib/spoor/transmission_failed", 0700);
open(my $login_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-login-follower.service") or die("Could not open: $!");
print $login_handle App::Spoor::LoginUnitFile::contents();
close $login_handle;
chmod(0644, "$root_path/etc/systemd/system/spoor-login-follower.service");
open(my $access_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-access-follower.service") or die("Could not open: $!");
print $access_handle App::Spoor::AccessUnitFile::contents();
close $access_handle;
chmod(0644, "$root_path/etc/systemd/system/spoor-access-follower.service");
open(my $error_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-error-follower.service") or die("Could not open: $!");
print $error_handle App::Spoor::ErrorUnitFile::contents();
close $error_handle;
chmod(0644, "$root_path/etc/systemd/system/spoor-error-follower.service");
open(my $transmitter_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-transmitter.service") or die("Could not open: $!");
print $transmitter_handle App::Spoor::TransmitterUnitFile::contents();
close $transmitter_handle;
chmod(0644, "$root_path/etc/systemd/system/spoor-transmitter.service");
mkdir("$root_path/var/cpanel/perl5", 0755);
mkdir("$root_path/var/cpanel/perl5/lib", 0755);
open(my $hook_file_handle, '>:encoding(UTF-8)', "$root_path/var/cpanel/perl5/lib/SpoorForwardHook.pm") or die("Could not open; $!");
print $hook_file_handle App::Spoor::CpanelHookFile::contents();
close $hook_file_handle;
chmod(0644, "$root_path/var/cpanel/perl5/lib/SpoorForwardHook.pm");
}
=head1 AUTHOR
Rory McKinley, C<< <rorymckinley at capefox.co> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
( run in 1.410 second using v1.01-cache-2.11-cpan-5837b0d9d2c )