pressly / sup

Super simple deployment tool - think of it like 'make' for a network of servers
https://pressly.github.io/sup
MIT License
2.48k stars 178 forks source link

[WIP] Use posix shell explicitly for remote commands #73

Closed juergenhoetzel closed 8 years ago

juergenhoetzel commented 8 years ago

Fixes issues on BSDs where the default shell is tcsh and "export=" syntax is invalid. Refs #59.

VojtechVitek commented 8 years ago

Please, do not merge. I need to test this properly. Seems like script depending on Bash doesn't work properly anymore -- and also, seems like Env Vars are not exported properly.

juergenhoetzel commented 8 years ago

Seems like script depending on Bash doesn't work properly anymore -- and also, seems like Env Vars are not exported properly.

Exporting works for me. But I can confirm the script issue:

Unmatched '.

Seems to be a quoting issue

eduardonunesp commented 8 years ago

It is something that must be necessary in order to Sup works fine, the /bin/sh shell, unfortunately Sup must require the existence of /bin/sh in the remote host and the internal commands at Sup need to "force" the /bin/sh style.

eduardonunesp commented 8 years ago

@juergenhoetzel Could you please show us that script, or some script that fails like your script.

VojtechVitek commented 8 years ago

Given Supfile

commands:
  build:
    script: ./build.sh

and ./build.sh:

#!/bin/bash -eu

[[ "hello" != "there" ]] && exit 0 || exit 1 

We need to make sure this is run under Bash, since there's #!/bin/bash at the very beginning of the file. Otherwise, we're gonna break things for many users. Actually, this bite me yesterday pretty bad, since ENV VARs didn't work properly and coincidently, this managed to kill one of my servers.

I don't want to implement parser for the script's first line on a Golang side. We need to figure out a native solution in /bin/sh itself.

VojtechVitek commented 8 years ago

@juergenhoetzel btw: does your FreeBSD have /bin/bash natively? I'm inclined to switch to Bash by default for now, if available everywhere.

eduardonunesp commented 8 years ago

A native solution to check which interpreter is using, is echo $0

juergenhoetzel commented 8 years ago

@juergenhoetzel btw: does your FreeBSD have /bin/bash natively? I'm inclined to switch to Bash by default for now, if available everywhere.

Bash is not part of the base system. It has to be installed from ports: /usr/local/bin/bash A portable way to invoke bash would be:

#!/usr/bin/env bash
juergenhoetzel commented 8 years ago

and ./build.sh:

!/bin/bash -eu

[[ "hello" != "there" ]] && exit 0 || exit 1

As far as I can see the shebang is not used in the sup implementation. It's just a comment, because its send as shell command and is not executed as a script:

VojtechVitek commented 8 years ago

@juergenhoetzel correct, the idea is to let the remote shells parse the shebangs, since we want to use /bin/sh by default. Thus, this /bin/sh should invoke another bash, if it sees #!/bin/bash shebank. I'm not a huge fun of temp files, but that might be an option.

juergenhoetzel commented 8 years ago

I'm not a huge fun of temp files, but that might be an option.

This was exactly what i was thinking about. Have you considered using sftp subsystem for file transfer? https://github.com/pkg/sftp instead of piping?

VojtechVitek commented 8 years ago

Closing in favor of #77.