Your first command, the one that works, uses curl's -L
option which is (from man curl
):
-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 re‐
quest on the new place. [. . .]
The way your URL works seems to be through that kind of redirection since without the -L
option, you get nothing:
$ url="https://github.com/uday1kiran/python_deb_create/raw/testbash/tmp/check.sh"
$ curl "$url" 2>/dev/null | wc
0 0 0
But with it, you get output:
$ curl -L "$url" 2>/dev/null
#!/usr/bin/env bash
count_apt=`whereis apt`
count_yum=`whereis yum`
## echo ${#count_apt} ${#count_yum}
if (( ${#count_yum} > 4 )); then
echo "---Redhat distributions are not supported---"
exit 0
fi
if (( ${#count_apt} > 4 )); then
echo "---Found Debian Distribution---"
echo "---Started installation of dependencies---"
apt install -y curl
wget https://xenowulf-deb.s3.us-west-2.amazonaws.com/agentxw_1.036-1_amd64.deb
apt install -y ./agentxw_1.036-1_amd64.deb
wget https://xenowulf-deb.s3.us-west-2.amazonaws.com/xvision_0.97-1_amd64.deb
apt install -y ./xvision_0.97-1_amd64.deb
echo "---Completed installation of dependencies---"
echo "---Started installation of main package with its dependencies: xenowulf-ai---"
wget https://github.com/uday1kiran/python_deb_create/raw/testdeb2/tmp/xenowulf-ai_1.0_all.deb
apt install -y ./xenowulf-ai_1.0_all.deb
echo "---Completed installation of main pacakge: xenowulf-ai---"
fi
So all you need to do is use the -L
option and then pass it to sudo bash
(since you need to run it as root):
curl -L "$url" | sudo bash
This is very risky, of course, and only run things like this if you are 100% the script is safe. Also, it seems weird that you are checking for the presence of curl
in the script if you are using curl
to download it. You already know curl
is available. In any case, although you are testing for curl
, your script actually uses wget
instead. There are various other improvements you can make (backticks are deprecated, use var=$(command)
instead of var=`command`
; there are better ways of checking the distribution since yum can be installed on non RedHat based distros and apt
on non-Debian ones), but those are off topic here.