Browse Source

Update upgrade.sh and pureftpd_host.sh

lj2007331@gmail.com 6 years ago
parent
commit
fcf2a62999

+ 5 - 3
include/upgrade_db.sh

@@ -55,7 +55,7 @@ Upgrade_DB() {
   echo
   echo "Current ${DB} Version: ${CMSG}${OLD_db_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade ${DB} Version(example: ${OLD_db_ver}): " NEW_db_ver
+    [ "${db_quiet}" != 'y' ] && read -e -p "Please input upgrade ${DB} Version(example: ${OLD_db_ver}): " NEW_db_ver
     if [ `echo ${NEW_db_ver} | awk -F. '{print $1"."$2}'` == `echo ${OLD_db_ver} | awk -F. '{print $1"."$2}'` ]; then
       if [ "${DB}" == 'MariaDB' ]; then
         DB_name=mariadb-${NEW_db_ver}-${GLIBC_FLAG}-${SYS_BIT_b}
@@ -85,8 +85,10 @@ Upgrade_DB() {
 
   if [ -e "`ls ${DB_name}.tar.?z 2>/dev/null`" ]; then
     echo "[${CMSG}`ls ${DB_name}.tar.?z 2>/dev/null`${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${db_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     if [ "${DB}" == 'MariaDB' ]; then
       service mysqld stop
       mv ${mariadb_install_dir}{,_old_`date +"%Y%m%d_%H%M%S"`}

+ 6 - 3
include/upgrade_memcached.sh

@@ -16,7 +16,7 @@ Upgrade_Memcached() {
   Latest_memcached_ver=${Latest_memcached_ver:-1.5.12}
   echo "Current Memcached Version: ${CMSG}${OLD_memcached_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade Memcached Version(default: ${Latest_memcached_ver}): " NEW_memcached_ver
+    [ "${memcached_quiet}" != 'y' ] && read -e -p "Please input upgrade Memcached Version(default: ${Latest_memcached_ver}): " NEW_memcached_ver
     NEW_memcached_ver=${NEW_memcached_ver:-${Latest_memcached_ver}}
     if [ "${NEW_memcached_ver}" != "${OLD_memcached_ver}" ]; then
       [ "$IPADDR_COUNTRY"x == "CN"x ] && DOWN_ADDR=http://mirrors.linuxeye.com/oneinstack/src || DOWN_ADDR=http://www.memcached.org/files
@@ -29,13 +29,16 @@ Upgrade_Memcached() {
       fi
     else
       echo "${CWARNING}input error! Upgrade Memcached version is the same as the old version${CEND}"
+      exit
     fi
   done
 
   if [ -e "memcached-${NEW_memcached_ver}.tar.gz" ]; then
     echo "[${CMSG}memcached-${NEW_memcached_ver}.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${memcached_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf memcached-${NEW_memcached_ver}.tar.gz
     pushd memcached-${NEW_memcached_ver}
     make clean

+ 5 - 3
include/upgrade_php.sh

@@ -17,7 +17,7 @@ Upgrade_PHP() {
   echo
   echo "Current PHP Version: ${CMSG}$OLD_php_ver${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade PHP Version(Default: $Latest_php_ver): " NEW_php_ver
+    [ "${php_quiet}" != 'y' ] && read -e -p "Please input upgrade PHP Version(Default: $Latest_php_ver): " NEW_php_ver
     NEW_php_ver=${NEW_php_ver:-${Latest_php_ver}}
     if [ "${NEW_php_ver%.*}" == "${OLD_php_ver%.*}" ]; then
       [ ! -e "php-${NEW_php_ver}.tar.gz" ] && wget --no-check-certificate -c http://www.php.net/distributions/php-${NEW_php_ver}.tar.gz > /dev/null 2>&1
@@ -34,8 +34,10 @@ Upgrade_PHP() {
 
   if [ -e "php-${NEW_php_ver}.tar.gz" ]; then
     echo "[${CMSG}php-${NEW_php_ver}.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${php_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf php-${NEW_php_ver}.tar.gz
     src_url=http://mirrors.linuxeye.com/oneinstack/src/fpm-race-condition.patch && Download_src
     patch -d php-${NEW_php_ver} -p0 < fpm-race-condition.patch

+ 6 - 3
include/upgrade_phpmyadmin.sh

@@ -16,7 +16,7 @@ Upgrade_phpMyAdmin() {
   Latest_phpmyadmin_ver=${Latest_phpmyadmin_ver:-4.8.3}
   echo "Current phpMyAdmin Version: ${CMSG}${OLD_phpmyadmin_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade phpMyAdmin Version(default: ${Latest_phpmyadmin_ver}): " NEW_phpmyadmin_ver
+    [ "${phpmyadmin_quiet}" != 'y' ] && read -e -p "Please input upgrade phpMyAdmin Version(default: ${Latest_phpmyadmin_ver}): " NEW_phpmyadmin_ver
     NEW_phpmyadmin_ver=${NEW_phpmyadmin_ver:-${Latest_phpmyadmin_ver}}
     if [ "${NEW_phpmyadmin_ver}" != "${OLD_phpmyadmin_ver}" ]; then
       [ ! -e "phpMyAdmin-${NEW_phpmyadmin_ver}-all-languages.tar.gz" ] && wget --no-check-certificate -c https://files.phpmyadmin.net/phpMyAdmin/${NEW_phpmyadmin_ver}/phpMyAdmin-${NEW_phpmyadmin_ver}-all-languages.tar.gz > /dev/null 2>&1
@@ -28,13 +28,16 @@ Upgrade_phpMyAdmin() {
       fi
     else
       echo "${CWARNING}input error! Upgrade phpMyAdmin version is the same as the old version${CEND}"
+      exit
     fi
   done
 
   if [ -e "phpMyAdmin-${NEW_phpmyadmin_ver}-all-languages.tar.gz" ]; then
     echo "[${CMSG}phpMyAdmin-${NEW_phpmyadmin_ver}-all-languages.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${phpmyadmin_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf phpMyAdmin-${NEW_phpmyadmin_ver}-all-languages.tar.gz
     rm -rf ${wwwroot_dir}/default/phpMyAdmin
     /bin/mv phpMyAdmin-${NEW_phpmyadmin_ver}-all-languages ${wwwroot_dir}/default/phpMyAdmin

+ 6 - 3
include/upgrade_redis.sh

@@ -16,7 +16,7 @@ Upgrade_Redis() {
   Latest_redis_ver=${Latest_redis_ver:-5.0.2}
   echo "Current Redis Version: ${CMSG}$OLD_redis_ver${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade Redis Version(default: ${Latest_redis_ver}): " NEW_redis_ver
+    [ "${redis_quiet}" != 'y' ] && read -e -p "Please input upgrade Redis Version(default: ${Latest_redis_ver}): " NEW_redis_ver
     NEW_redis_ver=${NEW_redis_ver:-${Latest_redis_ver}}
     if [ "$NEW_redis_ver" != "$OLD_redis_ver" ]; then
       [ ! -e "redis-$NEW_redis_ver.tar.gz" ] && wget --no-check-certificate -c http://download.redis.io/releases/redis-$NEW_redis_ver.tar.gz > /dev/null 2>&1
@@ -28,13 +28,16 @@ Upgrade_Redis() {
       fi
     else
       echo "${CWARNING}input error! Upgrade Redis version is the same as the old version${CEND}"
+      exit
     fi
   done
 
   if [ -e "redis-$NEW_redis_ver.tar.gz" ]; then
     echo "[${CMSG}redis-$NEW_redis_ver.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${redis_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf redis-$NEW_redis_ver.tar.gz
     pushd redis-$NEW_redis_ver
     make clean

+ 29 - 15
include/upgrade_web.sh

@@ -18,7 +18,7 @@ Upgrade_Nginx() {
   echo
   echo "Current Nginx Version: ${CMSG}${OLD_nginx_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade Nginx Version(default: ${Latest_nginx_ver}): " NEW_nginx_ver
+    [ "${nginx_quiet}" != 'y' ] && read -e -p "Please input upgrade Nginx Version(default: ${Latest_nginx_ver}): " NEW_nginx_ver
     NEW_nginx_ver=${NEW_nginx_ver:-${Latest_nginx_ver}}
     if [ "${NEW_nginx_ver}" != "${OLD_nginx_ver}" ]; then
       [ ! -e "nginx-${NEW_nginx_ver}.tar.gz" ] && wget --no-check-certificate -c http://nginx.org/download/nginx-${NEW_nginx_ver}.tar.gz > /dev/null 2>&1
@@ -34,13 +34,16 @@ Upgrade_Nginx() {
       fi
     else
       echo "${CWARNING}input error! Upgrade Nginx version is the same as the old version${CEND}"
+      exit
     fi
   done
 
   if [ -e "nginx-${NEW_nginx_ver}.tar.gz" ]; then
     echo "[${CMSG}nginx-${NEW_nginx_ver}.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${nginx_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf nginx-${NEW_nginx_ver}.tar.gz
     [ "${Fedora_ver}" == '28' ] && patch -d nginx-${NEW_nginx_ver} -p1 < 0001-unix-ngx_user-Apply-fix-for-really-old-bug-in-glibc-.patch
     patch -d nginx-${NEW_nginx_ver} -p0 < nginx-auto-cc-gcc.patch
@@ -80,7 +83,7 @@ Upgrade_Tengine() {
   echo
   echo "Current Tengine Version: ${CMSG}${OLD_tengine_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade Tengine Version(default: ${Latest_tengine_ver}): " NEW_tengine_ver
+    [ "${tengine_quiet}" != 'y' ] && read -e -p "Please input upgrade Tengine Version(default: ${Latest_tengine_ver}): " NEW_tengine_ver
     NEW_tengine_ver=${NEW_tengine_ver:-${Latest_tengine_ver}}
     if [ "${NEW_tengine_ver}" != "${OLD_tengine_ver}" ]; then
       [ ! -e "tengine-${NEW_tengine_ver}.tar.gz" ] && wget --no-check-certificate -c http://tengine.taobao.org/download/tengine-${NEW_tengine_ver}.tar.gz > /dev/null 2>&1
@@ -96,13 +99,16 @@ Upgrade_Tengine() {
       fi
     else
       echo "${CWARNING}input error! Upgrade Tengine version is the same as the old version${CEND}"
+      exit
     fi
   done
 
   if [ -e "tengine-${NEW_tengine_ver}.tar.gz" ]; then
     echo "[${CMSG}tengine-${NEW_tengine_ver}.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${tengine_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf tengine-${NEW_tengine_ver}.tar.gz
     [ "${Fedora_ver}" == '28' ] && patch -d tengine-${tengine_ver} -p1 < 0001-unix-ngx_user-Apply-fix-for-really-old-bug-in-glibc-.patch
     patch -d tengine-${tengine_ver} -p0 < nginx-auto-cc-gcc.patch
@@ -147,7 +153,7 @@ Upgrade_OpenResty() {
   echo
   echo "Current OpenResty Version: ${CMSG}${OLD_openresy_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade OpenResty Version(default: ${Latest_openresy_ver}): " NEW_openresy_ver
+    [ "${openresty_quiet}" != 'y' ] && read -e -p "Please input upgrade OpenResty Version(default: ${Latest_openresy_ver}): " NEW_openresy_ver
     NEW_openresy_ver=${NEW_openresy_ver:-${Latest_openresy_ver}}
     if [ "${NEW_openresy_ver}" != "${OLD_openresy_ver}" ]; then
       [ ! -e "openresty-${NEW_openresy_ver}.tar.gz" ] && wget --no-check-certificate -c https://openresty.org/download/openresty-${NEW_openresy_ver}.tar.gz > /dev/null 2>&1
@@ -163,13 +169,16 @@ Upgrade_OpenResty() {
       fi
     else
       echo "${CWARNING}input error! Upgrade OpenResty version is the same as the old version${CEND}"
+      exit
     fi
   done
 
   if [ -e "openresty-${NEW_openresy_ver}.tar.gz" ]; then
     echo "[${CMSG}openresty-${NEW_openresy_ver}.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${openresty_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf openresty-${NEW_openresy_ver}.tar.gz
     [ "${Fedora_ver}" == '28' ] && patch -d openresty-${openresty_ver}/bundle/nginx-${NEW_openresy_ver%.*} -p1 < 0001-unix-ngx_user-Apply-fix-for-really-old-bug-in-glibc-.patch
     patch -d openresty-${openresty_ver}/bundle/nginx-${NEW_openresy_ver%.*} -p0 < nginx-auto-cc-gcc.patch
@@ -205,7 +214,7 @@ Upgrade_Apache() {
   echo
   echo "Current Apache Version: ${CMSG}${OLD_apache_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade Apache Version(Default: ${Latest_apache_ver}): " NEW_apache_ver
+    [ "${apache_quiet}" != 'y' ] && read -e -p "Please input upgrade Apache Version(Default: ${Latest_apache_ver}): " NEW_apache_ver
     NEW_apache_ver=${NEW_apache_ver:-${Latest_apache_ver}}
     if [ `echo ${NEW_apache_ver} | awk -F. '{print $1$2}'` == "${Apache_flag}" ]; then
       if [ "${NEW_apache_ver}" != "${OLD_apache_ver}" ]; then
@@ -224,6 +233,7 @@ Upgrade_Apache() {
         fi
       else
         echo "${CWARNING}input error! Upgrade Apache version is the same as the old version${CEND}"
+        exit
       fi
     else
       echo "${CWARNING}input error! ${CEND}Please only input '${CMSG}${OLD_apache_ver%.*}.xx${CEND}'"
@@ -232,8 +242,10 @@ Upgrade_Apache() {
 
   if [ -e "httpd-${NEW_apache_ver}.tar.gz" ]; then
     echo "[${CMSG}httpd-${NEW_apache_ver}.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${apache_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf httpd-${NEW_apache_ver}.tar.gz
     pushd httpd-${NEW_apache_ver}
     make clean
@@ -272,7 +284,7 @@ Upgrade_Tomcat() {
   echo
   echo "Current Tomcat Version: ${CMSG}${OLD_tomcat_ver}${CEND}"
   while :; do echo
-    read -e -p "Please input upgrade Tomcat Version(Default: ${Latest_tomcat_ver}): " NEW_tomcat_ver
+    [ "${tomcat_quiet}" != 'y' ] && read -e -p "Please input upgrade Tomcat Version(Default: ${Latest_tomcat_ver}): " NEW_tomcat_ver
     NEW_tomcat_ver=${NEW_tomcat_ver:-${Latest_tomcat_ver}}
     if [ "`echo ${NEW_tomcat_ver} | awk -F. '{print $1}'`" == "${Tomcat_flag}" ]; then
       rm -f catalina-jmx-remote.jar
@@ -294,8 +306,10 @@ Upgrade_Tomcat() {
 
   if [ -e "apache-tomcat-${NEW_tomcat_ver}.tar.gz" ]; then
     echo "[${CMSG}apache-tomcat-${NEW_tomcat_ver}.tar.gz${CEND}] found"
-    echo "Press Ctrl+c to cancel or Press any key to continue..."
-    char=`get_char`
+    if [ "${tomcat_quiet}" != 'y' ]; then
+      echo "Press Ctrl+c to cancel or Press any key to continue..."
+      char=`get_char`
+    fi
     tar xzf apache-tomcat-${NEW_tomcat_ver}.tar.gz
     /bin/mv apache-tomcat-${NEW_tomcat_ver}/conf/server.xml{,_bk}
     /bin/cp ${tomcat_install_dir}/conf/{server.xml,jmxremote.access,jmxremote.password,tomcat-users.xml} apache-tomcat-${NEW_tomcat_ver}/conf/

+ 215 - 107
pureftpd_vhost.sh

@@ -32,46 +32,193 @@ FTP_tmp_passfile=${pureftpd_install_dir}/etc/pureftpd_psss.tmp
 Puredbfile=${pureftpd_install_dir}/etc/pureftpd.pdb
 Passwdfile=${pureftpd_install_dir}/etc/pureftpd.passwd
 FTP_bin=${pureftpd_install_dir}/bin/pure-pw
-[ -z "`grep ^PureDB $FTP_conf`" ] && { echo "${CFAILURE}pure-ftpd is not own password database${CEND}" ; exit 1; }
+[ -z "`grep ^PureDB ${FTP_conf}`" ] && { echo "${CFAILURE}pure-ftpd is not own password database${CEND}" ; exit 1; }
 
-USER() {
-while :; do echo
-  read -e -p "Please input a username: " User
-  if [ -z "${User}" ]; then
-    echo "${CWARNING}username can't be NULL! ${CEND}"
-  else
-    break
-  fi
+ARG_NUM=$#
+showhelp() {
+  echo
+  echo "Usage: $0  command ...[parameters]....
+  --help, -h                          Show this help message
+  --useradd,--add                     Add username
+  --usermod                           Modify directory
+  --passwd                            Modify password
+  --userdel,--delete                  Delete User
+  --listalluser,--list                List all User
+  --showuser                          List User details
+  --username,-u     [ftp username]    Ftp username
+  --password,-p     [ftp password]    Ftp password
+  --directory,-d,-D [ftp directory]   Ftp home directory
+  "
+}
+
+TEMP=`getopt -o hu:p:d:D: --long help,useradd,add,usermod,passwd,userdel,delete,listalluser,list,showuser,username:,password:,directory: -- "$@" 2>/dev/null`
+[ $? != 0 ] && echo "${CWARNING}ERROR: unknown argument! ${CEND}" && showhelp && exit 1
+eval set -- "${TEMP}"
+while :; do
+  [ -z "$1" ] && break;
+  case "$1" in
+    -h|--help)
+      showhelp; exit 0
+      ;;
+    --add|--useradd)
+      useradd_quiet=y; shift 1
+      ;;
+    --usermod)
+      usermod_quiet=y; shift 1
+      ;;
+    --passwd)
+      passwd_quiet=y; shift 1
+      ;;
+    --delete|--userdel)
+      userdel_quiet=y; shift 1
+      ;;
+    --list|--listalluser)
+      listalluser_quiet=y; shift 1
+      ;;
+    --showuser)
+      showuser_quiet=y; shift 1
+      ;;
+    -u|--username)
+      username_quiet=y; User=$2; shift 2
+      ;;
+    -p|--password)
+      password_quiet=y; Password=$2; shift 2
+      ;;
+    -d|-D|--directory)
+      directory_quiet=y; Directory=$2; shift 2
+      ;;
+    --)
+      shift
+      ;;
+    *)
+      echo "${CWARNING}ERROR: unknown argument! ${CEND}" && showhelp && exit 1
+      ;;
+  esac
 done
+
+USER() {
+  while :; do
+    if [ "${username_quiet}" != 'y' ]; then
+      echo
+      read -e -p "Please input a username: " User
+    fi
+    if [ -z "${User}" ]; then
+      echo "${CWARNING}username can't be NULL! ${CEND}"
+    else
+      break
+    fi
+  done
 }
 
 PASSWORD() {
-while :; do echo
-  read -e -p "Please input the password: " Password
-  [ -n "`echo ${Password} | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and &${CEND}"; continue; }
-  if (( ${#Password} >= 5 ));then
-    echo -e "${Password}\n${Password}" > ${FTP_tmp_passfile}
-    break
+  while :; do
+    if [ "${password_quiet}" != 'y' ]; then
+      echo
+      read -e -p "Please input the password: " Password
+    fi
+    [ -n "`echo ${Password} | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and &${CEND}"; continue; }
+    if (( ${#Password} >= 5 )); then
+      echo -e "${Password}\n${Password}" > ${FTP_tmp_passfile}
+      break
+    else
+      echo "${CWARNING}Ftp password least 5 characters! ${CEND}"
+    fi
+  done
+}
+
+DIRECTORY() {
+  while :; do
+    if [ "${directory_quiet}" != 'y' ]; then
+      echo
+      read -e -p "Please input the directory(Default directory: ${wwwroot_dir}): " Directory
+    fi
+    Directory=${Directory:-${wwwroot_dir}}
+    if [ ! -d "${Directory}" ]; then
+      echo "${CWARNING}The directory does not exist${CEND}"
+    else
+      break
+    fi
+  done
+}
+
+UserAdd() {
+  USER
+  [ -e "${Passwdfile}" ] && [ -n "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] is already existed! ${CEND}"; exit 1; }
+  PASSWORD;DIRECTORY
+  ${FTP_bin} useradd ${User} -f ${Passwdfile} -u ${run_user} -g ${run_user} -d ${Directory} -m < ${FTP_tmp_passfile}
+  ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
+  echo "#####################################"
+  echo
+  echo "[${User}] create successful! "
+  echo
+  echo "You user name is : ${CMSG}${User}${CEND}"
+  echo "You Password is : ${CMSG}${Password}${CEND}"
+  echo "You directory is : ${CMSG}${Directory}${CEND}"
+  echo
+}
+
+UserMod() {
+  USER
+  [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
+  DIRECTORY
+  ${FTP_bin} usermod ${User} -f ${Passwdfile} -d ${Directory} -m
+  ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
+  echo "#####################################"
+  echo
+  echo "[${User}] modify a successful! "
+  echo
+  echo "You user name is : ${CMSG}${User}${CEND}"
+  echo "You new directory is : ${CMSG}${Directory}${CEND}"
+  echo
+}
+
+UserPasswd() {
+  USER
+  [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
+  PASSWORD
+  ${FTP_bin} passwd ${User} -f ${Passwdfile} -m < ${FTP_tmp_passfile}
+  ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
+  echo "#####################################"
+  echo
+  echo "[${User}] Password changed successfully! "
+  echo
+  echo "You user name is : ${CMSG}${User}${CEND}"
+  echo "You new password is : ${CMSG}${Password}${CEND}"
+  echo
+}
+
+UserDel() {
+  if [ ! -e "${Passwdfile}" ]; then
+    echo "${CQUESTION}User was not existed! ${CEND}"
   else
-    echo "${CWARNING}Ftp password least 5 characters! ${CEND}"
+    ${FTP_bin} list
   fi
-done
+
+  USER
+  [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
+  ${FTP_bin} userdel ${User} -f ${Passwdfile} -m
+  ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
+  echo
+  echo "[${User}] have been deleted! "
 }
 
-DIRECTORY() {
-while :; do echo
-  read -e -p "Please input the directory(Default directory: ${wwwroot_dir}): " Directory
-  Directory=${Directory:-${wwwroot_dir}}
-  if [ ! -d "${Directory}" ]; then
-    echo "${CWARNING}The directory does not exist${CEND}"
+ListAllUser() {
+  if [ ! -e "${Passwdfile}" ]; then
+    echo "${CQUESTION}User was not existed! ${CEND}"
   else
-    break
+    ${FTP_bin} list
   fi
-done
 }
 
-while :; do
-  printf "
+ShowUser() {
+  USER
+  [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
+  ${FTP_bin} show ${User}
+}
+
+Menu() {
+  while :; do
+    printf "
 What Are You Doing?
 \t${CMSG}1${CEND}. UserAdd
 \t${CMSG}2${CEND}. UserMod
@@ -81,83 +228,44 @@ What Are You Doing?
 \t${CMSG}6${CEND}. ShowUser
 \t${CMSG}q${CEND}. Exit
 "
-  read -e -p "Please input the correct option: " Number
-  if [[ ! $Number =~ ^[1-6,q]$ ]]; then
-    echo "${CFAILURE}input error! Please only input 1~6 and q${CEND}"
-  else
-    case "$Number" in
-    1)
-      USER
-      [ -e "${Passwdfile}" ] && [ -n "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] is already existed! ${CEND}"; continue; }
-      PASSWORD;DIRECTORY
-      ${FTP_bin} useradd ${User} -f ${Passwdfile} -u ${run_user} -g ${run_user} -d ${Directory} -m < ${FTP_tmp_passfile}
-      ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
-      echo "#####################################"
-      echo
-      echo "[${User}] create successful! "
-      echo
-      echo "You user name is : ${CMSG}${User}${CEND}"
-      echo "You Password is : ${CMSG}${Password}${CEND}"
-      echo "You directory is : ${CMSG}${Directory}${CEND}"
-      echo
-      ;;
-    2)
-      USER
-      [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; continue; }
-      DIRECTORY
-      ${FTP_bin} usermod ${User} -f ${Passwdfile} -d ${Directory} -m
-      ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
-      echo "#####################################"
-      echo
-      echo "[${User}] modify a successful! "
-      echo
-      echo "You user name is : ${CMSG}${User}${CEND}"
-      echo "You new directory is : ${CMSG}${Directory}${CEND}"
-      echo
-      ;;
-    3)
-      USER
-      [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; continue; }
-      PASSWORD
-      ${FTP_bin} passwd ${User} -f ${Passwdfile} -m < ${FTP_tmp_passfile}
-      ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
-      echo "#####################################"
-      echo
-      echo "[${User}] Password changed successfully! "
-      echo
-      echo "You user name is : ${CMSG}${User}${CEND}"
-      echo "You new password is : ${CMSG}${Password}${CEND}"
-      echo
-      ;;
-    4)
-      if [ ! -e "${Passwdfile}" ]; then
-        echo "${CQUESTION}User was not existed! ${CEND}"
-      else
-        ${FTP_bin} list
-      fi
-
-      USER
-      [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; continue; }
-      ${FTP_bin} userdel ${User} -f ${Passwdfile} -m
-      ${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
-      echo
-      echo "[${User}] have been deleted! "
-      ;;
-    5)
-      if [ ! -e "${Passwdfile}" ]; then
-        echo "${CQUESTION}User was not existed! ${CEND}"
-      else
-        ${FTP_bin} list
-      fi
-      ;;
-    6)
-      USER
-      [ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; continue; }
-      ${FTP_bin} show ${User}
-      ;;
-    q)
-      exit
-      ;;
-    esac
-  fi
-done
+    read -e -p "Please input the correct option: " Number
+    if [[ ! ${Number} =~ ^[1-6,q]$ ]]; then
+      echo "${CFAILURE}input error! Please only input 1~6 and q${CEND}"
+    else
+      case "${Number}" in
+      1)
+        UserAdd
+        ;;
+      2)
+        UserMod
+        ;;
+      3)
+        UserPasswd
+        ;;
+      4)
+        UserDel
+        ;;
+      5)
+        ListAllUser
+        ;;
+      6)
+        ShowUser
+        ;;
+      q)
+        exit
+        ;;
+      esac
+    fi
+  done
+}
+
+if [ ${ARG_NUM} == 0 ]; then
+  Menu
+else
+  [ "${useradd_quiet}" == 'y' ] && UserAdd
+  [ "${usermod_quiet}" == 'y' ] && UserMod
+  [ "${passwd_quiet}" == 'y' ] && UserPasswd
+  [ "${userdel_quiet}" == 'y' ] && UserDel
+  [ "${listalluser_quiet}" == 'y' ] && ListAllUser
+  [ "${showuser_quiet}" == 'y' ] && ShowUser
+fi

+ 108 - 84
upgrade.sh

@@ -39,69 +39,131 @@ pushd ${oneinstack_dir} > /dev/null
 
 # get the IP information
 PUBLIC_IPADDR=$(./include/get_public_ipaddr.py)
-IPADDR_COUNTRY=$(./include/get_ipaddr_state.py $PUBLIC_IPADDR)
+IPADDR_COUNTRY=$(./include/get_ipaddr_state.py ${PUBLIC_IPADDR})
 
-Usage(){
-  printf "
-Usage: $0 [ ${CMSG}web${CEND} | ${CMSG}db${CEND} | ${CMSG}php${CEND} | ${CMSG}redis${CEND} | ${CMSG}memcached${CEND} | ${CMSG}phpmyadmin${CEND} | ${CMSG}oneinstack${CEND} | ${CMSG}acme.sh${CEND} ]
-${CMSG}web${CEND} [nginx|tengine|openresty|apache|tomcat] ->Upgrade Nginx/Tengine/OpenResty/Apache/Tomcat
-${CMSG}db${CEND}                                          ->Upgrade MySQL/MariaDB/Percona
-${CMSG}php${CEND}                                         ->Upgrade PHP
-${CMSG}redis${CEND}                                       ->Upgrade Redis
-${CMSG}memcached${CEND}                                   ->Upgrade Memcached
-${CMSG}phpmyadmin${CEND}                                  ->Upgrade phpMyAdmin
-${CMSG}oneinstack${CEND}                                  ->Upgrade OneinStack
-${CMSG}acme.sh${CEND}                                     ->Upgrade acme.sh
-
-"
+showhelp() {
+  echo
+  echo "Usage: $0  command ...[version]....
+  --help, -h                  Show this help message
+  --nginx        [version]    Upgrade Nginx
+  --tengine      [version]    Upgrade Tengine
+  --openresty    [version]    Upgrade OpenResty
+  --apache       [version]    Upgrade Apache
+  --tomcat       [version]    Upgrade Tomcat
+  --db           [version]    Upgrade MySQL/MariaDB/Percona
+  --php          [version]    Upgrade PHP
+  --redis        [version]    Upgrade Redis
+  --memcached    [version]    Upgrade Memcached
+  --phpmyadmin   [version]    Upgrade phpMyAdmin
+  --oneinstack                Upgrade OneinStack latest
+  --acme.sh                   Upgrade acme.sh latest
+  "
 }
 
+ARG_NUM=$#
+TEMP=`getopt -o h --long help,nginx:,tengine:,openresty:,apache:,tomcat:,db:,php:,redis:,memcached:,phpmyadmin:,oneinstack,acme.sh -- "$@" 2>/dev/null`
+[ $? != 0 ] && echo "${CWARNING}ERROR: unknown argument! ${CEND}" && showhelp && exit 1
+eval set -- "${TEMP}"
+while :; do
+  [ -z "$1" ] && break;
+  case "$1" in
+    -h|--help)
+      showhelp; exit 0
+      ;;
+    --nginx)
+      nginx_quiet=y; NEW_nginx_ver=$2; shift 2
+      ;;
+    --tengine)
+      tengine_quiet=y; NEW_tengine_ver=$2; shift 2
+      ;;
+    --openresty)
+      openresty_quiet=y; NEW_openresy_ver=$2; shift 2
+      ;;
+    --apache)
+      apache_quiet=y; NEW_apache_ver=$2; shift 2
+      ;;
+    --tomcat)
+      tomcat_quiet=y; NEW_tomcat_ver=$2; shift 2
+      ;;
+    --php)
+      php_quiet=y; NEW_php_ver=$2; shift 2
+      ;;
+    --redis)
+      redis_quiet=y; NEW_redis_ver=$2; shift 2
+      ;;
+    --memcached)
+      memcached_quiet=y; NEW_memcached_ver=$2; shift 2
+      ;;
+    --phpmyadmin)
+      phpmyadmin_quiet=y; NEW_phpmyadmin_ver=$2; shift 2
+      ;;
+    --oneinstack)
+      NEW_oneinstack_ver=latest; shift 1
+      ;;
+    --acme.sh)
+      NEW_acme_ver=latest; shift 1
+      ;;
+    --)
+      shift
+      ;;
+    *)
+      echo "${CWARNING}ERROR: unknown argument! ${CEND}" && showhelp && exit 1
+      ;;
+  esac
+done
+
 Menu(){
   while :; do
     printf "
 What Are You Doing?
-\t${CMSG}1${CEND}. Upgrade Nginx/Tengine/OpenResty/Apache/Tomcat
-\t${CMSG}2${CEND}. Upgrade MySQL/MariaDB/Percona
-\t${CMSG}3${CEND}. Upgrade PHP
-\t${CMSG}4${CEND}. Upgrade Redis
-\t${CMSG}5${CEND}. Upgrade Memcached
-\t${CMSG}6${CEND}. Upgrade phpMyAdmin
-\t${CMSG}7${CEND}. Upgrade OneinStack
-\t${CMSG}8${CEND}. Upgrade acme.sh
-\t${CMSG}q${CEND}. Exit
+\t${CMSG} 1${CEND}. Upgrade Nginx/Tengine/OpenResty
+\t${CMSG} 2${CEND}. Upgrade Apache
+\t${CMSG} 3${CEND}. Upgrade Tomcat
+\t${CMSG} 4${CEND}. Upgrade MySQL/MariaDB/Percona
+\t${CMSG} 5${CEND}. Upgrade PHP
+\t${CMSG} 6${CEND}. Upgrade Redis
+\t${CMSG} 7${CEND}. Upgrade Memcached
+\t${CMSG} 8${CEND}. Upgrade phpMyAdmin
+\t${CMSG} 9${CEND}. Upgrade OneinStack latest
+\t${CMSG}10${CEND}. Upgrade acme.sh latest
+\t${CMSG} q${CEND}. Exit
 "
     echo
     read -e -p "Please input the correct option: " Upgrade_flag
-    if [[ ! ${Upgrade_flag} =~ ^[1-8,q]$ ]]; then
-      echo "${CWARNING}input error! Please only input 1~8 and q${CEND}"
+    if [[ ! "${Upgrade_flag}" =~ ^[1-9,q]$|^10$ ]]; then
+      echo "${CWARNING}input error! Please only input 1~10 and q${CEND}"
     else
       case "${Upgrade_flag}" in
         1)
           [ -e "${nginx_install_dir}/sbin/nginx" ] && Upgrade_Nginx
           [ -e "${tengine_install_dir}/sbin/nginx" ] && Upgrade_Tengine
           [ -e "${openresty_install_dir}/nginx/sbin/nginx" ] && Upgrade_OpenResty
-          [ -e "${apache_install_dir}/conf/httpd.conf" ] && Upgrade_Apache
-          [ -e "${tomcat_install_dir}/conf/server.xml" ] && Upgrade_Tomcat
           ;;
         2)
-          Upgrade_DB
+          Upgrade_Apache
           ;;
         3)
-          Upgrade_PHP
+          Upgrade_Tomcat
           ;;
         4)
-          Upgrade_Redis
+          Upgrade_DB
           ;;
         5)
-          Upgrade_Memcached
+          Upgrade_PHP
           ;;
         6)
-          Upgrade_phpMyAdmin
+          Upgrade_Redis
           ;;
         7)
-          Upgrade_OneinStack
+          Upgrade_Memcached
           ;;
         8)
+          Upgrade_phpMyAdmin
+          ;;
+        9)
+          Upgrade_OneinStack
+          ;;
+        10)
           [ -e ~/.acme.sh/acme.sh ] && { ~/.acme.sh/acme.sh --upgrade; ~/.acme.sh/acme.sh --version; }
           ;;
         q)
@@ -112,57 +174,19 @@ What Are You Doing?
   done
 }
 
-if [ $# == 0 ]; then
+if [ ${ARG_NUM} == 0 ]; then
   Menu
-elif [ $# -ge 1 ] && [ $# -le 2 ]; then
-  case $1 in
-    web)
-      case $2 in
-        nginx)
-          Upgrade_Nginx
-          ;;
-        tengine)
-          Upgrade_Tengine
-          ;;
-        openresty)
-          Upgrade_OpenResty
-          ;;
-        apache)
-          Upgrade_Apache
-          ;;
-        tomcat)
-          Upgrade_Tomcat
-          ;;
-        *)
-          Usage
-          ;;
-      esac
-      ;;
-    db)
-      Upgrade_DB
-      ;;
-    php)
-      Upgrade_PHP
-      ;;
-    redis)
-      Upgrade_Redis
-      ;;
-    memcached)
-      Upgrade_Memcached
-      ;;
-    phpmyadmin)
-      Upgrade_phpMyAdmin
-      ;;
-    oneinstack)
-      Upgrade_OneinStack
-      ;;
-    acme.sh)
-      [ -e ~/.acme.sh/acme.sh ] && { ~/.acme.sh/acme.sh --upgrade; ~/.acme.sh/acme.sh --version; }
-      ;;
-    *)
-      Usage
-      ;;
-  esac
 else
-  Usage
+  [ "${nginx_quiet}" == 'y' ] && Upgrade_Nginx
+  [ "${tengine_quiet}" == 'y' ] && Upgrade_Tengine
+  [ "${openresty_quiet}" == 'y' ] && Upgrade_OpenResty
+  [ "${apache_quiet}" == 'y' ] && Upgrade_Apache
+  [ "${tomcat_quiet}" == 'y' ] && Upgrade_Tomcat
+  [ "${db_quiet}" == 'y' ] && Upgrade_DB
+  [ "${php_quiet}" == 'y' ] && Upgrade_PHP
+  [ "${redis_quiet}" == 'y' ] && Upgrade_Redis
+  [ "${memcached_quiet}" == 'y' ] && Upgrade_Memcached
+  [ "${phpmyadmin_quiet}" == 'y' ] && Upgrade_phpMyAdmin
+  [ "${NEW_oneinstack_ver}" == 'latest' ] && Upgrade_OneinStack
+  [ "${NEW_acme_ver}" == 'latest' ] && [ -e ~/.acme.sh/acme.sh ] && { ~/.acme.sh/acme.sh --upgrade; ~/.acme.sh/acme.sh --version; }
 fi

+ 4 - 4
versions.txt

@@ -25,12 +25,12 @@ mysql56_ver=5.6.42
 mysql55_ver=5.5.62
 
 mariadb103_ver=10.3.11
-mariadb102_ver=10.2.19
+mariadb102_ver=10.2.20
 mariadb101_ver=10.1.37
 mariadb100_ver=10.0.37
 mariadb55_ver=5.5.62
 
-percona57_ver=5.7.24-26
+percona57_ver=5.7.24-27
 percona56_ver=5.6.42-84.2
 percona55_ver=5.5.62-38.14
 
@@ -88,7 +88,7 @@ pecl_redis_ver=4.2.0
 memcached_ver=1.5.12
 libmemcached_ver=1.0.18
 pecl_memcached_ver=2.2.0
-pecl_memcached_php7_ver=3.1.2
+pecl_memcached_php7_ver=3.1.3
 pecl_memcache_ver=3.0.8
 
 # MongoDB
@@ -111,5 +111,5 @@ libevent_ver=2.0.22-stable
 tmux_ver=2.8
 htop_ver=2.2.0
 bison_ver=2.7.1
-python_ver=3.6.7
+python_ver=3.6.8
 fail2ban_ver=0.10.4