Browse Source

pdate SS.sh

lj2007331@gmail.com 7 years ago
parent
commit
eb9f6e2494
5 changed files with 196 additions and 40 deletions
  1. 1 1
      include/upgrade_oneinstack.sh
  2. 0 0
      init.d/SS-libev-init-CentOS
  3. 137 0
      init.d/SS-libev-init-Ubuntu
  4. 37 29
      ss.sh
  5. 21 10
      uninstall.sh

+ 1 - 1
include/upgrade_oneinstack.sh

@@ -28,7 +28,7 @@ Upgrade_OneinStack() {
     [ "$install_flag" == 'n' ] && { /bin/mv /tmp/backup*.sh .; rm -rf install.sh LICENSE README.md; }
     sed -i "s@^oneinstack_md5=.*@oneinstack_md5=${Latest_OneinStack_MD5}@" ./options.conf
     echo
-    echo "${CSUCCESS}Congratulations! OneinStack successful! ${CEND}"
+    echo "${CSUCCESS}Congratulations! OneinStack upgrade successful! ${CEND}"
     echo
   else
     echo "${CWARNING}Your OneinStack already has the latest version or does not need to be upgraded! ${CEND}"

+ 0 - 0
init.d/SS-libev-init → init.d/SS-libev-init-CentOS


+ 137 - 0
init.d/SS-libev-init-Ubuntu

@@ -0,0 +1,137 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          shadowsocks-libev
+# Required-Start:    $network $local_fs $remote_fs
+# Required-Stop:     $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: lightweight secured socks5 proxy
+# Description:       Shadowsocks-libev is a lightweight secured
+#                    socks5 proxy for embedded devices and low end boxes.
+### END INIT INFO
+
+# Author: Max Lv <max.c.lv@gmail.com>
+
+# PATH should only include /usr/ if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC=shadowsocks-libev       # Introduce a short description here
+NAME=shadowsocks-libev       # Introduce the short server's name here
+DAEMON=/usr/local/bin/ss-server    # Introduce the server's location here
+DAEMON_ARGS=""               # Arguments to run the daemon with
+PIDFILE=/var/run/$NAME/$NAME.pid
+SCRIPTNAME=/etc/init.d/shadowsocks
+CONFFILE=/etc/shadowsocks/config.json
+
+# Exit if the package is not installed
+[ -x $DAEMON ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+#[ "$START" = "yes" ] || exit 0
+
+: ${USER:="nobody"}
+: ${GROUP:="nogroup"}
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+    # Modify the file descriptor limit
+    ulimit -n ${MAXFD}
+
+    # Take care of pidfile permissions
+    mkdir /var/run/$NAME 2>/dev/null || true
+    chown "$USER:$GROUP" /var/run/$NAME
+
+    # Return
+    #   0 if daemon has been started
+    #   1 if daemon was already running
+    #   2 if daemon could not be started
+    start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$GROUP --exec $DAEMON --test > /dev/null \
+        || return 1
+    start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$GROUP --exec $DAEMON -- \
+        -c "$CONFFILE" -u -f $PIDFILE $DAEMON_ARGS \
+        || return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+    # Return
+    #   0 if daemon has been stopped
+    #   1 if daemon was already stopped
+    #   2 if daemon could not be stopped
+    #   other if a failure occurred
+    start-stop-daemon --stop --quiet --retry=TERM/5 --pidfile $PIDFILE --exec $DAEMON
+    RETVAL="$?"
+    [ "$RETVAL" = 2 ] && return 2
+    # Wait for children to finish too if this is a daemon that forks
+    # and if the daemon is only ever run from this initscript.
+    # If the above conditions are not satisfied then add some other code
+    # that waits for the process to drop all resources that could be
+    # needed by services started subsequently.  A last resort is to
+    # sleep for some time.
+    start-stop-daemon --stop --quiet --oknodo --retry=KILL/5 --exec $DAEMON
+    [ "$?" = 2 ] && return 2
+    # Many daemons don't delete their pidfiles when they exit.
+    rm -f $PIDFILE
+    return "$RETVAL"
+}
+
+
+case "$1" in
+    start)
+        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
+        do_start
+        case "$?" in
+            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+    esac
+    ;;
+stop)
+    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+    do_stop
+    case "$?" in
+        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+esac
+;;
+  status)
+      status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+      ;;
+  restart|force-reload)
+      log_daemon_msg "Restarting $DESC" "$NAME"
+      do_stop
+      case "$?" in
+          0|1)
+              do_start
+              case "$?" in
+                  0) log_end_msg 0 ;;
+              1) log_end_msg 1 ;; # Old process is still running
+          *) log_end_msg 1 ;; # Failed to start
+      esac
+      ;;
+  *)
+      # Failed to stop
+      log_end_msg 1
+      ;;
+    esac
+    ;;
+*)
+    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+    exit 3
+    ;;
+esac
+
+:

+ 37 - 29
ss.sh

@@ -90,31 +90,28 @@ Iptables_set() {
 }
 
 Def_parameter() {
+  while :; do echo
+    echo "Please select SS server version:"
+    echo -e "\t${CMSG}1${CEND}. Install SS-libev"
+    echo -e "\t${CMSG}2${CEND}. Install SS-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_SS
+  Iptables_set
   if [ "${OS}" == "CentOS" ]; then
-    while :; do echo
-      echo "Please select SS server version:"
-      echo -e "\t${CMSG}1${CEND}. Install SS-libev"
-      echo -e "\t${CMSG}2${CEND}. Install SS-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_SS
-    Iptables_set
-    pkgList="wget unzip openssl-devel gcc swig autoconf libtool libevent automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel git asciidoc xmlto pcre-devel mbedtls-devel udns-devel libev-devel libsodium"
+    pkgList="wget unzip openssl-devel gcc swig autoconf libtool libevent automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel git asciidoc xmlto c-ares-devel pcre-devel mbedtls-devel udns-devel libev-devel libsodium"
     for Package in ${pkgList}; do
       yum -y install ${Package}
     done
   elif [[ "${OS}" =~ ^Ubuntu$|^Debian$ ]]; then
-    SS_version=2
-    AddUser_SS
-    Iptables_set
     apt-get -y update
-    pkgList="curl wget unzip gcc swig automake make perl cpio git libmbedtls-dev libudns-dev libev-dev"
+    pkgList="curl wget unzip gcc swig automake make perl cpio git libmbedtls-dev libudns-dev libev-dev gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libc-ares-dev libsodium-dev"
     for Package in ${pkgList}; do
       apt-get -y install $Package
     done
@@ -141,28 +138,39 @@ Install_SS-python() {
 }
 
 Install_SS-libev() {
-  src_url=http://mirrors.linuxeye.com/oneinstack/src/shadowsocks-libev-3.0.4.tar.gz && Download_src
-  src_url=http://mirrors.linuxeye.com/oneinstack/src/libsodium-1.0.12.tar.gz && Download_src
-  tar xzf shadowsocks-libev-3.0.4.tar.gz
-  tar xzf libsodium-1.0.12.tar.gz
-  pushd libsodium-1.0.12
+  src_url=http://mirrors.linuxeye.com/oneinstack/src/shadowsocks-libev-3.1.1.tar.gz && Download_src
+  src_url=http://mirrors.linuxeye.com/oneinstack/src/libsodium-1.0.16.tar.gz && Download_src
+  src_url=http://mirrors.linuxeye.com/oneinstack/src/mbedtls-2.6.0-gpl.tgz && Download_src
+  tar xzf shadowsocks-libev-3.1.1.tar.gz
+  tar xzf libsodium-1.0.16.tar.gz
+  tar xzf mbedtls-2.6.0-gpl.tgz 
+  pushd libsodium-1.0.16
   ./configure
   make -j ${THREAD} && make install
   popd
-  pushd shadowsocks-libev-3.0.4
+  pushd mbedtls-2.6.0
+  make SHARED=1 CFLAGS=-fPIC
+  make DESTDIR=/usr install
+  popd
+  pushd shadowsocks-libev-3.1.1
   ./configure
   make -j ${THREAD} && make install
   popd
+  ldconfig
   if [ -f /usr/local/bin/ss-server ]; then
-    /bin/cp ../init.d/SS-libev-init /etc/init.d/shadowsocks
-    chmod +x /etc/init.d/shadowsocks
-    [ "${OS}" == "CentOS" ] && { chkconfig --add shadowsocks; chkconfig shadowsocks on; }
+    if [ "${OS}" == "CentOS" ]; then
+      /bin/cp ../init.d/SS-libev-init-CentOS /etc/init.d/shadowsocks
+      chkconfig --add shadowsocks
+      chkconfig shadowsocks on
+    elif [[ "${OS}" =~ ^Ubuntu$|^Debian$ ]];then
+      /bin/cp ../init.d/SS-libev-init-Ubuntu /etc/init.d/shadowsocks
+      update-rc.d shadowsocks defaults
+    fi
   else
     echo
     echo "${CQUESTION}SS-libev install failed! Please visit https://oneinstack.com${CEND}"
     exit 1
   fi
-
 }
 
 Uninstall_SS() {

+ 21 - 10
uninstall.sh

@@ -93,14 +93,21 @@ Uninstall_Web() {
   echo "${CMSG}Web uninstall completed${CEND}"
 }
 
-Print_DB() {
+Print_MySQL() {
   [ -e "${db_install_dir}" ] && echo "${db_install_dir}"
   [ -e "/etc/init.d/mysqld" ] && echo "/etc/init.d/mysqld"
   [ -e "/etc/my.cnf" ] && echo "/etc/my.cnf"
+}
+
+Print_PosgreSQL() {
   [ -e "${pgsql_install_dir}" ] && echo "${pgsql_install_dir}"
   [ -e "/etc/init.d/postgresql" ] && echo "/etc/init.d/postgresql"
+}
+
+Print_MongoDB() {
   [ -e "${mongo_install_dir}" ] && echo "${mongo_install_dir}"
   [ -e "/etc/init.d/mongod" ] && echo "/etc/init.d/mongod"
+  [ -e "/etc/mongod.conf" ] && echo "/etc/mongod.conf"
 }
 
 Uninstall_MySQL() {
@@ -136,7 +143,7 @@ Uninstall_MongoDB() {
   # uninstall mongodb 
   if [ -e "${mongo_install_dir}/bin/mongo" ]; then
     service mongod stop > /dev/null 2>&1
-    rm -rf ${mongo_install_dir} /etc/mongod.conf /etc/init.d/mongod /var/log/mongodb /tmp/mongo*.sock
+    rm -rf ${mongo_install_dir} /etc/mongod.conf /etc/init.d/mongod /tmp/mongo*.sock
     id -u mongod > /dev/null 2>&1 ; [ $? -eq 0 ] && userdel mongod 
     [ -e "${mongo_data_dir}" ] && /bin/mv ${mongo_data_dir}{,$(date +%Y%m%d%H)}
     sed -i 's@^dbmongopwd=.*@dbmongopwd=@' ./options.conf
@@ -246,7 +253,9 @@ What Are You Doing?
     0)
       Print_Warn
       Print_web
-      Print_DB
+      Print_MySQL
+      Print_PostgreSQL
+      Print_MongoDB
       Print_PHP
       Print_HHVM
       Print_PureFtpd
@@ -278,19 +287,19 @@ What Are You Doing?
       ;;
     2)
       Print_Warn
-      Print_DB
+      Print_MySQL
       Uninstall_status
       [ "${uninstall_yn}" == 'y' ] && Uninstall_MySQL || exit
       ;;
     3)
       Print_Warn
-      Print_DB
+      Print_PostgreSQL
       Uninstall_status
       [ "${uninstall_yn}" == 'y' ] && Uninstall_PostgreSQL || exit
       ;;
     4)
       Print_Warn
-      Print_DB
+      Print_MongoDB
       Uninstall_status
       [ "${uninstall_yn}" == 'y' ] && Uninstall_MongoDB || exit
       ;;
@@ -334,7 +343,9 @@ elif [ $# == 1 ]; then
   all)
     Print_Warn
     Print_web
-    Print_DB
+    Print_MySQL
+    Print_PostgreSQL
+    Print_MongoDB
     Print_PHP
     Print_HHVM
     Print_PureFtpd
@@ -364,19 +375,19 @@ elif [ $# == 1 ]; then
     ;;
   mysql)
     Print_Warn
-    Print_DB
+    Print_MySQL
     Uninstall_status
     [ "${uninstall_yn}" == 'y' ] && Uninstall_MySQL || exit
     ;;
   postgresql)
     Print_Warn
-    Print_DB
+    Print_PostgreSQL
     Uninstall_status
     [ "${uninstall_yn}" == 'y' ] && Uninstall_PostgreSQL || exit
     ;;
   mongodb)
     Print_Warn
-    Print_DB
+    Print_MongoDB
     Uninstall_status
     [ "${uninstall_yn}" == 'y' ] && Uninstall_MongoDB || exit
     ;;