#!/bin/bash echo '--------------------------------------' echo 'Proxy Settings' echo '--------------------------------------' menu1='SHOW CURRENT PROXY' menu2='DISABLE' menu3='SET [hoge.co.jp]' menu4='SET [foo.co.jp]' menu5='QUIT' select menu in "$menu1" "$menu2" "$menu3" "$menu4" "$menu5" do if [ -z "$menu" ]; then continue else break fi done case "$menu" in "$menu1" ) printenv | grep proxy $BASH_SOURCE ;; "$menu2" ) unset http_proxy unset https_proxy unset ftp_proxy unset no_proxy echo 'printenv | grep proxy' printenv | grep proxy $BASH_SOURCE ;; "$menu3" ) export http_proxy='http://hoge.co.jp:8080/' export https_proxy='https://hoge.co.jp:8080/' export ftp_proxy='ftp://hoge.co.jp:8080/' export no_proxy='localhost,127.0.0.1' echo 'printenv | grep proxy' printenv | grep proxy $BASH_SOURCE ;; "$menu4" ) export http_proxy='http://foo.co.jp:8090/' export https_proxy='https://foo.co.jp:8090/' export ftp_proxy='ftp://foo.co.jp:8090/' export no_proxy='localhost,127.0.0.1' echo 'printenv | grep proxy' printenv | grep proxy $BASH_SOURCE ;; "$menu5" ) echo bye ;; esac |
直接実行すると,スクリプト内での環境変数の変更が,スクリプト終了時に破棄されてしまう.
なので,sourceコマンドで呼び出す.
$ source proxyswitch.sh |
エイリアスを設定しておくと使いやすい.
ついでに,Windowsで同じようなことをやるバッチ.
@echo off :Menu cls echo -------------------------------------- echo Proxy Settings echo -------------------------------------- echo 1:SHOW CURRENT PROXY echo 2:ENABLE echo 3:DISABLE echo 4:SET [hoge.co.jp] echo 5:SET [foo.co.jp] echo q:QUIT echo -------------------------------------- echo Attention: it changes registry settings. echo -------------------------------------- set Slt=nul set /p Slt="input:" if '%Slt%'=='1' goto Set_1 if '%Slt%'=='2' goto Set_2 if '%Slt%'=='3' goto Set_3 if '%Slt%'=='4' goto Set_4 if '%Slt%'=='5' goto Set_5 if '%Slt%'=='q' goto :eof goto Menu :Set_1 FOR /F "TOKENS=1,2,*" %%A IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable') DO IF "%%A"=="ProxyEnable" SET enable=%%C FOR /F "TOKENS=1,2,*" %%A IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer 2^>nul') DO IF "%%A"=="ProxyServer" SET proxy=%%C if %enable%==0x0 echo [disabled] (%proxy%) if %enable%==0x1 echo [enabled] %proxy% pause goto :Menu :Set_2 reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /f /v ProxyEnable /t reg_dword /d 1 echo Proxy ON reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer pause goto :Menu :Set_3 reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /f /v ProxyEnable /t reg_dword /d 0 echo Proxy OFF pause goto :Menu :Set_4 reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d hoge.co.jp:8080 /f reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer pause goto :Menu :Set_5 reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d foo.co.jp:8090 /f reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer pause goto :Menu |
0 件のコメント:
コメントを投稿