Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Slackware #1387

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Revision history for Rex
[MINOR]

[NEW FEATURES]
- Add Slackware support

[REVISION]

Expand Down
19 changes: 18 additions & 1 deletion lib/Rex/Commands/Gather.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use vars qw(@EXPORT);

@EXPORT = qw(operating_system_is network_interfaces memory
get_operating_system operating_system operating_system_version operating_system_release
is_freebsd is_netbsd is_openbsd is_redhat is_linux is_bsd is_solaris is_suse is_debian is_mageia is_windows is_alt is_openwrt is_gentoo is_fedora is_arch is_void
is_freebsd is_netbsd is_openbsd is_redhat is_linux is_bsd is_solaris is_suse is_debian is_mageia is_windows is_alt is_openwrt is_gentoo is_fedora is_arch is_void is_slackware
get_system_information dump_system_information kernelname);

=head2 get_operating_system
Expand Down Expand Up @@ -573,4 +573,21 @@ sub is_void {

}

=head2 is_slackware

Returns true if the target system is a Slackware system.

=cut

sub is_slackware {
my $os = @_ ? shift : get_operating_system();

my @slackware_clones = ("Slackware");

if ( grep { /$os/i } @slackware_clones ) {
return 1;
}

}

1;
15 changes: 15 additions & 0 deletions lib/Rex/Hardware/Host.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ sub get_operating_system {
return "Manjaro";
}

if ( is_file("/etc/slackware-version") ) {
return "Slackware";
}

my $os_string = i_run("uname -s");
return $os_string; # return the plain os

Expand Down Expand Up @@ -333,6 +337,17 @@ sub get_operating_system_version {
return "outdated";
}
}
elsif ( $op eq "Slackware" ) {
my $fh = file_read("/etc/slackware-version");
my $content = $fh->read_all;
$fh->close;

chomp $content;

my ($version) = $content =~ m/(\d+(\.\d+)*\+?)$/;

return $version;
}

return [ i_run("uname -r") ]->[0];

Expand Down
3 changes: 3 additions & 0 deletions lib/Rex/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ sub get {
elsif ( is_arch($operatingsystem) && $can_run_systemctl ) {
$class = "Rex::Service::Arch::systemd";
}
elsif ( is_slackware($operatingsystem) ) {
$class = "Rex::Service::Slackware";
}

my $provider_for = Rex::Config->get("service_provider") || {};
my $provider;
Expand Down
73 changes: 73 additions & 0 deletions lib/Rex/Service/Slackware.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package Rex::Service::Slackware;

use strict;
use warnings;

# VERSION

use Fcntl qw(:mode);
use Rex::Commands::File;
use Rex::Commands::Fs;
use Rex::Logger;

use base qw(Rex::Service::Base);

sub new {
my $that = shift;
my $proto = ref($that) || $that;
my $self = $proto->SUPER::new(@_);

bless( $self, $proto );

$self->{commands} = {
start => '/etc/rc.d/rc.%s start',
restart => '/etc/rc.d/rc.%s restart',
stop => '/etc/rc.d/rc.%s stop',
reload => '/etc/rc.d/rc.%s reload',
status => '/etc/rc.d/rc.%s status',
action => '/etc/rc.d/rc.%s %s',
};

return $self;
}

sub _get_file_mode {
my ( $self, $file ) = @_;

my $mode;
if ( is_file($file) ) {
my %stat = stat $file;
$mode = oct $stat{mode};
}
return $mode;
}

sub ensure {
my ( $self, $service, $options ) = @_;

my $what = $options->{ensure};

my $script = sprintf '/etc/rc.d/rc.%s', $service;
my $mode = $self->_get_file_mode($script);
if ( !defined $mode ) {
Rex::Logger::info( "Startup script $script not found", 'error' );
return 0;
}

if ( $what =~ /^stop/ ) {
if ( ( $mode & S_IXUSR ) != 0 ) {
$self->stop( $service, $options );
file $script, mode => 'a-x';
}
}
elsif ( $what =~ /^(?:start|run)/ ) {
if ( ( $mode & S_IXUSR ) == 0 ) {
file $script, mode => 'a+x';
$self->start( $service, $options );
}
}

return 1;
}

1;