From bd542f8b3fc8aaa77ce25d1607eec3c0cb1818de Mon Sep 17 00:00:00 2001 From: James Young Date: Fri, 19 Aug 2016 14:43:54 +0100 Subject: [PATCH] If the SUDO_ASKPASS environment variable is set, tell sudo to use the askpass program to get the user's password. --- lib/vagrant-hostmanager/hosts_file/updater.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-hostmanager/hosts_file/updater.rb b/lib/vagrant-hostmanager/hosts_file/updater.rb index 409cbf4..38e346d 100644 --- a/lib/vagrant-hostmanager/hosts_file/updater.rb +++ b/lib/vagrant-hostmanager/hosts_file/updater.rb @@ -62,7 +62,12 @@ class << self copy_proc = Proc.new { windows_copy_file(file, hosts_location) } else hosts_location = '/etc/hosts' - copy_proc = Proc.new { `[ -w #{hosts_location} ] && cat #{file} > #{hosts_location} || sudo cp #{file} #{hosts_location}` } + if !ENV['SUDO_ASKPASS'].nil? + sudo='sudo -A' + else + sudo='sudo' + end + copy_proc = Proc.new { `[ -w #{hosts_location} ] && cat #{file} > #{hosts_location} || #{sudo} cp #{file} #{hosts_location}` } end FileUtils.cp(hosts_location, file)