From: Dietmar Maurer Date: Wed, 11 Jan 2017 11:12:11 +0000 (+0100) Subject: PVE/RPCEnvironment.pm: new function setup_default_cli_env X-Git-Url: https://git.proxmox.com/?p=pve-access-control.git;a=commitdiff_plain;h=5ae5900d26ffa7e158d4847ebeb537714fb9439d;ds=sidebyside PVE/RPCEnvironment.pm: new function setup_default_cli_env Convenience function for command line tools. --- diff --git a/PVE/RPCEnvironment.pm b/PVE/RPCEnvironment.pm index 3ec2c91..30415eb 100644 --- a/PVE/RPCEnvironment.pm +++ b/PVE/RPCEnvironment.pm @@ -513,6 +513,23 @@ sub init { return $self; }; +# convenience function for command line tools +sub setup_default_cli_env { + my ($username) = @_; + + $username //= 'root@pam'; + + PVE::INotify::inotify_init(); + + my $rpcenv = PVE::RPCEnvironment->init('cli'); + $rpcenv->init_request(); + $rpcenv->set_language($ENV{LANG}); + $rpcenv->set_user($username); + + die "please run as root\n" + if ($username eq 'root@pam') && ($> != 0); +} + # get the singleton sub get {