AoEiuV020CN
2022-08-08 10:31:19 +08:00
不一定有效,毕竟 linux 情况比 windows 复杂,
以下代码 export 变量针对的是命令行,dconf 针对的是类 gnome 桌面里的“系统代理”,
proxy() {
echo setup system proxy...
export http_proxy_host='proxyhost'
export socks_proxy_host=$http_proxy_host
export http_proxy_port='1082'
export socks_proxy_port='1081'
export ALL_PROXY="socks5://$socks_proxy_host:$socks_proxy_port/"
# ftp 代理会导致 wget 无法下载 ftp 文件,
unset FTP_PROXY
export HTTPS_PROXY="http://$http_proxy_host:$http_proxy_port/"
export HTTP_PROXY="http://$http_proxy_host:$http_proxy_port/"
# 写死 127.0.0.1 因为 flutter 的 websocket 需要,
export NO_PROXY="localhost,127.0.0.1,127.0.0.0/8,::1"
export all_proxy=$ALL_PROXY
unset ftp_proxy
export http_proxy=$HTTP_PROXY
export https_proxy=$HTTPS_PROXY
export no_proxy=$NO_PROXY
which dconf &>/dev/null && (
dconf write /system/proxy/http/host "'$http_proxy_host'"
dconf write /system/proxy/http/port "$http_proxy_port"
dconf write /system/proxy/https/host "'$http_proxy_host'"
dconf write /system/proxy/https/port "$http_proxy_port"
dconf reset /system/proxy/ftp/host
dconf reset /system/proxy/ftp/port
dconf write /system/proxy/socks/host "'$socks_proxy_host'"
dconf write /system/proxy/socks/port "$socks_proxy_port"
dconf write /system/proxy/ignore-hosts "['localhost', '127.0.0.1', '127.0.0.0/8', '::1']"
dconf write /system/proxy/mode "'manual'"
) || true
}
noproxy() {
unset ALL_PROXY
unset FTP_PROXY
unset HTTPS_PROXY
unset HTTP_PROXY
unset NO_PROXY
unset all_proxy
unset ftp_proxy
unset http_proxy
unset https_proxy
unset no_proxy
which dconf &>/dev/null && (
dconf write /system/proxy/mode "'none'"
) || true
}