我们有一个多元化的开发团队,一个在Windows上,另一个在Ubuntu上,另一个在OSX上.作为Windows男孩,我设置了流浪汉设置脚本的第一个版本,其工作非常棒;)
但是,在Ubuntu主机上运行它时,第一次进入调用bash脚本的供应步骤时,由于权限而失败.
在Windows中,这没有关系的桑巴份额自动拥有足够的权限来运行bash脚本(驻留在项目层次结构中,因此存在于虚拟机上的/游民的份额),但与Ubuntu的我需要设置在我调用之前,在配置脚本中对此文件的权限.
这不是问题,说实话,我即使有额外的"文件模式"怀疑加强它仍然会在Windows下很好地工作,但是,有没有流浪文件标记某一供应步骤为"仅Windows","办法Linux Only'还是'Mac Only'?
即在pseduo代码中,类似于.
.
.
if (host == windows) then
config.vm.provision : shell, : inline => "/vagrant/provisioning/only_run_this_on_windows.sh"
else if (host == linux) then
config.vm.provision : shell, : inline => "/vagrant/provisioning/only_run_this_on_linux.sh"
else if (host == osx) then
config.vm.provision : shell, : inline => "/vagrant/provisioning/only_run_this_on_osx.sh"
end if
.
.
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Tom*_*ers 56
需要注意的是流浪本身,在对流浪::的Util ::平台类已经实现了平台检查逻辑的更高级版本的答案被BernardoSilva.
所以在Vagrantfile中,您可以简单地使用以下内容:
if Vagrant::Util::Platform.windows? then
myHomeDir = ENV["USERPROFILE"]
else
myHomeDir = "~"
end
Run Code Online (Sandbox Code Playgroud)
Ber*_*lva 45
将其添加到您的Vagrantfile中:
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.windows?
end
def OS.linux?
OS.unix? and not OS.mac?
end
end
Run Code Online (Sandbox Code Playgroud)
然后你可以随意使用它.
if OS.windows? [then]
code...
end
Run Code Online (Sandbox Code Playgroud)
编辑:错过了?如果条件.
用于测试的示例:
is_windows_host = "#{OS.windows?}"
puts "is_windows_host: #{OS.windows?}"
if OS.windows?
puts "Vagrant launched from windows."
elsif OS.mac?
puts "Vagrant launched from mac."
elsif OS.unix?
puts "Vagrant launched from unix."
elsif OS.linux?
puts "Vagrant launched from linux."
else
puts "Vagrant launched from unknown platform."
end
Run Code Online (Sandbox Code Playgroud)
执行:
# Ran provision to call Vagrantfile.
$ vagrant provision
is_windows_host: false
Vagrant launched from mac.
Run Code Online (Sandbox Code Playgroud)
这是一个使用 Vagrant 工具检查 mac 和 windows 的版本:
if Vagrant::Util::Platform.windows?
# is windows
elsif Vagrant::Util::Platform.darwin?
# is mac
else
# is linux or some other OS
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11400 次 |
| 最近记录: |