~/My Command/Set My Proxy.sh
+
#
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110:
#!/bin/bash
dirPropBash=~/".bash_proxy"
dirPropCurl=~/".curlrc"
dirPropWget="/etc/wget"
dirPropApt="/etc/apt/apt.conf"
proxyServer="プロキシーのアドレス"
proxyPort="ポート番号"
command="$1"
function createEmptyFile() {
echo "" > "$1"
sed '1d' "$1" > "$1"
}
function sudoCreateEmptyFile() {
echo "" | sudo tee "$1" 1> /dev/null
sudo sed '1d' "$1" | sudo tee "$1" 1> /dev/null
}
function insertNewLine() {
echo -e "$2" >> "$1"
}
function sudoInsertNewLine() {
echo -e "$2" | sudo tee -a "$1" 1> /dev/null
}
function resetProxyConfig() {
echo -e "#!/bin/bash\n" > "$dirPropBash"
createEmptyFile "$dirPropCurl"
sudoCreateEmptyFile "$dirPropWget"
sudoCreateEmptyFile "$dirPropApt"
}
function addBashProxyConfig() {
local proxy="http://${proxyServer}:${proxyPort}"
insertNewLine "$dirPropBash" "export $1=\"${proxy}\""
export $1="$proxy"
}
function addCurlProxyConfig() {
local proxy="http://${proxyServer}:${proxyPort}"
insertNewLine "$dirPropCurl" "$1=${proxy}"
}
function addWgetProxyConfig() {
local proxy="${proxyServer}:${proxyPort}"
sudoInsertNewLine "$dirPropWget" "$1 = ${proxy}"
}
function addAptProxyConfig() {
local proxy="http://${proxyServer}:${proxyPort}"
sudoInsertNewLine "$dirPropApt" "$1 \"${proxy}\";"
}
function removeBashProxyConfig() {
insertNewLine "$dirPropBash" "export $1=\"\""
unset $1=""
}
case "$command" in
True|true|T|t|1 )
resetProxyConfig
addBashProxyConfig "http_proxy"
addBashProxyConfig "HTTP_PROXY"
addBashProxyConfig "https_proxy"
addBashProxyConfig "HTTPS_PROXY"
addBashProxyConfig "ftp_proxy"
addBashProxyConfig "FTP_PROXY"
addCurlProxyConfig "proxy"
addWgetProxyConfig "http_proxy"
addWgetProxyConfig "https_proxy"
addWgetProxyConfig "ftp_proxy"
addAptProxyConfig "Acquire::http::Proxy"
addAptProxyConfig "Acquire::https::Proxy"
git config --global http.proxy "http://${proxyServer}:${proxyPort}"
echo -e "\e[32;1mプロキシー設定を有効化(ターミナルの再起動が必要な場合があります)\e[m";;
False|false|F|f|0 )
resetProxyConfig
removeBashProxyConfig "http_proxy"
removeBashProxyConfig "HTTP_PROXY"
removeBashProxyConfig "https_proxy"
removeBashProxyConfig "HTTPS_PROXY"
removeBashProxyConfig "ftp_proxy"
removeBashProxyConfig "FTP_PROXY"
git config --global --unset http.proxy
echo -e "\e[31;1mプロキシー設定を無効化(ターミナルの再起動が必要な場合があります)\e[m";;
esac
source "$dirPropBash"