脚本介绍:
由于xx公司特殊原因导致服务器无法下载相关文件,自己搜索了很久写了一个脚本来实现,脚本用root账号运行的。可以不使用root,其他普通账号都可以
代理端:CCProxy工具,几乎没啥可配置的东西,windows启动起来就行了。
CCproyx配置
export具体想写入哪个配置文件内,改一下" _PATH "配置就行了。
#!/bin/sh
# Author:
# Date: 2021/11/3
# DESC:
# filename: httpProxy.sh
# environment
_PATH=~/.bashrc
# proxy
variableExists(){
cat >> ${_PATH} << EOF
#ccproxy
export https_proxy=https://xx.xx.xx.xx:808
export http_proxy=http://xx.xx.xx.xx:808
EOF
}
# Determine whether the file has a proxy
grep 'export http' ${_PATH} > /dev/null
_num=`echo $?`
if [[ ${_num} -ne 0 ]]; then
variableExists
fi
# source .bashrc
sourcebashrc(){
. ${_PATH}
}
# Show current file information
showbashrc(){
echo "Current state:
*--------------------------------------------"
sed -n '/export http*/p' ${_PATH}
echo "*--------------------------------------------"
}
# case choose
case $1 in
1)
sed -i 's/^export http*/#export http/g' ${_PATH}
sourcebashrc
showbashrc
;;
2)
sed -i 's/^#export http*/export http/g' ${_PATH}
sourcebashrc
showbashrc
;;
*)
echo "EXP:
sh httpProxy.sh [1/2]"
echo "---------------------"
echo "1 ---close http proxy"
echo "2 ---open http proxy"
echo "---------------------"
showbashrc
esac