Skip to content

Instantly share code, notes, and snippets.

@lockdef
Last active February 16, 2024 07:05
Show Gist options
  • Save lockdef/0b57d0837da153e45eb6293cefa44ef4 to your computer and use it in GitHub Desktop.
Save lockdef/0b57d0837da153e45eb6293cefa44ef4 to your computer and use it in GitHub Desktop.
茨城高専の学内Wifi接続時のプロキシ設定を自動化するスクリプト、.bashrcに記入しておく

setProxy.sh

茨城高専の学内Wifi接続時のプロキシ設定を自動化するスクリプト

.bashrcに書いておくとターミナル起動時に自動でプロキシ設定を行う

使用手順

  1. setProxy.sh.bashrcにコピペする
  2. terminalでiwconfigを実行しwifi受信機のインターフェイス名を取得する(例:wlp3s0)
  3. 6行目のINTERFACE_NAMEの値を取得したインターフェイス名に書き換える(例:INTERFACE_NAME=wlp3s0)

WSL/WSL2向け

WSL/WSL2ではiwconfigが使用出来ないので、入力によってプロキシ設定の判定を行う

使用手順

  1. setProxyWSL.sh.bashrcにコピペする

対応リスト

  • 環境変数
  • git
  • npm
  • yarn
  • apt
#bash用
PROXY=po.cc.ibaraki-ct.ac.jp:3128
HTTP_PROXY=http://${PROXY}
HTTPS_PROXY=http://${PROXY}
INTERFACE_NAME=wlp3s0
SSID=ibakosen
NAME=`iwconfig ${INTERFACE_NAME} | grep ESSID`
if [ `echo ${NAME##*ESSID:} | grep ${SSID}` ];then
export http_proxy=${HTTP_PROXY}
export https_proxy=${HTTPS_PROXY}
git config --global http.proxy ${HTTP_PROXY}
git config --global https.proxy ${HTTPS_PROXY}
npm -g config set proxy ${HTTP_PROXY}
npm -g config set https-proxy ${HTTP_PROXY}
npm -g config set registry "http://registry.npmjs.org/"
yarn config set proxy ${HTTP_PROXY} -g > /dev/null 2>&1
yarn config set https-proxy ${HTTP_PROXY} -g > /dev/null 2>&1
alias sudo="sudo -E "
else
unset http_proxy
unset https_proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
npm -g config delete proxy
npm -g config delete https-proxy
npm -g config delete registry
yarn config delete proxy -g > /dev/null 2>&1
yarn config delete https-proxy -g > /dev/null 2>&1
fi
# WSL/WSL2用
# 実行時に入力を受け取りプロキシの設定を行う
PROXY=po.cc.ibaraki-ct.ac.jp:3128
HTTP_PROXY=http://${PROXY}
HTTPS_PROXY=http://${PROXY}
echo "set proxy of kosen? (y/n)"
read proxy
if [ "${proxy}" = "y" ];then
export http_proxy=${HTTP_PROXY}
export https_proxy=${HTTPS_PROXY}
git config --global http.proxy ${HTTP_PROXY}
git config --global https.proxy ${HTTPS_PROXY}
npm -g config set proxy ${HTTP_PROXY}
npm -g config set https-proxy ${HTTP_PROXY}
npm -g config set registry "http://registry.npmjs.org/"
yarn config set proxy ${HTTP_PROXY} -g > /dev/null 2>&1
yarn config set https-proxy ${HTTP_PROXY} -g > /dev/null 2>&1
alias sudo="sudo -E "
else
unset http_proxy
unset https_proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
npm -g config delete proxy
npm -g config delete https-proxy
npm -g config delete registry
yarn config delete proxy -g > /dev/null 2>&1
yarn config delete https-proxy -g > /dev/null 2>&1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment