-
Notifications
You must be signed in to change notification settings - Fork 183
/
ShadowVPN-for-debian.sh
230 lines (205 loc) · 5.6 KB
/
ShadowVPN-for-debian.sh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#! /bin/bash
#===============================================================================================
# System Required: Debian (32bit/64bit)
# Description: Install ShadowVPN Single user for Debian
#
#===============================================================================================
clear
echo "#############################################################"
echo "# Install ShadowVPN for Debian (32bit/64bit)"
echo "#############################################################"
echo ""
# install ShadowVPN
function install_ShadowVPN_libsodium(){
root
debian
get_config
pre_install
ShadowVPN_install
config_ShadowVPN
stop_ShadowVPN
start_ShadowVPN
show_ShadowVPN
}
#change config
function changeconfig_ShadowVPN_libsodium(){
get_config
config_ShadowVPN
stop_ShadowVPN
start_ShadowVPN
show_ShadowVPN
}
#update ShadowVPN
function update_ShadowVPN_libsodium(){
stop_ShadowVPN
cp -rpf /etc/shadowvpn/server.conf /opt/server.conf
ShadowVPN_update
rm -f /etc/shadowvpn/server.conf
mv /opt/server.conf /etc/shadowvpn/server.conf
rm -f /opt/server.conf
start_ShadowVPN
}
#unistall ShadowVPN
function uninstall_ShadowVPN_libsodium(){
printf "Are you sure uninstall ShadowVPN? (y/n) "
printf "\n"
read -p "(Default: n):" answer
if [ -z $answer ]; then
answer="n"
fi
if [ "$answer" = "y" ]; then
#stop
stop_ShadowVPN
# restore /etc/rc.local
if [[ -s /opt/rc.local_bak_sv_l ]]; then
sed -i "s@/usr/local/bin/shadowvpn -c /etc/shadowvpn/server.conf -s start@@" /etc/rc.local
rm -f /opt/rc.local_bak_sv_l
fi
# delete config file
rm -rf /etc/shadowvpn
# delete ShadowVPN
rm -f /usr/local/bin/shadowvpn
echo "ShadowVPN uninstall success!"
else
echo "uninstall cancelled, Nothing to do"
fi
}
# Check if user is root
function root(){
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script!!"
exit 1
fi
}
# debian only
function debian(){
if [[ ! -e /etc/debian_version ]]; then
echo "Looks like you aren't running this installer on a Debian-based system"
exit 1
fi
}
# pre_install
function pre_install(){
cd ~
echo linux-image-`uname -r` hold | sudo dpkg --set-selections
apt-get update
apt-get upgrade -y
apt-get install -y build-essential autoconf libtool libssl-dev gcc
apt-get install -y vim sudo git gawk debhelper curl
clear
}
function get_config(){
# Get ShadowVPN config password
echo "Please input password for ShadowVPN:"
read -p "(Default password: 123456):" ShadowVPNpwd
if [ "$ShadowVPNpwd" = "" ]; then
ShadowVPNpwd="123456"
fi
echo "password:$ShadowVPNpwd"
echo "####################################"
# Get ShadowVPN config servers port
echo "Please input server port for ShadowVPN:"
read -p "(Default port: 443):" ShadowVPNpt
if [ "$ShadowVPNpt" = "" ]; then
ShadowVPNpt="443"
fi
echo "port:$ShadowVPNpt"
echo "####################################"
}
function ShadowVPN_install(){
# install check
if [ -s /usr/local/bin/shadowvpn ];then
echo "ShadowVPN has been installed!"
echo "change config!"
else
ShadowVPN_update
fi
}
function ShadowVPN_update(){
cd ~
git clone https://github.com/clowwindy/ShadowVPN.git
cd ShadowVPN
git submodule update --init
./autogen.sh
./configure --enable-static --sysconfdir=/etc
make && sudo make install
cd ..
rm -rf ShadowVPN
}
function config_ShadowVPN(){
# set config
D_SVPN_PASSWD=`cat $SHADOWVPN_CONFIG | grep ^pa | cut -d '=' -f 2`
D_SVPN_PORT=`cat $SHADOWVPN_CONFIG | grep ^po | cut -d '=' -f 2`
sed -i 's/$D_SVPN_PASSWD/$ShadowVPNpwd/' $SHADOWVPN_CONFIG
sed -i 's/$D_SVPN_PORT/$ShadowVPNpt/' $SHADOWVPN_CONFIG
}
function stop_ShadowVPN(){
#stop all
sv_pid=`pidof shadowvpn`
if [ ! -z "$sv_pid" ]; then
for pid in $sv_pid
do
kill -9 $pid > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ShadowVPN process[$pid] has been killed"
fi
done
fi
}
function start_ShadowVPN(){
#start
/usr/local/bin/shadowvpn -c /etc/shadowvpn/server.conf -s start
#Add run on system start up
cat /etc/rc.local | grep 'shadowvpn -c /etc/shadowvpn/server.conf' > /dev/null 2>&1
if [ $? -ne 0 ]; then
cp -rpf /etc/rc.local /opt/rc.local_bak_sv_l
sed -i "/By default this script does nothing./a\/usr/local/bin/shadowvpn -c /etc/shadowvpn/server.conf -s start" /etc/rc.local
fi
}
function show_ShadowVPN(){
# Get IP
IP=$(wget -qO- ipv4.icanhazip.com)
if [ -z $IP ]; then
IP=`curl -s liyangyijie.sinaapp.com/ip/`
fi
# Run success or not
ps -ef | grep -v grep | grep -v ps | grep -i '/usr/local/bin/shadowvpn' > /dev/null 2>&1
if [ $? -eq 0 ]; then
clear
echo ""
echo "Congratulations!ShadowVPN start success!"
echo -e "Your Server IP: \033[41;37m ${IP} \033[0m"
echo -e "Your Server Port: \033[41;37m ${ShadowVPNpt} \033[0m"
echo -e "Your Password: \033[41;37m ${ShadowVPNpwd} \033[0m"
echo ""
echo "Enjoy it!"
echo ""
exit
else
echo "ShadowVPN start failure!"
exit
fi
}
#vars
SHADOWVPN_CONFIG="/etc/shadowvpn/server.conf"
# Initialization step
action=$1
[ -z $1 ] && action=install
case "$action" in
install)
install_ShadowVPN_libsodium
;;
changeconfig)
changeconfig_ShadowVPN_libsodium
;;
update)
update_ShadowVPN_libsodium
;;
uninstall)
uninstall_ShadowVPN_libsodium
;;
*)
echo "Arguments error! [${action} ]"
echo "Usage: `basename $0` {install|changeconfig|update|uninstall}"
;;
esac