diff --git a/ChangeLog b/ChangeLog index 116f991e0..aba4932eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,7 @@ Revision history for Rex [MINOR] [NEW FEATURES] + - Added Slackware Linux support [REVISION] diff --git a/lib/Rex/Commands/Gather.pm b/lib/Rex/Commands/Gather.pm index 8848355d2..4b2bd9c6b 100644 --- a/lib/Rex/Commands/Gather.pm +++ b/lib/Rex/Commands/Gather.pm @@ -43,7 +43,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_slackware is_fedora is_arch is_void get_system_information dump_system_information kernelname); =head2 get_operating_system @@ -537,6 +537,20 @@ sub is_gentoo { } +=head2 is_slackware + +Returns true if the target system is a Gentoo System. + +=cut + +sub is_slackware { + my $os = get_operating_system(); + if ( $os =~ m/Slackware/i ) { + return 1; + } + +} + =head2 is_arch task "foo", "server1", sub { diff --git a/lib/Rex/Hardware/Host.pm b/lib/Rex/Hardware/Host.pm index 24a37968d..27326540e 100644 --- a/lib/Rex/Hardware/Host.pm +++ b/lib/Rex/Hardware/Host.pm @@ -117,6 +117,9 @@ sub get_operating_system { elsif ( $ret eq "ManjaroLinux" ) { $ret = "Manjaro"; } + elsif ( $ret =~ m/Slackware/i ) { + $ret = "Slackware"; + } return $ret; } } @@ -187,6 +190,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 @@ -339,6 +346,17 @@ sub get_operating_system_version { return $version; } } + elsif ( $op eq 'Slackware' ) { + my $fh = file_read("/etc/slackware-version"); + my $content = $fh->read_all; + $fh->close; + + chomp $content; + + $content =~ m/(\d+(\.[\d+]+)*)/; + + return $1; + } return [ i_run("uname -r") ]->[0]; diff --git a/lib/Rex/Pkg/Slackware.pm b/lib/Rex/Pkg/Slackware.pm new file mode 100644 index 000000000..e1f927a40 --- /dev/null +++ b/lib/Rex/Pkg/Slackware.pm @@ -0,0 +1,93 @@ +# Slackware +# +# (c) Giuseppe Di Terlizzi +# +# vim: set ts=2 sw=2 tw=0: +# vim: set expandtab: + +package Rex::Pkg::Slackware; + +use 5.010001; +use strict; +use warnings; + +our $VERSION = '9999.99.99_99'; # VERSION + +use Rex::Commands::Run; +use Rex::Helper::Run; +use Rex::Commands::File; +use Rex::Pkg::Base; +use base qw(Rex::Pkg::Base); + +sub new { + my $that = shift; + my $proto = ref($that) || $that; + my $self = $proto->SUPER::new(@_); + + bless( $self, $proto ); + + $self->{commands} = { + install => 'slackpkg -batch=on -default_answer=y install %s', + install_version => 'slackpkg -batch=on -default_answer=y install %s', + update_system => 'slackpkg -batch=on -default_answer=y upgrade-all', + dist_update_system => 'slackpkg -batch=on -default_answer=y upgrade-all', + remove => 'slackpkg -batch=on -default_answer=y remove %s', + update_package_db => 'slackpkg -batch=on -default_answer=y update', + }; + + return $self; +} + +sub bulk_install { + my ( $self, $packages_aref, $option ) = @_; + + delete $option->{version}; # makes no sense to specify the same version for several packages + + $self->update( "@{$packages_aref}", $option ); + + return 1; +} + +sub get_installed { + my ($self) = @_; + + my @ret; + + for my $line ( i_run("ls -d /var/log/packages/* | cut -d '/' -f5-") ) { + + my $name; + my $version; + my $build; + my $tag; + my $arch; + + # Stantard Slackware Linux package naming: + # + # name-1.0-arch-1 (Official: name + version + arch + build) + # name-1.0-arch-1tag (Third-Party: name + version + arch + build + tag) + + my @parts = split /-/, $line; + + $build = pop @parts; + $arch = pop @parts; + $version = pop @parts; + $name = join '-', @parts; + + ( $build, $tag ) = ( $build =~ /^(\d+)(.*)/ ); + + push( + @ret, + { + name => $name, + version => $version, + arch => $arch, + build => $build, + tag => $tag + } + ); + } + + return @ret; +} + +1; diff --git a/lib/Rex/Service/Slackware.pm b/lib/Rex/Service/Slackware.pm new file mode 100644 index 000000000..b384148fb --- /dev/null +++ b/lib/Rex/Service/Slackware.pm @@ -0,0 +1,39 @@ +# +# (c) Giuseppe Di Terlizzi +# +# vim: set ts=2 sw=2 tw=0: +# vim: set expandtab: + +package Rex::Service::Slackware; + +use 5.010001; +use strict; +use warnings; + +our $VERSION = '9999.99.99_99'; # VERSION + +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', + ensure_stop => 'chmod -x /etc/rc.d/rc.%s', + ensure_start => 'chmod +x /etc/rc.d/rc.%s', + action => '/etc/rc.d/rc.%s %s', + service_exists => 'test -e /etc/rc.d/rc.%s', + }; + + return $self; +} + +1;