最近用上了shadowsocks之后,就不再想用vpn来翻墙了,相信很多朋友都想偷懒,希望一个脚本就配置好.下面我就给大家个我从别人那拿来改了之后的脚本,原来这个脚本不支持centos 5.x,我修改成只适合centos 5.x用,下面来看看脚本吧.
系统:centos 5.x 64位(我只在64位上测试了脚本,32位的我相信应该没有问题)
脚本内容:
cat /root/soft_shell/shadowsocks.sh
|
002 |
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
|
004 |
#=============================================================================================== |
|
005 |
# System Required: CentOS5.x (32bit/64bit) |
|
006 |
# Description: Install Shadowsocks(Python) for CentOS |
|
008 |
#=============================================================================================== |
|
010 |
echo "#############################################################" |
|
011 |
echo "# Install Shadowsocks(Python) for CentOS 5.x (32bit/64bit)" |
|
012 |
echo "# Intro: http://blog.slogra.com" |
|
014 |
echo "# Author: rocdk890" |
|
015 |
echo "#############################################################" |
|
018 |
# Make sure only root can run our script |
|
020 |
if [[ $EUID -ne 0 ]]; then |
|
021 |
echo "Error:This script must be run as root!" 1>&2 |
|
028 |
if [ -f /etc/redhat-release ];then |
|
031 |
echo "Not support OS, Please reinstall OS and retry!" |
|
037 |
function getversion(){ |
|
038 |
if [[ -s /etc/redhat-release ]];then |
|
039 |
grep -oE "[0-9.]+" /etc/redhat-release |
|
041 |
grep -oE "[0-9.]+" /etc/issue |
|
046 |
function centosversion(){ |
|
048 |
local version="`getversion`" |
|
049 |
local main_ver=${version%%.*} |
|
050 |
if [ $main_ver == $code ];then |
|
058 |
function disable_selinux(){ |
|
059 |
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config;then |
|
060 |
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config |
|
070 |
function download_epel(){ |
|
071 |
if [ -s epel-release-5-4.noarch.rpm ]; then |
|
072 |
echo "epel-release-5-4.noarch.rpm [found]" |
|
074 |
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then |
|
075 |
wget -c --tries=3 http://mirrors.ustc.edu.cn/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm |
|
077 |
wget -c --tries=3 http://mirrors.ustc.edu.cn/fedora/epel/5/i386/epel-release-5-4.noarch.rpm |
|
083 |
# Pre-installation settings |
|
084 |
function pre_install(){ |
|
085 |
# Not support CentOS 6 |
|
086 |
if centosversion 6; then |
|
087 |
echo "Not support CentOS 6.x, please change to CentOS 5 and try again." |
|
089 |
# Not support CentOS 7 |
|
090 |
elif centosversion 7; then |
|
091 |
echo "Not support CentOS 7.x, please change to CentOS 5 try again." |
|
094 |
#Set shadowsocks config password |
|
095 |
echo "Please input password for shadowsocks:" |
|
096 |
read -p "(Default password: blog.slogra.com):" shadowsockspwd |
|
097 |
if [ "$shadowsockspwd" = "" ]; then |
|
098 |
shadowsockspwd="blog.slogra.com" |
|
100 |
echo "password:$shadowsockspwd" |
|
101 |
echo "####################################" |
|
106 |
dd if=/dev/tty bs=1 count=1 2> /dev/null |
|
112 |
echo "Press any key to start...or Press Ctrl+C to cancel" |
|
114 |
#Install necessary dependencies |
|
116 |
rpm -ivh epel-release-5-4.noarch.rpm |
|
117 |
yum install -y wget unzip openssl-devel gcc gcc-c++ which python26 python26-devel autoconf libtool libevent automake make curl curl-devel zlib-devel perl pcre pcre-devel cpio expat-devel gettext-devel |
|
118 |
mv /usr/bin/python /usr/bin/python.old |
|
119 |
ln -s /usr/bin/python26 /usr/bin/python |
|
120 |
old_python=`cat /usr/bin/yum |awk 'NR==1'|awk -F "/" '{print $4}'|awk -F"python" '{print $NF}'` |
|
121 |
ls -l /usr/bin/python2.4 >/tmp/t.txt |
|
122 |
python=`cat /root/t.txt |awk '{print $NF}'|awk -F "python" '{print $NF}'` |
|
123 |
if [[ $old_python = $python ]];then |
|
125 |
echo "The two Pythons are identical !" |
|
127 |
sed -i 's/python/python2.4/g' /usr/bin/yum |
|
129 |
echo "Python has been fixed successfully !" |
|
132 |
echo "Getting Public IP address, Please wait a moment..." |
|
133 |
IP=`curl -s checkip.dyndns.com | cut -d' ' -f 6 | cut -d'<' -f 1` |
|
134 |
if [ $? -ne 0 -o -z $IP ]; then |
|
135 |
IP=`curl -s -4 ipinfo.io | grep "ip" | awk -F\" '{print $4}'` |
|
137 |
echo -e "Your main public IP is\t\033[32m$IP\033[0m" |
|
143 |
function download_files(){ |
|
144 |
if [ -f setuptools-12.4.zip ]; then |
|
145 |
echo "setuptools-12.4.zip [found]" |
|
147 |
echo "setuptools-12.4.zip not found!!!download now......" |
|
148 |
if ! wget --no-check-certificatehttps://pypi.python.org/packages/source/s/setuptools/setuptools-12.4.zip; then |
|
149 |
echo "Failed to download setuptools-12.4.zip!" |
|
153 |
if [ -f pip-6.0.8.tar.gz ]; then |
|
154 |
echo "pip-6.0.8.tar.gz [found]" |
|
156 |
echo "pip-6.0.8.tar.gz not found!!!download now......" |
|
157 |
if ! wget -c --tries=3 http://download.slogra.com/python/pip-6.0.8.tar.gz; then |
|
158 |
echo "Failed to download pip-6.0.8.tar.gz!" |
|
162 |
if [ -f swig-3.0.0.tar.gz ]; then |
|
163 |
echo "swig-3.0.0.tar.gz [found]" |
|
165 |
echo "swig-3.0.0.tar.gz not found!!!download now......" |
|
166 |
if ! wget http://jaist.dl.sourceforge.net/project/swig/swig/swig-3.0.0/swig-3.0.0.tar.gz; then |
|
167 |
echo "Failed to download swig-3.0.0.tar.gz!" |
|
170 |
# Download shadowsocks chkconfig file |
|
171 |
if ! wget --no-check-certificatehttps://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-O /etc/init.d/shadowsocks; then |
|
172 |
echo "Failed to download shadowsocks chkconfig file!" |
|
177 |
function install_setuptools(){ |
|
178 |
if [ ! -f /usr/bin/easy_install ];then |
|
180 |
unzip setuptools-12.4.zip |
|
181 |
cd $cur_dir/setuptools-12.4 |
|
182 |
python setup.py build |
|
183 |
python setup.py install |
|
185 |
echo "setuptools had been installed!" |
|
188 |
if [ ! -f /usr/local/bin/swig ];then |
|
190 |
tar zxf swig-3.0.0.tar.gz |
|
191 |
cd $cur_dir/swig-3.0.0 |
|
195 |
ln -s /usr/local/bin/swig /usr/bin/swig |
|
197 |
echo "swig had been installed!" |
|
202 |
function config_shadowsocks(){ |
|
203 |
cat > /etc/shadowsocks.json<<-EOF |
|
207 |
"local_address": "127.0.0.1", |
|
209 |
"password":"${shadowsockspwd}", |
|
211 |
"method":"aes-256-cfb", |
|
218 |
function iptables_set(){ |
|
219 |
echo "iptables start setting..." |
|
220 |
/sbin/service iptables status 1>/dev/null 2>&1 |
|
221 |
if [ $? -eq 0 ]; then |
|
222 |
/etc/init.d/iptables status | grep '8989' | grep 'ACCEPT' >/dev/null 2>&1 |
|
223 |
if [ $? -ne 0 ]; then |
|
224 |
/sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8989 -j ACCEPT |
|
225 |
/etc/init.d/iptables save |
|
226 |
/etc/init.d/iptables restart |
|
228 |
echo "port 8989 has been set up." |
|
231 |
echo "iptables looks like shutdown, please manually set it if necessary." |
|
237 |
which pip > /dev/null 2>&1 |
|
238 |
if [ $? -ne 0 ]; then |
|
239 |
#python ez_setup.py install |
|
240 |
/usr/bin/easy_install pip-6.0.8.tar.gz |
|
242 |
if [ -f /usr/bin/pip ]; then |
|
246 |
pip install shadowsocks |
|
247 |
if [ -f /usr/bin/ssserver ]; then |
|
248 |
chmod +x /etc/init.d/shadowsocks |
|
249 |
# Add run on system start up |
|
250 |
chkconfig --add shadowsocks |
|
251 |
chkconfig shadowsocks on |
|
252 |
# Run shadowsocks in the background |
|
253 |
/etc/init.d/shadowsocks start |
|
256 |
echo "Shadowsocks install failed!" |
|
261 |
echo "Congratulations, shadowsocks install completed!" |
|
262 |
echo -e "Your Server IP: \033[41;37m ${IP} \033[0m" |
|
263 |
echo -e "Your Server Port: \033[41;37m 8989 \033[0m" |
|
264 |
echo -e "Your Password: \033[41;37m ${shadowsockspwd} \033[0m" |
|
265 |
echo -e "Your Local IP: \033[41;37m 127.0.0.1 \033[0m" |
|
266 |
echo -e "Your Local Port: \033[41;37m 1080 \033[0m" |
|
267 |
echo -e "Your Encryption Method: \033[41;37m aes-256-cfb \033[0m" |
|
269 |
echo "Welcome to visit:http://blog.slogra.com" |
|
275 |
echo "pip install failed!" |
|
280 |
# Uninstall Shadowsocks |
|
281 |
function uninstall_shadowsocks(){ |
|
282 |
printf "Are you sure uninstall Shadowsocks? (y/n) " |
|
284 |
read -p "(Default: n):" answer |
|
285 |
if [ -z $answer ]; then |
|
288 |
if [ "$answer" = "y" ]; then |
|
289 |
NODE_PID=`ps -ef | grep -v grep | grep -v ps | grep -i '/usr/bin/python /usr/bin/ssserver' | awk '{print $2}'` |
|
290 |
if [ ! -z $NODE_PID ]; then |
|
294 |
if [ $? -eq 0 ]; then |
|
295 |
echo "Shadowsocks process[$pid] has been killed" |
|
299 |
chkconfig --del shadowsocks |
|
301 |
rm -f /etc/shadowsocks.json |
|
302 |
rm -f /var/run/shadowsocks.pid |
|
303 |
rm -f /etc/init.d/shadowsocks |
|
304 |
pip uninstall -y shadowsocks |
|
305 |
if [ $? -eq 0 ]; then |
|
306 |
echo "Shadowsocks uninstall success!" |
|
308 |
echo "Shadowsocks uninstall failed!" |
|
311 |
echo "uninstall cancelled, Nothing to do" |
|
315 |
# Install Shadowsocks-python |
|
316 |
function install_shadowsocks(){ |
|
329 |
# Initialization step |
|
331 |
[ -z $1 ] && action=install |
|
337 |
uninstall_shadowsocks |
|
340 |
echo "Arguments error! [${action} ]" |
|
341 |
echo "Usage: `basename $0` {install|uninstall}" |
好了,为了给更多的技术人员可以使用到google服务,希望这个脚本给很多懒人带来方便.
ps:
希望原作者不会怪我把他的脚本改得看起来很低端,我也无耻的把制作人改成了我自己.
(责任编辑:IT) |