-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_proxy.sh
More file actions
executable file
·101 lines (88 loc) · 3.03 KB
/
setup_proxy.sh
File metadata and controls
executable file
·101 lines (88 loc) · 3.03 KB
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
#!/bin/bash
# ==============================================================================
# This script reads proxy information from a given file.
# Setups proxies on the system - Ubuntu/CentOS.
#
# Additonal proxy file sintaxis look at proxyrc.sample
# ==============================================================================
# Uncomment the following line to debug this script
# set -o xtrace
# Handle file sent as parameter - from where proxy info will be retrieved.
while [[ ${1} ]]; do
case "${1}" in
--file|-f)
proxy_file=${2}
shift
;;
--help|-h)
echo " "
echo "Script reads proxy information from a given file."
echo "Setups proxies on the system - Ubuntu/CentOS."
echo " "
echo "Usage:"
echo " setup_proxy [--file | -f] <filePath>"
echo " "
echo " --file <filePath> Pass the full file name where proxy information lives. See proxyrc.sample to see file sintaxis."
echo " -f <filePath> Pass the full file name where proxy information lives. See proxyrc.sample to see file sintaxis."
echo " --help Prints current help text. "
echo " "
exit 1
;;
*)
echo "***************************" >&2
echo "* Error: Invalid argument. $1" >&2
echo "***************************" >&2
exit 1
esac
shift
done
# Ensure script is run as root
if [ "$EUID" -ne "0" ]; then
echo "$(date +"%F %T.%N") ERROR : This script must be run as root." >&2
exit 1
fi
# proxy_file="/root/shared/proxyrc"
echo "Setting proxy information from $proxy_file "
if [ -f "${proxy_file}" ]; then
source $proxy_file
# Ubuntu
if [ -f /etc/apt/apt.conf ]
then
echo "Ubuntu system - Acquiring proxy."
echo "Acquire::http::Proxy \"${http_proxy}\";" >> /etc/apt/apt.conf
echo "Acquire::https::Proxy \"${https_proxy}\";" >> /etc/apt/apt.conf
fi
if [ -d /etc/apt/apt.conf.d ]
then
echo "Ubuntu system - Acquiring proxy."
echo "Acquire::http::Proxy \"${http_proxy}\";" >> /etc/apt/apt.conf.d/70proxy.conf
echo "Acquire::https::Proxy \"${https_proxy}\";" >> /etc/apt/apt.conf.d/70proxy.conf
fi
# CentOS
if [ -f /etc/yum.conf ]
then
echo "CentOS system - Acquiring proxy."
echo "proxy=${http_proxy}" >> /etc/yum.conf
fi
# Interactive shell
if [ -f /etc/bashrc ]
then
echo "Modifying interactive shell."
echo "export http_proxy=${http_proxy}" >> /etc/bashrc
echo "export https_proxy=${https_proxy}" >> /etc/bashrc
echo "export no_proxy=${no_proxy}" >> /etc/bashrc
fi
# Interactive shell - all users
if [ -f /etc/bash.bashrc ]
then
echo "Modifying interactive shell."
echo "export http_proxy=${http_proxy}" >> /etc/bash.bashrc
echo "export https_proxy=${https_proxy}" >> /etc/bash.bashrc
echo "export no_proxy=${no_proxy}" >> /etc/bash.bashrc
fi
echo "http_proxy=${http_proxy}" >> /etc/wgetrc
echo "https_proxy=${https_proxy}" >> /etc/wgetrc
else
# 0. Workaround for vagrant boxes
sed -i "s/10.0.2.3/8.8.8.8/g" /etc/resolv.conf
fi