App-Slaughter
view release on metacpan or search on metacpan
lib/Slaughter/API/linux.pm view on Meta::CPAN
# TODO
=for example end
The following parameters are required:
=over 8
=item Login
The username to create.
=item UID
The UID for the user.
=item GID
The primary GID for the user.
=back
You may optionally specify the GCos field to use.
=cut
sub UserCreate
{
my (%params) = (@_);
#
# Ensure we have the variables we need.
#
foreach my $variable (qw! Login UID GID !)
{
if ( !defined( $params{ $variable } ) )
{
#
# Return undef..
#
return ( $params{ $variable } );
}
}
#
# If the GCos field isn't set then define it.
#
$params{ 'Gcos' } = $params{ 'Login' } if ( !$params{ 'Gcos' } );
#
# The user-addition command.
#
my $cmd =
"useradd -c \"$params{ 'Gcos' }\"" . " -G adm" .
" -g $params{ 'Login' }" . " -m" . " -u $params{ 'UID' }" .
" -s /bin/bash" . " $params{ 'Login' }";
# Ensure the group exists first.
RunCommand( Cmd => "addgroup --gid $params{ 'UID' } $params{ 'Login' }" );
# useradd -c name -d /home/user -g adm -m -u 801 user
RunCommand( Cmd => $cmd );
}
1;
=head1 AUTHOR
Steve Kemp <steve@steve.org.uk>
=cut
=head1 LICENSE
Copyright (c) 2010-2015 by Steve Kemp. All rights reserved.
This module is free software;
you can redistribute it and/or modify it under
the same terms as Perl itself.
The LICENSE file contains the full text of the license.
=cut
( run in 1.037 second using v1.01-cache-2.11-cpan-5735350b133 )