-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy
65 lines (56 loc) · 1.72 KB
/
proxy
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
#!/bin/bash
#use source or .(dot)
#Script_Path=$(dirname `which $0`)
Script_Path="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ini_path="${Script_Path}/proxy.ini"
#echo $ini_path
if [ ! -d "${Script_Path}/tmp" ]; then
mkdir "${Script_Path}/tmp"
fi
if [ ! -e "${ini_path}" ]; then
echo "proxy.ini missing"
return 1
fi
conf=( `cat "${ini_path}"` )
if [ ${#conf} -lt 4 ]; then
echo "proxy.ini error"
return 1
fi
addr=${conf[0]}:${conf[1]}@${conf[2]}:${conf[3]}
if [ $# -eq 0 ]; then
export http_proxy="http://${addr}"
export https_proxy="https://${addr}"
export ftp_proxy="ftp://${addr}"
echo "proxy setted at $addr"
elif [ "$1" = "stop" ]; then
echo $1
export http_proxy=
export https_proxy=
export ftp_proxy=
echo "proxy stopped."
elif [ "$1" = "apt-on" ]; then
echo $1
tmp_path="${Script_Path}/tmp/apt.conf"
echo -e "Acquire::http::proxy \"http://${addr}\";\n\
Acquire::https::proxy \"https://${addr}\";\n\
Acquire::ftp::proxy \"ftp://${addr}\";\n" > $tmp_path
sudo cp $tmp_path /etc/apt/apt.conf
echo "--apt-get proxy on."
elif [ "$1" = "apt-off" ]; then
sudo rm /etc/apt/apt.conf
echo "--file /etc/apt/apt.conf removed."
#fixed the "Hash Sum Mismatch" when it behind a proxy
elif [ "$1" = "apt-nocache-on" ]; then
echo $1
tmp_path="${Script_Path}/tmp/99fixbadproxy"
echo -e "Acquire::http::Pipeline-Depth 0;\n\
Acquire::http::No-Cache true;\n\
Acquire::BrokenProxy true;\n" > $tmp_path
sudo cp $tmp_path /etc/apt/apt.conf.d/99fixbadproxy
echo "--add file 99fixbadproxy."
elif [ "$1" = "apt-nocache-off" ]; then
sudo rm /etc/apt/apt.conf.d/99fixbadproxy
echo "--file 99fixbadproxy removed."
else
echo "--command wrong"
fi