0

I'm serving a Go binary located in /var/www/bin/binary:

location ~ (binary) {
     root /var/www/bin;
}

However, when I download it with wget http://example.com/binary, I can't run it right away, since it's not an executable anymore. I need to run chmod +x binary first.

How can I fix this? Thanks.

Edit: found a similar question with a larger discussion: https://unix.stackexchange.com/questions/82578/why-is-that-when-i-download-a-binary-from-the-web-it-doesnt-have-executable-per

Alex
  • 139
  • 10

1 Answers1

3

File permissions are not communicated in the process of an HTTP file transfer. All nginx does is open the binary file, read the data, and stream it to the client (wget). Setting permissions on the client machine is determined by the umask on the client, and whatever else your web client browser might do to it.

If you're looking to simplify the steps to download and execute the binary, there are a few approaches you could take. One would simply be:

wget -O binary http://example.com/binary && chmod +x ./binary && ./binary

Or, you could place a shell script at http://example.com/install.sh:

#!/bin/sh

if wget -O "binary" "http://example.com/binary"; then
    chmod +x "./binary"
    echo "Successfully installed binary. To run, use: ./binary"

    # Or just run it here:
    # ./binary
else
    echo "Failed to download binary." >&2
fi

Then, your installation can be:

wget -O - http://example.com/install.sh | sh

Or:

curl -o - http://example.com/install.sh | sh

Note that none of these methods of installation are secure, at all. You need to calculate signatures for the binary (and the shell script) and verify them at download time, and I recommend using HTTPS. But, I'm assuming this is for some type of internal use (in which case, security is still usually important)!

Will
  • 1,147
  • 10
  • 26
  • Thanks for the explanation. I come from a Windows world where all you need is an exe fie. I thought it was the same in nix, but I guess it makes sense from a security point of view. – Alex Jan 03 '16 at 13:47