Скажем, у меня есть следующий файл my_cool_file.sh в репозитории Git в Github (или BitBucket, если на то пошло) с именем my_cool_repo. Файл - это скрипт, используемый для установки хорошо известного программного обеспечения CSF-LFD от ConfigServer:
#!/bin/bash
cd /usr/src
rm -fv csf.tgz
wget https://download.configserver.com/csf.tgz
tar -xzf csf.tgz
cd csf
sh install.sh
sed -i "s/TESTING = "1"/TESTING = "0"/g" /etc/csf/csf.conf
csf -r
perl /usr/local/csf/bin/csftest.pl
# sh /etc/csf/uninstall.sh
Как выполнить этот сценарий Bash (файл .sh) непосредственно из Github через командную строку?
Загрузите файл (убедитесь, что вы используете необработанный файл, иначе вы загружаете HTML-страницу!) с помощью wget, используя его точный URL-адрес, а затем передайте вывод на bash:
пример с пояснениями:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash
Из manpage для команды wget:
-O file
--output-document=file
The documents will not be written to the appropriate files, but all
will be concatenated together and written to file. If - is used as
file, documents will be printed to standard output, disabling link
conversion. (Use ./- to print to a file literally named -.)
Use of -O is not intended to mean simply "use the name file instead
of the one in the URL;" rather, it is analogous to shell
redirection: wget -O file http://foo is intended to work like wget
-O - http://foo > file; file will be truncated immediately, and all
downloaded content will be written there.
Таким образом, вывод на - будет фактически писать содержимое файлов в STDOUT, а затем вы просто подключаете его к bash или любой другой оболочке, которую вы предпочитаете. Если вам нужен скрипт sudo, вам нужно сделать sudo bash в конце, чтобы строка стала:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | sudo bash
Загрузите файл (убедитесь, что вы используете необработанный файл, иначе вы загружаете HTML-страницу!) с помощью wget, используя его точный URL-адрес, а затем передайте вывод на bash:
пример с пояснениями:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash
Из manpage для команды wget:
-O file
--output-document=file
The documents will not be written to the appropriate files, but all
will be concatenated together and written to file. If - is used as
file, documents will be printed to standard output, disabling link
conversion. (Use ./- to print to a file literally named -.)
Use of -O is not intended to mean simply "use the name file instead
of the one in the URL;" rather, it is analogous to shell
redirection: wget -O file http://foo is intended to work like wget
-O - http://foo > file; file will be truncated immediately, and all
downloaded content will be written there.
Таким образом, вывод на - будет фактически писать содержимое файлов в STDOUT, а затем вы просто подключаете его к bash или любой другой оболочке, которую вы предпочитаете. Если вам нужен скрипт sudo, вам нужно сделать sudo bash в конце, чтобы строка стала:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | sudo bash
Загрузите файл (убедитесь, что вы используете необработанный файл, иначе вы загружаете HTML-страницу!) с помощью wget, используя его точный URL-адрес, а затем передайте вывод на bash:
пример с пояснениями:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash
Из manpage для команды wget:
-O file
--output-document=file
The documents will not be written to the appropriate files, but all
will be concatenated together and written to file. If - is used as
file, documents will be printed to standard output, disabling link
conversion. (Use ./- to print to a file literally named -.)
Use of -O is not intended to mean simply "use the name file instead
of the one in the URL;" rather, it is analogous to shell
redirection: wget -O file http://foo is intended to work like wget
-O - http://foo > file; file will be truncated immediately, and all
downloaded content will be written there.
Таким образом, вывод на - будет фактически писать содержимое файлов в STDOUT, а затем вы просто подключаете его к bash или любой другой оболочке, которую вы предпочитаете. Если вам нужен скрипт sudo, вам нужно сделать sudo bash в конце, чтобы строка стала:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | sudo bash