Class: Vagrant::LXC::SudoWrapper
- Inherits:
-
Object
- Object
- Vagrant::LXC::SudoWrapper
- Includes:
- Util::Retryable
- Defined in:
- lib/vagrant-lxc/sudo_wrapper.rb
Instance Attribute Summary collapse
-
#wrapper_path ⇒ Object
readonly
Returns the value of attribute wrapper_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(privileged: true) ⇒ SudoWrapper
constructor
A new instance of SudoWrapper.
- #run(*command) ⇒ Object
Constructor Details
#initialize(privileged: true) ⇒ SudoWrapper
Returns a new instance of SudoWrapper.
13 14 15 16 17 |
# File 'lib/vagrant-lxc/sudo_wrapper.rb', line 13 def initialize(privileged: true) @wrapper_path = Pathname.new(SudoWrapper.dest_path).exist? && SudoWrapper.dest_path || nil @privileged = privileged @logger = Log4r::Logger.new("vagrant::lxc::sudo_wrapper") end |
Instance Attribute Details
#wrapper_path ⇒ Object (readonly)
Returns the value of attribute wrapper_path.
7 8 9 |
# File 'lib/vagrant-lxc/sudo_wrapper.rb', line 7 def wrapper_path @wrapper_path end |
Class Method Details
.dest_path ⇒ Object
9 10 11 |
# File 'lib/vagrant-lxc/sudo_wrapper.rb', line 9 def self.dest_path "/usr/local/bin/vagrant-lxc-wrapper" end |
Instance Method Details
#run(*command) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vagrant-lxc/sudo_wrapper.rb', line 19 def run(*command) = command.last.is_a?(Hash) ? command.last : {} # Avoid running LXC commands with a restrictive umask. # Otherwise disasters occur, like the container root directory # having permissions `rwxr-x---` which prevents the `vagrant` # user from accessing its own home directory; among other # problems, SSH cannot then read `authorized_keys`! old_mask = File.umask File.umask(old_mask & 022) # allow all `r` and `x` bits begin if @privileged if @wrapper_path && ![:no_wrapper] command.unshift @wrapper_path execute *(['sudo'] + command) else execute *(['sudo', '/usr/bin/env'] + command) end else execute *(['/usr/bin/env'] + command) end ensure File.umask(old_mask) end end |