From 5ae5900d26ffa7e158d4847ebeb537714fb9439d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 11 Jan 2017 12:12:11 +0100 Subject: [PATCH] PVE/RPCEnvironment.pm: new function setup_default_cli_env Convenience function for command line tools. --- PVE/RPCEnvironment.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 { -- 2.39.2