Created
July 21, 2018 03:10
-
-
Save carlosanders/0cc57800eb8f1e7244d06503c7426750 to your computer and use it in GitHub Desktop.
Adicionar proxy no shell do Oracle Linux 7+ (sem interação, tem que configurar o arquivo)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Script Autor: 1T (T) Anders | |
| ########################################################################### | |
| ########################################################################### | |
| ################## ARQUIVOS QUE NÃO PODEM MEXER ########################### | |
| bash_profile_root_file="/root/.bash_profile" | |
| wgetrc_config_file="/etc/wgetrc" | |
| yum_config_file="/etc/yum.conf" | |
| up2date_file="/etc/sysconfig/rhn/up2date" | |
| bashrc_profile_root_file="/root/.bashrc" | |
| ########################################################################### | |
| ########################################################################### | |
| ################## ARQUIVOS QUE PODEM SER PERSONALIZADOS ################## | |
| #user/senha proxy | |
| user_proxy="seuUser" | |
| user_passwd="suaSenha" | |
| #url proxy | |
| url_proxy="suaURL" | |
| port_proxy="8080" | |
| # arquivos do usuario logado na maquina que tera acesso via proxy | |
| user_logado="userDoLinux" | |
| # ou assim caso nao esteja com o root logado | |
| #user_logado=$USER | |
| bash_profile_file="/home/${user_logado}/.bash_profile" | |
| bashrc_profile_file="/home/${user_logado}/.bashrc" | |
| ########################################################################### | |
| ########################################################################### | |
| ver_so=`cat /etc/oracle-release` | |
| # Rotina principal do script e chamada na ordem abaixo do arquivo | |
| main() { | |
| echo -e "\033[01;47;31m>>>>>>>> Servidor: ${ver_so} <<<<<<<<\033[00m" | |
| proxy_go | |
| #deleta_proxy_go | |
| echo -e '\033[00;47;31m----- Provisionamento Concluído ----- \033[00m' | |
| } | |
| #sub-rotina que verifica se existe proxy no sistema | |
| #se sim chama as outras sub-rotinas, evitando duplicidade de proxy no sistema | |
| proxy_go() { | |
| echo -e '\033[01;33m>>>>>>>> Verficando o proxy no Servidor <<<<<<<<\033[00m' | |
| if ! grep -in "proxy" ${bash_profile_root_file}; then | |
| echo -e '\033[00;36mO proxy não está presente! \033[00m' | |
| insere_proxy_go | |
| else | |
| echo -e '\033[00;36mO proxy está presente! \033[00m' | |
| deleta_proxy_go | |
| insere_proxy_go | |
| fi | |
| echo -e '\033[00;36mVerificações de Proxy Concluídas \033[00m' | |
| } | |
| #sub-rotina chamada quando existe proxy no sistema | |
| deleta_proxy_go() { | |
| echo -e '\033[01;33m>>>>>>>> Deletando o proxy no Servidor <<<<<<<<\033[00m' | |
| #apaga ocorrencias de proxy nos arquivos | |
| sudo sed -i '/proxy/d' ${bash_profile_root_file} | |
| sudo sed -i '/proxy/d' ${bash_profile_file} | |
| sudo sed -i '/proxy/d' ${wgetrc_config_file} | |
| sudo sed -i '/proxy/d' ${yum_config_file} | |
| #sudo sed -i '/proxy/d' ${up2date_file} | |
| #Habilita /etc/sysconfig/rhn/up2date | |
| sed -i "s/enableProxy=1/enableProxy=0/g" ${up2date_file} | |
| sed -i "s/proxyPassword=/proxyPassword= /g" ${up2date_file} | |
| sed -i "s/proxyUser= /proxyUser= /g" ${up2date_file} | |
| sed -i "s/httpProxy= /httpProxy= /g" ${up2date_file} | |
| sed -i "s/enableProxyAuth=/enableProxyAuth= /g" ${up2date_file} | |
| sudo sed -i '/proxy-user/d' ${bashrc_profile_root_file} | |
| sudo sed -i '/proxy-user/d' ${bashrc_profile_file} | |
| echo -e '\033[00;36m----- Concluído ----- \033[00m' | |
| } | |
| #sud-rotina chamada para inserir proxy no sistema | |
| insere_proxy_go(){ | |
| echo -e '\033[01;33m>>>>>>>> Inserindo o proxy no Servidor <<<<<<<<\033[00m' | |
| #Habilita .bash_profile do root/vagrant | |
| cat << EOF >> ${bash_profile_root_file} | |
| export http_proxy="http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export ftp_proxy="ftp://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export https_proxy="http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export socks_proxy="socks://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| EOF | |
| cat << EOF >> ${bash_profile_file} | |
| export http_proxy="http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export ftp_proxy="ftp://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export https_proxy="http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export socks_proxy="socks://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| EOF | |
| #Habilita wgetrc | |
| cat << EOF >> ${wgetrc_config_file} | |
| https_proxy = http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}/ | |
| http_proxy = http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}/ | |
| ftp_proxy = http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}/ | |
| use_proxy = on | |
| EOF | |
| #Habilita yum.conf | |
| echo "proxy = http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" >> ${yum_config_file} | |
| #Habilita /etc/sysconfig/rhn/up2date | |
| sed -i "s/enableProxy=0/enableProxy=1/g" ${up2date_file} | |
| sed -i "s/proxyPassword=/proxyPassword=${user_passwd}/g" ${up2date_file} | |
| sed -i "s/proxyUser= /proxyUser=${user_proxy}/g" ${up2date_file} | |
| sed -i "s/httpProxy= /httpProxy=${url_proxy}/g" ${up2date_file} | |
| sed -i "s/enableProxyAuth=/enableProxyAuth=1/g" ${up2date_file} | |
| #Habilita bashrc_profile_root_file | |
| cat << EOF >> ${bashrc_profile_root_file} | |
| alias curl="curl --proxy-user ${user_proxy}:${user_passwd}" | |
| umask 022 | |
| EOF | |
| #Habilita bashrc_profile_file | |
| cat << EOF >> ${bashrc_profile_file} | |
| alias curl="curl --proxy-user ${user_proxy}:${user_passwd}" | |
| umask 022 | |
| EOF | |
| #Habilita export | |
| export http_proxy="http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export ftp_proxy="ftp://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export https_proxy="http://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| export socks_proxy="socks://${user_proxy}:${user_passwd}@${url_proxy}:${port_proxy}" | |
| echo -e '\033[00;36m----- Concluído ----- \033[00m' | |
| } | |
| main | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment