Skip to content

Commit

Permalink
Merge pull request #25 from SkullTech/capitalised-envs
Browse files Browse the repository at this point in the history
Add support for capitalised proxy environment variables
  • Loading branch information
himanshub16 authored Jun 23, 2017
2 parents 07fd704 + d1fb46e commit 0e6c964
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ fix_new_line() {
list_proxy() {
echo
echo -e "\e[1m Bash proxy settings \e[0m"
lines="$(cat $HOME/.bashrc | grep proxy | wc -l)"
lines="$(cat $HOME/.bashrc | grep proxy -i | wc -l)"
if [ "$lines" -gt 0 ]; then
cat $HOME/.bashrc | grep proxy | sed "s/\=/\ /g"
cat $HOME/.bashrc | grep proxy -i | sed "s/\=/\ /g"
else
echo -e "\e[36m None \e[0m"
fi
Expand All @@ -72,6 +72,7 @@ unset_proxy() {
return
fi
sed -i "/proxy\=/d" $HOME/.bashrc
sed -i "/PROXY\=/d" $HOME/.bashrc
}

set_proxy() {
Expand All @@ -90,6 +91,9 @@ set_proxy() {
echo "http_proxy=\"http$newvar\"" >> bash_config.tmp
echo "https_proxy=\"https$newvar\"" >> bash_config.tmp
echo "ftp_proxy=\"ftp$newvar\"" >> bash_config.tmp
echo "HTTP_PROXY=\"http$newvar\"" >> bash_config.tmp
echo "HTTPS_PROXY=\"https$newvar\"" >> bash_config.tmp
echo "FTP_PROXY=\"ftp$newvar\"" >> bash_config.tmp

fix_new_line $HOME/.bashrc
cat bash_config.tmp | tee -a $HOME/.bashrc > /dev/null
Expand All @@ -100,6 +104,9 @@ set_proxy() {
echo "http_proxy=\"http://$var$1:$2\"" >> bash_config.tmp
echo "https_proxy=\"https://$var$7:$8\"" >> bash_config.tmp
echo "ftp_proxy=\"ftp://$var$9:$10\"" >> bash_config.tmp
echo "HTTP_PROXY=\"http://$var$1:$2\"" >> bash_config.tmp
echo "HTTPS_PROXY=\"https://$var$7:$8\"" >> bash_config.tmp
echo "FTP_PROXY=\"ftp://$var$9:$10\"" >> bash_config.tmp

cat bash_config.tmp | tee -a $HOME/.bashrc > /dev/null
rm bash_config.tmp
Expand Down
11 changes: 9 additions & 2 deletions environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ fix_new_line() {
list_proxy() {
echo
echo -e "\e[1m Environment proxy settings \e[0m"
lines="$(cat /etc/environment | grep proxy | wc -l)"
lines="$(cat /etc/environment | grep proxy -i | wc -l)"
if [ "$lines" -gt 0 ]; then
cat "/etc/environment" | grep proxy | sed "s/\=/\ /g"
cat "/etc/environment" | grep proxy -i | sed "s/\=/\ /g"
else
echo -e "\e[36m None \e[0m"
fi
Expand All @@ -73,6 +73,7 @@ unset_proxy() {
return
fi
sed -i "/proxy\=/d" /etc/environment
sed -i "/PROXY\=/d" /etc/environment
}

set_proxy() {
Expand All @@ -91,6 +92,9 @@ set_proxy() {
echo "http_proxy=\"http$newvar\"" >> bash_config.tmp
echo "https_proxy=\"https$newvar\"" >> bash_config.tmp
echo "ftp_proxy=\"ftp$newvar\"" >> bash_config.tmp
echo "HTTP_PROXY=\"http$newvar\"" >> bash_config.tmp
echo "HTTPS_PROXY=\"https$newvar\"" >> bash_config.tmp
echo "FTP_PROXY=\"ftp$newvar\"" >> bash_config.tmp

cat bash_config.tmp | tee -a /etc/environment > /dev/null
rm bash_config.tmp
Expand All @@ -100,6 +104,9 @@ set_proxy() {
echo "http_proxy=\"http://$var$1:$2\"" >> bash_config.tmp
echo "https_proxy=\"https://$var$7:$8\"" >> bash_config.tmp
echo "ftp_proxy=\"ftp://$var$9:$10\"" >> bash_config.tmp
echo "HTTP_PROXY=\"http://$var$1:$2\"" >> bash_config.tmp
echo "HTTPS_PROXY=\"https://$var$7:$8\"" >> bash_config.tmp
echo "FTP_PROXY=\"ftp://$var$9:$10\"" >> bash_config.tmp

fix_new_line "/etc/environment"
cat bash_config.tmp | tee -a /etc/environment > /dev/null
Expand Down

0 comments on commit 0e6c964

Please sign in to comment.