Reputation: 4050
I want to run a script from GitHub with curl, and I can do this easily with:
# This is safe to run but will add a few lines to .bashrc, .vimrc, .inputrc to add some configuration options.
# Please check the project before running:
# https://raw.github.com/roysubs/custom_bash/
# But this is just to illustrate the point, bash shell script on GitHub, and how to use curl to pipe it to bash
curl -s https://raw.githubusercontent.com/roysubs/custom_bash/master/custom_loader.sh | bash
I have a few problems with this however that I was hoping for some help with:
read -e -p
statements to take input from the console. I'd appreciate if there is a better way to run the script such that it does not do this. Other methods to do this would be great.curl
method to work using this. i.e. curl -s https://git.io/Jt0fZ | bash
Does anyone know why this fails and for a workaround to use the shortened url to execute the remote script?Upvotes: 4
Views: 12223
Reputation: 8741
The "Firstly" is more complex, but you might try a temporary shell script without using pipe.
curl -s https://raw.githubusercontent.com/roysubs/custom_bash/master/custom_loader.sh >tmp.sh
bash tmp.sh
Your "Secondly" question is very easy to explain, when you do curl -s https://git.io/Jt0fZ
, we get a Redirect 302, here is hints:
We try to get headers only from the server:
curl --head https://git.io/Jt0fZ
HTTP/1.1 302 Found
Server: Cowboy
Connection: keep-alive
Date: Sun, 25 Apr 2021 14:24:43 GMT
Status: 302 Found
Content-Type: text/html;charset=utf-8
Location: https://raw.githubusercontent.com/roysubs/custom_bash/master/custom_loader.sh
Content-Length: 0
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.003242
X-Node: 69d60833-56c5-4364-94c1-6f0c5b12863f
X-Revision: 392798d237fc1aa5cd55cada10d2945773e741a8
Strict-Transport-Security: max-age=31536000; includeSubDomains
Via: 1.1 vegur
We see HTTP/1.1 302 Found
and Location: https://raw.githubusercontent.com/roysubs/custom_bash/master/custom_loader.sh
, not the real content of the latter.
So bash gets empty script to run, by default, curl does not do a second call to the new location, as does graphic webbrowsers usually do.
But you can do this to overcome the default:
curl -L https://git.io/Jt0fZ | bash
man curl gives this:
-L, --location (HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place.
Upvotes: 4