
Eu tenho um arquivo bash, que mantive remotamente e as etapas abaixo estão 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
Mas, se eu mudar isso para um comando de linha, ele não estará funcionando/mostrando nenhuma saída.
curl https://github.com/uday1kiran/python_deb_create/raw/testbash/tmp/check.sh | bash
O código real é:
#!/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 sugira.
Responder1
Seu primeiro comando, aquele que funciona, usa -L
a opção curl que é (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. [. . .]
A forma como sua URL funciona parece ser por meio desse tipo de redirecionamento, pois sem a -L
opção você não ganha nada:
$ url="https://github.com/uday1kiran/python_deb_create/raw/testbash/tmp/check.sh"
$ curl "$url" 2>/dev/null | wc
0 0 0
Mas com isso, você obtém a saída:
$ 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
Então tudo que você precisa fazer é usar a -L
opção e passá-la para sudo bash
(já que você precisa executá-la como root):
curl -L "$url" | sudo bash
Isso é muito arriscado, claro, e só execute coisas assim se você tiver 100% de segurança do script. Além disso, parece estranho que você esteja verificando a presença de curl
no script se estiver usando curl
para baixá-lo. Você já sabe curl
que está disponível. De qualquer forma, embora você esteja testando curl
, seu script realmente usa wget
. Existem várias outras melhorias que você pode fazer (crases estão obsoletos, use var=$(command)
em vez de var=`command`
; existem maneiras melhores de verificar a distribuição, já que o yum pode ser instalado em distros não baseadas em RedHat e apt
em distros não-Debian), mas essas estão fora do tópico aqui.