-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmitproxy_silent
executable file
·126 lines (99 loc) · 3.96 KB
/
rmitproxy_silent
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# =============================================================================
# If the computer is currently connected to RMIT's network then this
# script will set the appropriate proxy environment variables, otherwise
# it just unsets everything
# For ubuntu users: edit info in the "Sensitive info" part, then:
#
# sudo cp ~/dotfiles/scripts/rmitproxy_silent /etc/network/if-up.d/rmitproxy_silent
# sudo chmod 700 /etc/network/if-up.d/rmitproxy_silent
#
# to execute it every time your computer connects to a network :)
# Inpired by:
# http://askubuntu.com/questions/150210/how-do-i-set-systemwide-proxy-servers-in-xubuntu-lubuntu-or-ubuntu-studio/151047#151047
# =============================================================================
# RMIT's SSID and basic info
ssid=RMITWPA
host=proxy.rmit.edu.vn
port=8080
# Sensitive info - ENTER YOUR INFO HERE
# =====================================
user='enter_your_s_number_here'
pass='your_rmit_account_password'
sudopw='your_sudo_password'
# =====================================
# DON'T TOUCH ANYTHING BELOW unless you know what you're doing!
# Check if this system has git
git --version 2>&1 >/dev/null
git_installed=$?
rmitOn() {
# Standard environment variables
http_str=http://$user:$pass@$host:$port
https_str=https://$user:$pass@$host:$port
http=( http_proxy HTTP_PROXY FTP_PROXY ftp_proxy )
for envar in $http
do
export $envar=$http_str
done
https=( https_proxy HTTPS_PROXY )
for envar in $https
do
export $envar=$https_str
done
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
# Gnome proxy settings
gsettings set org.gnome.system.proxy.http host $host
gsettings set org.gnome.system.proxy.https host $host
gsettings set org.gnome.system.proxy mode 'manual'
# Hardcore stuff ahead - requiring sudo permission
# =====================================================================
# /etc/apt/apt.conf - If you ever want to install stuff while at RMIT
aptconf=`echo -e "Acquire::http::proxy \"$http_str\";\nAcquire::https::proxy \"$https_str\";"`
# Write apt.conf file content to temporary file then move it to its
# appropriate location. For some weird reason I can't write directly to
# a file in /etc/apt/
echo $aptconf > ~/tmp_apt_conf
echo $sudopw | sudo -S mv -f ~/tmp_apt_conf /etc/apt/apt.conf || true
# Git
if [ $git_installed -eq 0 ]; then
git config --global http.proxy "$http_str" || true
git config --global https.proxy "$https_str" || true
git config --global core.gitproxy '/bin/gitproxy'
fi
}
rmitOff() {
envars=( https_proxy HTTPS_PROXY http_proxy HTTP_PROXY FTP_PROXY ftp_proxy all_proxy ALL_PROXY)
for envar in $envars
do
export $envar=""
done
# Gnome proxy settings
gsettings set org.gnome.system.proxy.http host ""
gsettings set org.gnome.system.proxy.https host ""
gsettings set org.gnome.system.proxy mode 'none'
# Hardcore stuff ahead - requiring sudo permission
# =====================================================================
# Switch apt conf file
aptconf=""
# Write apt.conf file content to temporary file then move it to its
# appropriate location. For some weird reason I can't write directly to
# a file in /etc/apt/
echo $aptconf > ~/tmp_apt_conf
echo $sudopw | sudo -S mv -f ~/tmp_apt_conf /etc/apt/apt.conf || true
# Git
if [ $git_installed -eq 0 ]; then
git config --global http.proxy "" || true
git config --global https.proxy "" || true
git config --global core.gitproxy ''
fi
}
# If current network SSID is RMIT's then set up the proxy,
# otherwise unset everything
if [ `iwgetid -s | grep $ssid` ]; then
rmitOn
echo "Connected to '$ssid'. Proxy settings applied."
else
rmitOff
echo "Not on '$ssid'. Proxy settings cleared."
fi