Running commands or script lines with simple tests, like -e
, in vagrant
using the ssh
subcommand works fine (e.g.
vagrant ssh -c 'if ! [ -e file.deb ] ; then wget http://a.b/file.deb; fi'
as soon as string comparison and command execution bash
quoting gets involved, complexity immediately rises to the sky. I tried
- escaping strings, but that doesn't seem to work in general (complexity of escaping of escaping of escaping ... in
bash
is just inacceptable) writing everything in a script file with
cat <<EOF > file [code]EOF
idiom, e.g.vagrant ssh -c 'cat <<EOF > fetch.sh \ #!/bin/bash \ if [ "$(md5sum file.deb | cut -d \" \" -f 1)" != "d757d51819f8f945ae7715b532ab8d2e" ] ; then wget http://a/b/file.deb; fi \ EOF' vagrant ssh -c 'bash ./fetch.sh'
causes
./fetch.sh: line 1: syntax error near unexpected token `if'
- the failure of the
cat EOF
idiom implies failure of any sort of script created invagrant
(python
,groovy
, etc. would suffer from the same incapacity ofbash
to provide usable string quoting/be usable at all)
Is there any way to execute script code with complex statements in tests inside a vagrant
box? Do I seriously need to transfer the script via the localhost interface (using FTP or something similar)?