
Tengo un archivo bash, que guardé de forma remota y los pasos siguientes están funcionando.
curl -fsSL -o check.sh https://github.com/uday1kiran/python_deb_create/raw/testbash/tmp/check.sh
chmod 700 check.sh
sudo ./check.sh
Pero, si cambio eso a un comando de una línea, no funciona ni muestra ningún resultado.
curl https://github.com/uday1kiran/python_deb_create/raw/testbash/tmp/check.sh | bash
El código real es:
#!/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 Ubuntu 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
Por favor recomiende.
Respuesta1
Su primer comando, el que funciona, usa -L
la opción de curl que es (de 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. [. . .]
La forma en que funciona tu URL parece ser a través de ese tipo de redirección ya que sin la -L
opción, no obtienes nada:
$ url="https://github.com/uday1kiran/python_deb_create/raw/testbash/tmp/check.sh"
$ curl "$url" 2>/dev/null | wc
0 0 0
Pero con él, obtienes el resultado:
$ 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
Entonces todo lo que necesitas hacer es usar la -L
opción y luego pasarla a sudo bash
(ya que necesitas ejecutarla como root):
curl -L "$url" | sudo bash
Esto es muy arriesgado, por supuesto, y solo ejecute cosas como esta si está 100% seguro de que el script. Además, parece extraño que estés comprobando la presencia de curl
en el script si lo estás utilizando curl
para descargarlo. Ya sabes curl
que está disponible. En cualquier caso, aunque estés probando curl
, tu script en realidad usa wget
en su lugar. Hay varias otras mejoras que puede hacer (las comillas invertidas están obsoletas, úselas var=$(command)
en lugar de var=`command`
; hay mejores formas de verificar la distribución ya que yum se puede instalar en distribuciones que no estén basadas en RedHat y apt
en distribuciones que no sean Debian), pero esas están fuera de tema aquí.