Skip to content

Instantly share code, notes, and snippets.

@takuzoo3868
Created May 17, 2019 08:50
Show Gist options
  • Save takuzoo3868/2bf33a37c09202777bcbb712f41c53c0 to your computer and use it in GitHub Desktop.
Save takuzoo3868/2bf33a37c09202777bcbb712f41c53c0 to your computer and use it in GitHub Desktop.
UEC proxy shell script
#!/usr/bin/env bash
# Author: takuzoo3868
# Last Modified: 10 May 2019.
HTTP_PROXY_HOST=proxy.uec.ac.jp
HTTP_PROXY_PORT=8080
HTTPS_PROXY_HOST=proxy.uec.ac.jp
HTTPS_PROXY_PORT=8080
SHELL_RC=$HOME/.bashrc_local
GIT_CONFIG_FILE=$HOME/.gitconfig.local
environment_on(){
sudo sed -i.bak '/http[s]::proxy/Id' /etc/apt/apt.conf
sudo sed -i.bak '/ftp::proxy/Id' /etc/apt/apt.conf
sudo tee -a /etc/apt/apt.conf <<EOF
Acquire::ftp::proxy "ftp://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT/";
Acquire::http::proxy "http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT/";
Acquire::https::proxy "https://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT/";
EOF
sudo sed -i.bak "/all_proxy/Id" /etc/environment
sudo sed -i.bak "/ALL_PROXY/Id" /etc/environment
sudo sed -i.bak "/http_proxy/Id" /etc/environment
sudo sed -i.bak "/HTTP_PROXY/Id" /etc/environment
sudo sed -i.bak "/https_proxy/Id" /etc/environment
sudo sed -i.bak "/HTTPS_PROXY/Id" /etc/environment
sudo sed -i.bak "/ftp_proxy/Id" /etc/environment
sudo sed -i.bak "/FTP_PROXY/Id" /etc/environment
sudo tee -a /etc/environment <<EOF
all_proxy="socks://$HTTP_PROXY_HOST:$HTTPS_PROXY_PORT/"
ALL_PROXY="socks://$HTTP_PROXY_HOST:$HTTPS_PROXY_PORT/"
http_proxy="http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT"
HTTP_PROXY="http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT"
https_proxy="http://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT"
HTTPS_PROXY="http://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT"
ftp_proxy="ftp://$HTTP_PROXY_HOST:$HTTPS_PROXY_PORT"
FTP_PROXY="ftp://$HTTP_PROXY_HOST:$HTTPS_PROXY_PORT"
EOF
echo "set UEC proxy environment for Linux!!!"
}
environment_off(){
sudo sed -i.bak "/http::proxy/Id" /etc/apt/apt.conf
sudo sed -i.bak "/https::proxy/Id" /etc/apt/apt.conf
sudo sed -i.bak "/ftp::proxy/Id" /etc/apt/apt.conf
sudo sed -i.bak "/all_proxy/Id" /etc/environment
sudo sed -i.bak "/ALL_PROXY/Id" /etc/environment
sudo sed -i.bak "/http_proxy/Id" /etc/environment
sudo sed -i.bak "/HTTP_PROXY/Id" /etc/environment
sudo sed -i.bak "/https_proxy/Id" /etc/environment
sudo sed -i.bak "/HTTPS_PROXY/Id" /etc/environment
sudo sed -i.bak "/ftp_proxy/Id" /etc/environment
sudo sed -i.bak "/FTP_PROXY/Id" /etc/environment
echo "See you UEC, welcome my home!!!"
}
proxy_on(){
export http_proxy=http://proxy.uec.ac.jp:8080/
export https_proxy=https://proxy.uec.ac.jp:8080/
export ALL_PROXY=http://proxy.uec.ac.jp:8080/
git config --file $GIT_CONFIG_FILE http.proxy $http_proxy
git config --file $GIT_CONFIG_FILE https.proxy $https_proxy
git config --file $GIT_CONFIG_FILE url."https://".insteadOf git://
echo "set UEC proxy!!!"
}
proxy_off(){
unset http_proxy
unset https_proxy
unset ALL_PROXY
git config --file $GIT_CONFIG_FILE --unset http.proxy
git config --file $GIT_CONFIG_FILE --unset https.proxy
git config --file $GIT_CONFIG_FILE --unset url."https://".insteadOf
echo "unset UEC proxy!!!"
}
if [[ $(uname) = "Linux" ]]; then
if [[ $(iwgetid -r) == "UECWireless" ]] || [[ $(iwgetid -r) == "netarch2_5G" ]] || [[ $(uname -n) == "Sco-Alniyat" ]]; then
proxy_on
environment_on
else
proxy_off
environment_off
fi
elif [[ $(uname) = "Darwin" ]]; then
AIRPORT="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
if test "` ${AIRPORT} -I |grep [^B]SSID|awk '{print $2}'`" = "UECWireless" || test "` ${AIRPORT} -I |grep [^B]SSID|awk '{print $2}'`" = "netarch2_5G"; then
proxy_on
else
proxy_off
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment