简体   繁体   English

Windows + Cygwin +单行(如果没有)+人偶

[英]Windows + Cygwin + Single Line If Else + Puppet

So I have a single line bash command that checks if a directory exists. 因此,我有一个单行bash命令来检查目录是否存在。 If it does, it git pulls, if it doesn't, it clones the repository. 如果是,它将进行git pull;否则,将克隆存储库。 I am running a Cygwin on my Windows box and when I run this command in Cygwin it works perfectly: 我在Windows机器上运行Cygwin,当我在Cygwin中运行此命令时,它运行良好:

if [ -d C:/repo ]; then cd C:/repo && "C:/Program Files (x86)/Git/bin/git.exe" pull; else "C:/Program Files (x86)/Git/bin/git.exe" clone -b develop https://repo.git C:/repo; fi

When I run the same command from Puppet though like this: 当我从Puppet运行相同的命令时,如下所示:

exec {'checkout repository':
    command => "if [ -d C:/repo ]; then cd C:/repo && "C:/Program Files (x86)/Git/bin/git.exe" pull; else "C:/Program Files (x86)/Git/bin/git.exe" clone -b develop https://repo.git C:/repo; fi"
}

I get error: 我得到错误:

Error: ' if [ -d C:/repo ]; 错误:'如果[[-d C:/ repo]; then cd C:/repo && "C:/Program Files (x86)/Git/bin/git.exe" pull; 然后cd C:/ repo &&“ C:/ Program Files(x86)/Git/bin/git.exe”拉; else "C:/Program Files (x86)/Git/bin/git.exe" clone -b develop https://repo.git C:/repo; 否则“ C:/ Program Files(x86)/Git/bin/git.exe”克隆-b开发https://repo.git C:/ repo; fi' is not qualified and no path was specified. fi'不合格,未指定路径。 Please qualify the command or specify a path. 请限定命令或指定路径。

Any ideas why? 有什么想法吗?

Puppet is a native Windows program (it works without cygwin). Puppet是本地Windows程序(无需cygwin即可工作)。 What you have written in the command -parameter is basically a short sh(1) script. 您在命令-parameter中编写的基本上是一个简短的sh(1)脚本。 Windows does not have sh(1) by default, although it is provided by cygwin. Windows默认情况下没有cy(1),尽管它由cygwin提供。 So puppet on windows will not try to execute the contents of command via sh(1). 因此,Windows上的p不会尝试通过sh(1)执行命令的内容。 It should be the (absolute) name of a windows executable, with optional parameters. 它应该是Windows可执行文件的(绝对)名称,带有可选参数。 If you wish to invoke a cmd.exe builtin, you need to do something like command => 'cmd /c dir' . 如果您希望调用内置的cmd.exe,则需要执行类似command => 'cmd /c dir'

escape your quotes or use single quotes and use cygdrive, so your code should look like this: 转义您的引号或使用单引号并使用cygdrive,因此您的代码应如下所示:

exec {'checkout repository':
    command => "if [ -d C:/repo ]; then cd C:/repo && 'C:/Program Files (x86)/Git/bin/git.exe' pull; else 'C:/Program Files (x86)/Git/bin/git.exe' clone -b develop https://repo.git C:/repo; fi"
}

and this: 和这个:

exec {'checkout repository':
    command => "if [ -d /cygdrive/c/repo ]; then cd /cygdrive/c/repo && '/cygdrive/c/Program Files (x86)/Git/bin/git.exe' pull; else '/cygdrive/c/Program Files (x86)/Git/bin/git.exe' clone -b develop https://repo.git /cygdrive/c/repo; fi"
}

And if you even install git inside cygwin, you can make it simpler: 而且,即使您在cygwin中安装git,也可以使其更简单:

exec {'checkout repository':
    command => "if [ -d /cygdrive/c/repo ]; then cd /cygdrive/c/repo && git pull; else git clone -b develop https://repo.git /cygdrive/c/repo; fi"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM