Doit
view release on metacpan or search on metacpan
examples/sudo.pl view on Meta::CPAN
#
# Author: Slaven Rezic
#
use strict;
use FindBin;
use lib ("$FindBin::RealBin/../lib");
use Doit;
sub hello {
warn "I am " . getpwuid($<);
}
sub something {
warn "else...";
}
return 1 if caller;
my $doit = Doit->init;
examples/xterm.pl view on Meta::CPAN
use lib ("$FindBin::RealBin/../lib");
use Doit;
use Doit::Log;
use Doit::XTermRPC;
use Getopt::Long;
use IO::Select;
sub hello {
warn "I am " . getpwuid($<);
}
sub something {
warn "else...";
}
sub wait_for_end {
my $timeout = 10;
info "Please hit ENTER to exit, or wait ${timeout}s...";
my $sel = IO::Select->new;
lib/Doit.pm view on Meta::CPAN
if ($preserve_mode) {
chmod $stat[2], $dest
or warning "Can't chmod $dest to " . sprintf("0%o", $stat[2]) . ": $!";
}
if ($preserve_ownership) {
chown $stat[4], $stat[5], $dest
or do {
my $save_err = $!; # otherwise it's lost in the get... calls
warning "Can't chown $dest to " .
(getpwuid($stat[4]))[0] . "/" .
(getgrgid($stat[5]))[0] . ": $save_err";
};
}
if ($preserve_time) {
utime $stat[8], $stat[9], $dest
or warning "Can't utime $dest to " .
scalar(localtime $stat[8]) . "/" .
scalar(localtime $stat[9]) .
": $!";
}
lib/Doit/Deb.pm view on Meta::CPAN
my $found_key;
if ($key) {
$key =~ s{\s}{}g; # convenience: strip spaces from key ('apt-key finger' returns them with spaces)
local $ENV{LC_ALL} = 'C';
# XXX If run with $sudo, then this will emit warnings in the form
# gpg: WARNING: unsafe ownership on configuration file `$HOME/.gnupg/gpg.conf'
# Annoying, but harmless. Could be workarounded by specifying
# '--homedir=/root/.gpg', but this would create gpg files under ~root. Similar
# if using something like
# local $ENV{HOME} = (getpwuid($<))[7];
# Probably better would be to work with privilege escalation and run
# this command as normal user (to be implemented).
#
# Older Debian (jessie and older?) have only /etc/apt/trusted.gpg,
# newer ones (stretch and newer?) have /etc/apt/trusted.gpg.d/*.gpg
SEARCH_FOR_KEY: {
require File::Glob;
for my $keyfile ('/etc/apt/trusted.gpg', File::Glob::bsd_glob('/etc/apt/trusted.gpg.d/*.gpg')) {
if (-r $keyfile) {
my @cmd = ('gpg', '--keyring', $keyfile, '--list-keys', '--fingerprint', '--with-colons');
like $@, qr{chown failed on all files: };
# no test case for "chown failed on some files"
}
SKIP: {
skip "getpwnam and getgrnam not available on MSWin32", 1 if $^O eq 'MSWin32';
eval { $r->chown("user-does-not-exist", undef, "doit-test") };
like $@, qr{\QUser 'user-does-not-exist' does not exist };
eval { $r->chown(undef, "group-does-not-exist", "doit-test") };
like $@, qr{\QGroup 'group-does-not-exist' does not exist };
SKIP: {
my $username = (getpwuid($>))[0];
skip "Cannot get username for uid $>", 1 if !defined $username;
is $r->chown($username, undef, "doit-test"), 0;
}
}
######################################################################
# rename, move
is $r->rename("doit-test", "doit-test3"), 1;
$r->move("doit-test3", "doit-test2");
is $r->rename("doit-test2", "doit-test"), 1;
use Doit;
sub get_id {
my $d = shift;
chomp(my $res = `id -u`);
$res;
}
sub pwinfo {
getpwuid($<);
}
sub envinfo { \%ENV }
sub stdout_test {
print "This goes to STDOUT\n";
4711;
}
sub stderr_test {
t/user-asuser.t view on Meta::CPAN
require FindBin;
unshift @INC, $FindBin::RealBin;
require TestUtil;
plan skip_all => 'Does not work on Windows' if $^O eq 'MSWin32'; # too many unix-isms used
plan skip_all => 'cygwin does not have a root user' if $^O eq 'cygwin';
plan 'no_plan';
my $doit = Doit->init;
my($me) = getpwuid($<);
######################################################################
# error cases
{
my $as_user_body_called;
eval {
as_user {
$as_user_body_called++;
} 'this-user-does-not-exist-' . time;
};
( run in 0.478 second using v1.01-cache-2.11-cpan-8d75d55dd25 )