From 023d3115dd5a74f406600ba450f1a2a1ed188fcf Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Sun, 2 Feb 2014 17:38:24 -0300 Subject: [PATCH] guests/{free,net,open}bsd: Add `shell_expand_guest_path` capability --- .../freebsd/cap/shell_expand_guest_path.rb | 27 +++++++++++++++++++ plugins/guests/freebsd/plugin.rb | 5 ++++ .../netbsd/cap/shell_expand_guest_path.rb | 26 ++++++++++++++++++ plugins/guests/netbsd/plugin.rb | 5 ++++ .../openbsd/cap/shell_expand_guest_path.rb | 26 ++++++++++++++++++ plugins/guests/openbsd/plugin.rb | 5 ++++ 6 files changed, 94 insertions(+) create mode 100644 plugins/guests/freebsd/cap/shell_expand_guest_path.rb create mode 100644 plugins/guests/netbsd/cap/shell_expand_guest_path.rb create mode 100644 plugins/guests/openbsd/cap/shell_expand_guest_path.rb diff --git a/plugins/guests/freebsd/cap/shell_expand_guest_path.rb b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb new file mode 100644 index 000000000..6d2f6e16a --- /dev/null +++ b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb @@ -0,0 +1,27 @@ +module VagrantPlugins + module GuestFreeBSD + module Cap + class ShellExpandGuestPath + def self.shell_expand_guest_path(machine, path) + real_path = nil + machine.communicate.execute("printf #{path}", + shell: "sh") do |type, data| + if type == :stdout + real_path ||= "" + real_path += data + end + end + + if !real_path + # If no real guest path was detected, this is really strange + # and we raise an exception because this is a bug. + raise ShellExpandFailed + end + + # Chomp the string so that any trailing newlines are killed + return real_path.chomp + end + end + end + end +end diff --git a/plugins/guests/freebsd/plugin.rb b/plugins/guests/freebsd/plugin.rb index 8e147087b..4392a1614 100644 --- a/plugins/guests/freebsd/plugin.rb +++ b/plugins/guests/freebsd/plugin.rb @@ -30,6 +30,11 @@ module VagrantPlugins require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder end + + guest_capability("freebsd", "shell_expand_guest_path") do + require_relative "cap/shell_expand_guest_path" + Cap::ShellExpandGuestPath + end end end end diff --git a/plugins/guests/netbsd/cap/shell_expand_guest_path.rb b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb new file mode 100644 index 000000000..8471f4724 --- /dev/null +++ b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb @@ -0,0 +1,26 @@ +module VagrantPlugins + module GuestNetBSD + module Cap + class ShellExpandGuestPath + def self.shell_expand_guest_path(machine, path) + real_path = nil + machine.communicate.execute("printf #{path}") do |type, data| + if type == :stdout + real_path ||= "" + real_path += data + end + end + + if !real_path + # If no real guest path was detected, this is really strange + # and we raise an exception because this is a bug. + raise ShellExpandFailed + end + + # Chomp the string so that any trailing newlines are killed + return real_path.chomp + end + end + end + end +end diff --git a/plugins/guests/netbsd/plugin.rb b/plugins/guests/netbsd/plugin.rb index ca55706fc..382754ffe 100644 --- a/plugins/guests/netbsd/plugin.rb +++ b/plugins/guests/netbsd/plugin.rb @@ -30,6 +30,11 @@ module VagrantPlugins require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder end + + guest_capability("netbsd", "shell_expand_guest_path") do + require_relative "cap/shell_expand_guest_path" + Cap::ShellExpandGuestPath + end end end end diff --git a/plugins/guests/openbsd/cap/shell_expand_guest_path.rb b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb new file mode 100644 index 000000000..653493548 --- /dev/null +++ b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb @@ -0,0 +1,26 @@ +module VagrantPlugins + module GuestOpenBSD + module Cap + class ShellExpandGuestPath + def self.shell_expand_guest_path(machine, path) + real_path = nil + machine.communicate.execute("printf #{path}") do |type, data| + if type == :stdout + real_path ||= "" + real_path += data + end + end + + if !real_path + # If no real guest path was detected, this is really strange + # and we raise an exception because this is a bug. + raise ShellExpandFailed + end + + # Chomp the string so that any trailing newlines are killed + return real_path.chomp + end + end + end + end +end diff --git a/plugins/guests/openbsd/plugin.rb b/plugins/guests/openbsd/plugin.rb index fc1043a53..cf6dec82e 100644 --- a/plugins/guests/openbsd/plugin.rb +++ b/plugins/guests/openbsd/plugin.rb @@ -30,6 +30,11 @@ module VagrantPlugins require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder end + + guest_capability("openbsd", "shell_expand_guest_path") do + require_relative "cap/shell_expand_guest_path" + Cap::ShellExpandGuestPath + end end end end