Browse Source

Add Shadowsocks-libev

lj2007331 9 years ago
parent
commit
e5f0858436

+ 4 - 4
apps.conf

@@ -4,7 +4,7 @@ nginx_version=1.9.14
 tengine_version=2.1.1
 openresty_version=1.9.7.4
 
-tomcat_7_version=7.0.68
+tomcat_7_version=7.0.69
 tomcat_8_version=8.0.30
 
 apache_2_version=2.2.31
@@ -14,9 +14,9 @@ apr_version=1.5.2
 apr_util_version=1.5.4
 
 # DB
-mysql_5_7_version=5.7.11
-mysql_5_6_version=5.6.29
-mysql_5_5_version=5.5.48
+mysql_5_7_version=5.7.12
+mysql_5_6_version=5.6.30
+mysql_5_5_version=5.5.49
 
 mariadb_10_1_version=10.1.13
 mariadb_10_0_version=10.0.24

+ 1 - 1
include/init_CentOS.sh

@@ -96,7 +96,7 @@ ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 sed -i 's/net.ipv4.tcp_syncookies.*$/net.ipv4.tcp_syncookies = 1/g' /etc/sysctl.conf
 [ -z "`cat /etc/sysctl.conf | grep 'fs.file-max'`" ] && cat >> /etc/sysctl.conf << EOF
 fs.file-max=65535
-fs.inotify.max_user_instances = 1024
+fs.inotify.max_user_instances = 8192 
 net.ipv4.tcp_fin_timeout = 30 
 net.ipv4.tcp_tw_reuse = 1
 net.ipv4.tcp_tw_recycle = 1

+ 1 - 1
include/init_Debian.sh

@@ -66,7 +66,7 @@ sed -i 's@^# alias@alias@g' ~/.bashrc
 # /etc/sysctl.conf
 [ -z "`cat /etc/sysctl.conf | grep 'fs.file-max'`" ] && cat >> /etc/sysctl.conf << EOF
 fs.file-max=65535
-fs.inotify.max_user_instances = 1024
+fs.inotify.max_user_instances = 8192 
 net.ipv4.tcp_syncookies = 1
 net.ipv4.tcp_fin_timeout = 30
 net.ipv4.tcp_tw_reuse = 1

+ 1 - 1
include/init_Ubuntu.sh

@@ -85,7 +85,7 @@ ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 # /etc/sysctl.conf
 [ -z "`cat /etc/sysctl.conf | grep 'fs.file-max'`" ] && cat >> /etc/sysctl.conf << EOF
 fs.file-max=65535
-fs.inotify.max_user_instances = 1024
+fs.inotify.max_user_instances = 8192 
 net.ipv4.tcp_syncookies = 1
 net.ipv4.tcp_fin_timeout = 30 
 net.ipv4.tcp_tw_reuse = 1

+ 2 - 7
include/nginx.sh

@@ -13,15 +13,10 @@ cd $oneinstack_dir/src
 src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
 src_url=http://nginx.org/download/nginx-$nginx_version.tar.gz && Download_src
 
-tar xzf pcre-$pcre_version.tar.gz
-cd pcre-$pcre_version
-./configure
-make && make install
-cd ..
-
 id -u $run_user >/dev/null 2>&1
 [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user 
 
+tar xzf pcre-$pcre_version.tar.gz
 tar xzf nginx-$nginx_version.tar.gz
 cd nginx-$nginx_version
 # Modify Nginx version
@@ -41,7 +36,7 @@ elif [ "$je_tc_malloc" == '2' ];then
 fi
 
 [ ! -d "$nginx_install_dir" ] && mkdir -p $nginx_install_dir
-./configure --prefix=$nginx_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module $malloc_module
+./configure --prefix=$nginx_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
 make && make install
 if [ -e "$nginx_install_dir/conf/nginx.conf" ];then
     cd ..

+ 2 - 7
include/openresty.sh

@@ -13,15 +13,10 @@ cd $oneinstack_dir/src
 src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
 src_url=https://openresty.org/download/openresty-$openresty_version.tar.gz && Download_src
 
-tar xzf pcre-$pcre_version.tar.gz
-cd pcre-$pcre_version
-./configure
-make && make install
-cd ..
-
 id -u $run_user >/dev/null 2>&1
 [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user 
 
+tar xzf pcre-$pcre_version.tar.gz
 tar xzf openresty-$openresty_version.tar.gz
 cd openresty-$openresty_version
 
@@ -38,7 +33,7 @@ elif [ "$je_tc_malloc" == '2' ];then
 fi
 
 [ ! -d "$openresty_install_dir" ] && mkdir -p $openresty_install_dir
-./configure --prefix=$openresty_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module $malloc_module
+./configure --prefix=$openresty_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
 make && make install
 if [ -e "$openresty_install_dir/nginx/conf/nginx.conf" ];then
     cd ..

+ 2 - 7
include/tengine.sh

@@ -13,15 +13,10 @@ cd $oneinstack_dir/src
 src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
 src_url=http://tengine.taobao.org/download/tengine-$tengine_version.tar.gz && Download_src
 
-tar xzf pcre-$pcre_version.tar.gz
-cd pcre-$pcre_version
-./configure
-make && make install
-cd ..
-
 id -u $run_user >/dev/null 2>&1
 [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user 
 
+tar xzf pcre-$pcre_version.tar.gz
 tar xzf tengine-$tengine_version.tar.gz 
 cd tengine-$tengine_version 
 # Modify Tengine version
@@ -39,7 +34,7 @@ elif [ "$je_tc_malloc" == '2' ];then
 fi
 
 [ ! -d "$tengine_install_dir" ] && mkdir -p $tengine_install_dir
-./configure --prefix=$tengine_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_spdy_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_concat_module=shared --with-http_sysguard_module=shared $malloc_module
+./configure --prefix=$tengine_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_spdy_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_concat_module=shared --with-http_sysguard_module=shared --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
 make && make install
 if [ -e "$tengine_install_dir/conf/nginx.conf" ];then
     cd ..

+ 7 - 1
include/upgrade_web.sh

@@ -22,6 +22,8 @@ do
     if [ "$NEW_Nginx_version" != "$OLD_Nginx_version" ];then
         [ ! -e "nginx-$NEW_Nginx_version.tar.gz" ] && wget --no-check-certificate -c http://nginx.org/download/nginx-$NEW_Nginx_version.tar.gz > /dev/null 2>&1
         if [ -e "nginx-$NEW_Nginx_version.tar.gz" ];then
+            src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
+            tar xzf pcre-$pcre_version.tar.gz
             echo "Download [${CMSG}nginx-$NEW_Nginx_version.tar.gz${CEND}] successfully! "
             break
         else
@@ -74,6 +76,8 @@ do
     if [ "$NEW_Tengine_version" != "$OLD_Tengine_version" ];then
         [ ! -e "tengine-$NEW_Tengine_version.tar.gz" ] && wget --no-check-certificate -c http://tengine.taobao.org/download/tengine-$NEW_Tengine_version.tar.gz > /dev/null 2>&1
         if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
+            src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
+            tar xzf pcre-$pcre_version.tar.gz
             echo "Download [${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] successfully! "
             break
         else
@@ -131,6 +135,8 @@ do
     if [ "$NEW_OpenResty_version" != "$OLD_OpenResty_version" ];then
         [ ! -e "openresty-$NEW_OpenResty_version.tar.gz" ] && wget --no-check-certificate -c https://openresty.org/download/openresty-$NEW_OpenResty_version.tar.gz > /dev/null 2>&1
         if [ -e "openresty-$NEW_OpenResty_version.tar.gz" ];then
+            src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
+            tar xzf pcre-$pcre_version.tar.gz
             echo "Download [${CMSG}openresty-$NEW_OpenResty_version.tar.gz${CEND}] successfully! "
             break
         else
@@ -155,7 +161,7 @@ if [ -e "openresty-$NEW_OpenResty_version.tar.gz" ];then
     rm -rf $$
     [ -n "`echo $openresty_configure_arguments | grep jemalloc`"] && malloc_module="--with-ld-opt='-ljemalloc'"
     [ -n "`echo $openresty_configure_arguments | grep perftools`" ] && malloc_module='--with-google_perftools_module'
-    ./configure --prefix=$openresty_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module $malloc_module
+    ./configure --prefix=$openresty_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
     make
     if [ -f "build/nginx-$openresty_version_tmp/objs/nginx" ];then
         /bin/mv $openresty_install_dir/nginx/sbin/nginx $openresty_install_dir/nginx/sbin/nginx$(date +%m%d)

+ 124 - 0
init.d/Shadowsocks-libev-init

@@ -0,0 +1,124 @@
+#!/bin/bash
+#
+# Script to run Shadowsocks in daemon mode at boot time.
+# ScriptAuthor: icyboy
+# Revision 1.0 - 14th Sep 2013
+#====================================================================
+# Run level information:
+# chkconfig: 2345 99 99
+# Description: lightweight secured scoks5 proxy
+# processname: ss-server
+# Author: Max Lv <max.c.lv@gmail.com>;
+# Run "/sbin/chkconfig --add shadowsocks" to add the Run levels.
+#====================================================================
+
+#====================================================================
+# Paths and variables and system checks.
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Check that networking is up.
+#
+[ ${NETWORKING} ="yes" ] || exit 0
+
+# Daemon
+NAME=shadowsocks-server
+DAEMON=/usr/local/bin/ss-server
+
+# Path to the configuration file.
+#
+CONF=/etc/shadowsocks/config.json
+
+#USER="nobody"
+#GROUP="nobody"
+
+# Take care of pidfile permissions
+mkdir /var/run/$NAME 2>/dev/null || true
+#chown "$USER:$GROUP" /var/run/$NAME
+
+# Check the configuration file exists.
+#
+if [ ! -f $CONF ] ; then
+echo "The configuration file cannot be found!"
+exit 0
+fi
+
+# Path to the lock file.
+#
+LOCK_FILE=/var/lock/subsys/shadowsocks
+
+# Path to the pid file.
+#
+PID=/var/run/$NAME/pid
+
+
+#====================================================================
+
+#====================================================================
+# Run controls:
+
+RETVAL=0
+
+# Start shadowsocks as daemon.
+#
+start() {
+if [ -f $LOCK_FILE ]; then
+echo "$NAME is already running!"
+exit 0
+else
+echo -n $"Starting ${NAME}: "
+#daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null"
+daemon $DAEMON -u -c $CONF -f $PID
+fi
+
+RETVAL=$?
+[ $RETVAL -eq 0 ] && success
+echo
+[ $RETVAL -eq 0 ] && touch $LOCK_FILE
+return $RETVAL
+}
+
+
+# Stop shadowsocks.
+#
+stop() {
+echo -n $"Shutting down ${NAME}: "
+killproc -p ${PID}
+RETVAL=$?
+[ $RETVAL -eq 0 ]
+rm -f $LOCK_FILE
+rm -f ${PID}
+echo
+return $RETVAL
+}
+
+# See how we were called.
+case "$1" in
+start)
+start
+;;
+stop)
+stop
+;;
+restart)
+stop
+start
+;;
+condrestart)
+if [ -f $LOCK_FILE ]; then
+stop
+start
+RETVAL=$?
+fi
+;;
+status)
+status $DAEMON
+RETVAL=$?
+;;
+*)
+echo $"Usage: $0 {start|stop|restart|condrestart|status}"
+RETVAL=1
+esac
+
+exit $RETVAL

+ 90 - 0
init.d/Shadowsocks-python-init

@@ -0,0 +1,90 @@
+#!/bin/bash
+# Author:  yeho <lj2007331 AT gmail.com>
+# BLOG:  https://blog.linuxeye.com
+#
+# chkconfig: - 90 10
+# description: Shadowsocks start/stop/status/restart script
+
+Shadowsocks_bin=/usr/bin/ssserver
+Shadowsocks_conf=/etc/shadowsocks/config.json
+
+#Shadowsocks_USAGE is the message if this script is called without any options
+Shadowsocks_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"
+
+#SHUTDOWN_WAIT is wait time in seconds for shadowsocks proccess to stop
+SHUTDOWN_WAIT=20
+
+Shadowsocks_pid(){
+	echo `ps -ef | grep $Shadowsocks_bin | grep -v grep | tr -s " "|cut -d" " -f2`
+}
+
+start() {
+  pid=$(Shadowsocks_pid)
+  if [ -n "$pid" ];then
+    echo -e "\e[00;31mShadowsocks is already running (pid: $pid)\e[00m"
+  else
+    $Shadowsocks_bin -c $Shadowsocks_conf -d start
+    RETVAL=$?
+    if [ "$RETVAL" = "0" ]; then
+    	echo -e "\e[00;32mStarting Shadowsocks\e[00m"
+    else
+    	echo -e "\e[00;32mShadowsocks start Failed\e[00m"
+    fi
+    status
+  fi
+  return 0
+}
+
+status(){
+  pid=$(Shadowsocks_pid)
+  if [ -n "$pid" ];then
+    echo -e "\e[00;32mShadowsocks is running with pid: $pid\e[00m"
+  else
+    echo -e "\e[00;31mShadowsocks is not running\e[00m"
+  fi
+}
+
+stop(){
+  pid=$(Shadowsocks_pid)
+  if [ -n "$pid" ];then
+    echo -e "\e[00;31mStoping Shadowsocks\e[00m"
+    $Shadowsocks_bin -c $Shadowsocks_conf -d stop
+    let kwait=$SHUTDOWN_WAIT
+    count=0;
+    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
+    do
+      echo -n -e "\e[00;31mwaiting for processes to exit\e[00m\n";
+      sleep 1
+      let count=$count+1;
+    done
+
+    if [ $count -gt $kwait ];then
+      echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
+      kill -9 $pid
+    fi
+  else
+    echo -e "\e[00;31mShadowsocks is not running\e[00m"
+  fi
+
+  return 0
+}
+
+case $1 in
+	start)
+          start
+        ;;
+        stop)  
+          stop
+        ;;
+        restart)
+          stop
+          start
+        ;;
+        status)
+	  status
+        ;;
+        *)
+	  echo -e $Shadowsocks_USAGE
+        ;;
+esac    
+exit 0

+ 166 - 76
shadowsocks.sh

@@ -3,7 +3,7 @@
 # BLOG:  https://blog.linuxeye.com
 #
 # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
-#        Install Shadowsocks(Python) Server 
+#        Install Shadowsocks Server 
 #
 # Project home page:
 #       http://oneinstack.com
@@ -14,7 +14,7 @@ clear
 printf "
 #######################################################################
 #       OneinStack for CentOS/RadHat 6+ Debian 6+ and Ubuntu 12+      #
-#                  Install Shadowsocks(Python) Server                 #
+#                   Install Shadowsocks Server                        #
 #       For more information please visit http://oneinstack.com       #
 #######################################################################
 "
@@ -32,20 +32,97 @@ PUBLIC_IPADDR=`../include/get_public_ipaddr.py`
 
 [ "$CentOS_RHEL_version" == '5' ] && { echo "${CWARNING}Shadowsocks only support CentOS6,7 or Debian or Ubuntu! ${CEND}"; exit 1; }
 
-Install_shadowsocks(){
+Check_shadowsocks() {
+    [ -f /usr/local/bin/ss-server ] && SS_version=1
+    [ -f /usr/bin/ssserver -o -f /usr/local/bin/ssserver ] && SS_version=2 
+}
+
+AddUser_shadowsocks() {
+while :
+do
+    echo
+    read -p "Please input password for shadowsocks: " Shadowsocks_password
+    [ -n "`echo $Shadowsocks_password | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and & ${CEND}"; continue; }
+    (( ${#Shadowsocks_password} >= 5 )) && break || echo "${CWARNING}Shadowsocks password least 5 characters! ${CEND}"
+done
+}
+
+Iptables_set() {
+if [ -e '/etc/sysconfig/iptables' ];then
+    Shadowsocks_Already_port=`grep -oE '9[0-9][0-9][0-9]' /etc/sysconfig/iptables | head -n 1`
+elif [ -e '/etc/iptables.up.rules' ];then
+    Shadowsocks_Already_port=`grep -oE '9[0-9][0-9][0-9]' /etc/iptables.up.rules | head -n 1`
+fi
+
+if [ -n "$Shadowsocks_Already_port" ];then
+    Shadowsocks_Default_port=`expr $Shadowsocks_Already_port + 1`
+else
+    Shadowsocks_Default_port=9001
+fi
+
+while :
+do
+    echo
+    read -p "Please input Shadowsocks port(Default: $Shadowsocks_Default_port): " Shadowsocks_port
+    [ -z "$Shadowsocks_port" ] && Shadowsocks_port=$Shadowsocks_Default_port
+    if [ $Shadowsocks_port -ge 9000 >/dev/null 2>&1 -a $Shadowsocks_port -le 10000 >/dev/null 2>&1 ];then
+        break
+    else
+        echo "${CWARNING}input error! Input range: 9001~9999${CEND}"
+    fi
+done
+
+if [ "$OS" == 'CentOS' ];then
+    if [ -z "`grep -E $Shadowsocks_port /etc/sysconfig/iptables`" ];then
+        iptables -I INPUT 4 -p udp -m state --state NEW -m udp --dport $Shadowsocks_port -j ACCEPT
+        iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport $Shadowsocks_port -j ACCEPT
+        service iptables save 
+    fi
+elif [[ $OS =~ ^Ubuntu$|^Debian$ ]];then 
+    if [ -z "`grep -E $Shadowsocks_port /etc/iptables.up.rules`" ];then
+        iptables -I INPUT 4 -p udp -m state --state NEW -m udp --dport $Shadowsocks_port -j ACCEPT
+        iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport $Shadowsocks_port -j ACCEPT
+        iptables-save > /etc/iptables.up.rules 
+    fi
+else
+    echo "${CWARNING}This port is already in iptables${CEND}"
+fi
+
+}
+
+Def_parameter() {
 if [ "$OS" == 'CentOS' ]; then
-    for Package in wget unzip openssl-devel gcc swig python python-devel python-setuptools autoconf libtool libevent automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel
+    while :; do echo
+        echo 'Please select Shadowsocks server version:'
+        echo -e "\t${CMSG}1${CEND}. Install Shadowsocks-libev"
+        echo -e "\t${CMSG}2${CEND}. Install Shadowsocks-python"
+        read -p "Please input a number:(Default 1 press Enter) " SS_version
+        [ -z "$SS_version" ] && SS_version=1
+        if [[ ! $SS_version =~ ^[1-2]$ ]];then
+            echo "${CWARNING}input error! Please only input number 1,2${CEND}"
+        else
+            break
+        fi
+    done
+    AddUser_shadowsocks
+    Iptables_set
+    for Package in wget unzip openssl-devel gcc swig python python-devel python-setuptools autoconf libtool libevent automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel git
     do
         yum -y install $Package
     done
 elif [[ $OS =~ ^Ubuntu$|^Debian$ ]];then 
+    SS_version=2
+    AddUser_shadowsocks
+    Iptables_set
     apt-get -y update
-    for Package in python-dev python-pip curl wget unzip gcc swig automake make perl cpio
+    for Package in python-dev python-pip curl wget unzip gcc swig automake make perl cpio git
     do
         apt-get -y install $Package
     done
 fi
+}
 
+Install_shadowsocks-python() { 
 src_url=http://mirrors.linuxeye.com/oneinstack/src/ez_setup.py && Download_src
 
 which pip > /dev/null 2>&1
@@ -57,19 +134,37 @@ if [ -f /usr/bin/pip ]; then
     pip install gevent
     pip install shadowsocks
     if [ -f /usr/bin/ssserver -o -f /usr/local/bin/ssserver ]; then
-        /bin/cp ../init.d/Shadowsocks-init /etc/init.d/shadowsocks
+        /bin/cp ../init.d/Shadowsocks-python-init /etc/init.d/shadowsocks
         chmod +x /etc/init.d/shadowsocks
         [ "$OS" == 'CentOS' ] && { chkconfig --add shadowsocks; chkconfig shadowsocks on; }
         [[ $OS =~ ^Ubuntu$|^Debian$ ]] && update-rc.d shadowsocks defaults
         [ ! -e /usr/bin/ssserver -a -e /usr/local/bin/ssserver ] && sed -i 's@Shadowsocks_bin=.*@Shadowsocks_bin=/usr/local/bin/ssserver@' /etc/init.d/shadowsocks
     else
         echo
-        echo "${CQUESTION}Shadowsocks install failed! Please visit http://oneinstack.com${CEND}"
+        echo "${CQUESTION}Shadowsocks-python install failed! Please visit http://oneinstack.com${CEND}"
         exit 1
     fi
 fi
 }
 
+Install_shadowsocks-libev() {
+git clone https://github.com/shadowsocks/shadowsocks-libev.git
+cd shadowsocks-libev
+./configure
+make && make install
+cd ..
+if [ -f  /usr/local/bin/ss-server ];then
+    /bin/cp ../init.d/Shadowsocks-libev-init /etc/init.d/shadowsocks
+    chmod +x /etc/init.d/shadowsocks
+    [ "$OS" == 'CentOS' ] && { chkconfig --add shadowsocks; chkconfig shadowsocks on; }
+else
+   echo
+   echo "${CQUESTION}Shadowsocks-libev install failed! Please visit http://oneinstack.com${CEND}"
+   exit 1
+fi
+
+}
+
 Uninstall_shadowsocks(){
 while :
 do
@@ -83,75 +178,59 @@ do
 done
 
 if [ "$Shadowsocks_yn" == 'y' ]; then
-    [ -n "`ps -ef | grep -v grep | grep -i "ssserver"`" ] && /etc/init.d/shadowsocks stop
+    [ -n "`ps -ef | grep -v grep | grep -iE "ssserver|ss-server"`" ] && /etc/init.d/shadowsocks stop
     [ "$OS" == 'CentOS' ] && chkconfig --del shadowsocks 
     [[ $OS =~ ^Ubuntu$|^Debian$ ]] && update-rc.d -f shadowsocks remove 
-
-    rm -rf /etc/shadowsocks.json /var/run/shadowsocks.pid /etc/init.d/shadowsocks
-    pip uninstall -y shadowsocks
-    if [ $? -eq 0 ]; then
-        echo "${CSUCCESS}Shadowsocks uninstall success! ${CEND}"
-    else
-        echo "${CFAILURE}Shadowsocks uninstall failed! ${CEND}"
+    rm -rf /etc/shadowsocks /var/run/shadowsocks.pid /etc/init.d/shadowsocks
+    if [ "$SS_version" == '1' ];then
+        rm -f /usr/local/bin/ss-local
+        rm -f /usr/local/bin/ss-tunnel
+        rm -f /usr/local/bin/ss-server
+        rm -f /usr/local/bin/ss-manager
+        rm -f /usr/local/bin/ss-redir
+        rm -f /usr/local/lib/libshadowsocks.a
+        rm -f /usr/local/lib/libshadowsocks.la
+        rm -f /usr/local/include/shadowsocks.h
+        rm -f /usr/local/lib/pkgconfig/shadowsocks-libev.pc
+        rm -f /usr/local/share/man/man1/ss-local.1
+        rm -f /usr/local/share/man/man1/ss-tunnel.1
+        rm -f /usr/local/share/man/man1/ss-server.1
+        rm -f /usr/local/share/man/man1/ss-manager.1
+        rm -f /usr/local/share/man/man1/ss-redir.1
+        rm -f /usr/local/share/man/man8/shadowsocks.8
+        if [ $? -eq 0 ]; then
+            echo "${CSUCCESS}Shadowsocks-libev uninstall success! ${CEND}"
+        else
+            echo "${CFAILURE}Shadowsocks-libev uninstall failed! ${CEND}"
+        fi
+    elif [ "$SS_version" == '2' ];then
+        pip uninstall -y shadowsocks
+        if [ $? -eq 0 ]; then
+            echo "${CSUCCESS}Shadowsocks-python uninstall success! ${CEND}"
+        else
+            echo "${CFAILURE}Shadowsocks-python uninstall failed! ${CEND}"
+        fi
     fi
 else
     echo "${CMSG}Shadowsocks uninstall cancelled! ${CEND}"
 fi
 }
 
-AddUser_shadowsocks(){
-while :
-do
-    echo
-    read -p "Please input password for shadowsocks: " Shadowsocks_password
-    [ -n "`echo $Shadowsocks_password | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and & ${CEND}"; continue; }
-    (( ${#Shadowsocks_password} >= 5 )) && break || echo "${CWARNING}Shadowsocks password least 5 characters! ${CEND}"
-done
-}
-
-Iptables_set(){
-if [ -e '/etc/sysconfig/iptables' ];then
-    Shadowsocks_Already_port=`grep -oE '9[0-9][0-9][0-9]' /etc/sysconfig/iptables | head -n 1`
-elif [ -e '/etc/iptables.up.rules' ];then
-    Shadowsocks_Already_port=`grep -oE '9[0-9][0-9][0-9]' /etc/iptables.up.rules | head -n 1`
-fi
-
-if [ -n "$Shadowsocks_Already_port" ];then
-    Shadowsocks_Default_port=`expr $Shadowsocks_Already_port + 1`
-else
-    Shadowsocks_Default_port=9001
-fi
-
-while :
-do
-    echo
-    read -p "Please input Shadowsocks port(Default: $Shadowsocks_Default_port): " Shadowsocks_port
-    [ -z "$Shadowsocks_port" ] && Shadowsocks_port=$Shadowsocks_Default_port
-    if [ $Shadowsocks_port -ge 9000 >/dev/null 2>&1 -a $Shadowsocks_port -le 10000 >/dev/null 2>&1 ];then
-        break
-    else
-        echo "${CWARNING}input error! Input range: 9001~9999${CEND}"
-    fi
-done
-
-if [ "$OS" == 'CentOS' ];then
-    if [ -z "`grep -E $Shadowsocks_port /etc/sysconfig/iptables`" ];then
-        iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport $Shadowsocks_port -j ACCEPT
-        service iptables save 
-    fi
-elif [[ $OS =~ ^Ubuntu$|^Debian$ ]];then 
-    if [ -z "`grep -E $Shadowsocks_port /etc/iptables.up.rules`" ];then
-        iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport $Shadowsocks_port -j ACCEPT
-        iptables-save > /etc/iptables.up.rules 
-    fi
-else
-    echo "${CWARNING}This port is already in iptables${CEND}"
-fi
-
+Config_shadowsocks(){
+[ ! -d '/etc/shadowsocks' ] && mkdir /etc/shadowsocks
+[ "$SS_version" == '1' ] && cat > /etc/shadowsocks/config.json<<EOF
+{
+    "server":"0.0.0.0",
+    "server_port":$Shadowsocks_port,
+    "local_address":"127.0.0.1",
+    "local_port":1080,
+    "password":"$Shadowsocks_password",
+    "timeout":300,
+    "method":"aes-256-cfb",
 }
+EOF
 
-Config_shadowsocks(){
-cat > /etc/shadowsocks.json<<EOF
+[ "$SS_version" == '2' ] && cat > /etc/shadowsocks/config.json<<EOF
 {
     "server":"0.0.0.0",
     "local_address":"127.0.0.1",
@@ -167,8 +246,8 @@ EOF
 }
 
 AddUser_Config_shadowsocks(){
-[ ! -e /etc/shadowsocks.json ] && { echo "${CFAILURE}Shadowsocks is not installed! ${CEND}"; exit 1; }
-[ -z "`grep \"$Shadowsocks_port\" /etc/shadowsocks.json`" ] && sed -i "s@\"port_password\":{@\"port_password\":{\n\t\"$Shadowsocks_port\":\"$Shadowsocks_password\",@" /etc/shadowsocks.json || { echo "${CWARNING}This port is already in /etc/shadowsocks.json${CEND}"; exit 1; } 
+[ ! -e /etc/shadowsocks/config.json ] && { echo "${CFAILURE}Shadowsocks is not installed! ${CEND}"; exit 1; }
+[ -z "`grep \"$Shadowsocks_port\" /etc/shadowsocks/config.json`" ] && sed -i "s@\"port_password\":{@\"port_password\":{\n\t\"$Shadowsocks_port\":\"$Shadowsocks_password\",@" /etc/shadowsocks/config.json || { echo "${CWARNING}This port is already in /etc/shadowsocks/config.json${CEND}"; exit 1; } 
 }
 
 Print_User_shadowsocks(){
@@ -184,21 +263,32 @@ Your Encryption Method: ${CMSG}aes-256-cfb${CEND}
 
 case "$1" in
 install)
-    AddUser_shadowsocks
-    Iptables_set
-    Install_shadowsocks
+    Def_parameter
+    [ "$SS_version" == '1' ] && Install_shadowsocks-libev
+    [ "$SS_version" == '2' ] && Install_shadowsocks-python
     Config_shadowsocks
     service shadowsocks start 
     Print_User_shadowsocks
     ;;
 adduser)
-    AddUser_shadowsocks
-    Iptables_set
-    AddUser_Config_shadowsocks
-    service shadowsocks restart
-    Print_User_shadowsocks
+    Check_shadowsocks
+    if [ "$SS_version" == '2' ];then
+        AddUser_shadowsocks
+        Iptables_set
+        AddUser_Config_shadowsocks
+        service shadowsocks restart
+        Print_User_shadowsocks
+    else
+        printf "
+        Sorry, we have no plan to support multi port configuration. Actually you can use multiple instances instead. For example:
+        ss-server -c /etc/shadowsocks/config1.json -f /var/run/shadowsocks-server/pid1
+        ss-server -c /etc/shadowsocks/config2.json -f /var/run/shadowsocks-server/pid2
+        ss-server -c /etc/shadowsocks/config3.json -f /var/run/shadowsocks-server/pid3
+        "
+    fi
     ;;
 uninstall)
+    Check_shadowsocks
     Uninstall_shadowsocks
     ;;
 *)

+ 1 - 0
upgrade.sh

@@ -20,6 +20,7 @@ printf "
 # get pwd
 sed -i "s@^oneinstack_dir.*@oneinstack_dir=`pwd`@" ./options.conf
 
+. ./apps.conf
 . ./options.conf
 . ./include/color.sh
 . ./include/check_os.sh