@cyysu
2017-10-07T08:32:00.000000Z
字数 26701
阅读 902
- 时间:2017年10月7日
- 作者:Kali
- 邮箱:cyysu.github.io@gmail.com
- 版本:3.0
- 描述:frp内网穿透自动安装
脚本编写
#! /bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATH#===============================================================================================# System Required: CentOS Debian or Ubuntu (32bit/64bit)# Description: A tool to auto-compile & install frps on Linux# Author: Clang# Intro: http://koolshare.cn/forum-72-1.html#===============================================================================================program_name="frps"version="1.6"str_program_dir="/usr/local/${program_name}"aliyun_download_url="https://code.aliyun.com/clangcn/frp/raw/master"github_download_url="https://github.com/fatedier/frp/releases/download"program_version="0.13.0"program_init="/etc/init.d/${program_name}"program_config_file="frps.ini"program_init_download_url=https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/frps.initstr_install_shell=https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.shshell_update(){fun_clangcn "clear"echo "Check updates for shell..."remote_shell_version=`wget --no-check-certificate -qO- ${str_install_shell} | sed -n '/'^version'/p' | cut -d\" -f2`if [ ! -z ${remote_shell_version} ]; thenif [[ "${version}" != "${remote_shell_version}" ]];thenecho -e "${COLOR_GREEN}Found a new version,update now!!!${COLOR_END}"echoecho -n "Update shell ..."if ! wget --no-check-certificate -qO $0 ${str_install_shell}; thenecho -e " [${COLOR_RED}failed${COLOR_END}]"echoexit 1elseecho -e " [${COLOR_GREEN}OK${COLOR_END}]"echoecho -e "${COLOR_GREEN}Please Re-run${COLOR_END} ${COLOR_PINK}$0 ${clang_action}${COLOR_END}"echoexit 1fiexit 1fifi}fun_clangcn(){local clear_flag=""clear_flag=$1if [[ ${clear_flag} == "clear" ]]; thenclearfiecho ""echo "+---------------------------------------------------------+"echo "| frps for Linux Server, Written by Clang |"echo "+---------------------------------------------------------+"echo "| A tool to auto-compile & install frps on Linux |"echo "+---------------------------------------------------------+"echo "| Intro: http://koolshare.cn/thread-65379-1-1.html |"echo "+---------------------------------------------------------+"echo ""}fun_set_text_color(){COLOR_RED='\E[1;31m'COLOR_GREEN='\E[1;32m'COLOR_YELOW='\E[1;33m'COLOR_BLUE='\E[1;34m'COLOR_PINK='\E[1;35m'COLOR_PINKBACK_WHITEFONT='\033[45;37m'COLOR_GREEN_LIGHTNING='\033[32m \033[05m'COLOR_END='\E[0m'}# Check if user is rootrootness(){if [[ $EUID -ne 0 ]]; thenfun_clangcnecho "Error:This script must be run as root!" 1>&2exit 1fi}get_char(){SAVEDSTTY=`stty -g`stty -echostty cbreakdd if=/dev/tty bs=1 count=1 2> /dev/nullstty -rawstty echostty $SAVEDSTTY}# Check OScheckos(){if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; thenOS=CentOSelif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; thenOS=Debianelif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; thenOS=Ubuntuelseecho "Not support OS, Please reinstall OS and retry!"exit 1fi}# Get versiongetversion(){if [[ -s /etc/redhat-release ]];thengrep -oE "[0-9.]+" /etc/redhat-releaseelsegrep -oE "[0-9.]+" /etc/issuefi}# CentOS versioncentosversion(){local code=$1local version="`getversion`"local main_ver=${version%%.*}if [ $main_ver == $code ];thenreturn 0elsereturn 1fi}# Check OS bitcheck_os_bit(){ARCHS=""if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; thenIs_64bit='y'ARCHS="amd64"elseIs_64bit='n'ARCHS="386"fi}check_centosversion(){if centosversion 5; thenecho "Not support CentOS 5.x, please change to CentOS 6,7 or Debian or Ubuntu and try again."exit 1fi}# Disable selinuxdisable_selinux(){if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; thensed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configsetenforce 0fi}pre_install_packs(){local wget_flag=''local killall_flag=''local netstat_flag=''wget --version > /dev/null 2>&1wget_flag=$?killall -V >/dev/null 2>&1killall_flag=$?netstat --version >/dev/null 2>&1netstat_flag=$?if [[ ${wget_flag} -gt 1 ]] || [[ ${killall_flag} -gt 1 ]] || [[ ${netstat_flag} -gt 6 ]];thenecho -e "${COLOR_GREEN} Install support packs...${COLOR_END}"if [ "${OS}" == 'CentOS' ]; thenyum install -y wget psmisc net-toolselseapt-get -y update && apt-get -y install wget psmisc net-toolsfifi}# Random passwordfun_randstr(){strNum=$1[ -z "${strNum}" ] && strNum="16"strRandomPass=""strRandomPass=`tr -cd '[:alnum:]' < /dev/urandom | fold -w ${strNum} | head -n1`echo ${strRandomPass}}fun_getServer(){def_server_url="aliyun"echo ""echo -e "Please select ${program_name} download url:"echo -e "[1].aliyun (default)"echo -e "[2].github"read -p "Enter your choice (1, 2 or exit. default [${def_server_url}]): " set_server_url[ -z "${set_server_url}" ] && set_server_url="${def_server_url}"case "${set_server_url}" in1|[Aa][Ll][Ii][Yy][Uu][Nn])program_download_url=${aliyun_download_url};;2|[Gg][Ii][Tt][Hh][Uu][Bb])program_download_url=${github_download_url};;[eE][xX][iI][tT])exit 1;;*)program_download_url=${aliyun_download_url};;esacecho "---------------------------------------"echo "Your select: ${set_server_url}"echo "---------------------------------------"}fun_getVer(){echo -e "Loading network version for ${program_name}, please wait..."program_latest_filename="frp_${program_version}_linux_${ARCHS}.tar.gz"program_latest_file_url="${program_download_url}/v${program_version}/${program_latest_filename}"if [ -z "${program_latest_filename}" ]; thenecho -e "${COLOR_RED}Load network version failed!!!${COLOR_END}"elseecho -e "${program_name} Latest release file ${COLOR_GREEN}${program_latest_filename}${COLOR_END}"fi}fun_download_file(){# downloadif [ ! -s ${str_program_dir}/${program_name} ]; thenrm -fr ${program_latest_filename} frp_${program_version}_linux_${ARCHS}if ! wget --no-check-certificate -q ${program_latest_file_url} -O ${program_latest_filename}; thenecho -e " ${COLOR_RED}failed${COLOR_END}"exit 1fitar xzf ${program_latest_filename}mv frp_${program_version}_linux_${ARCHS}/frps ${str_program_dir}/${program_name}rm -fr ${program_latest_filename} frp_${program_version}_linux_${ARCHS}fichown root:root -R ${str_program_dir}if [ -s ${str_program_dir}/${program_name} ]; then[ ! -x ${str_program_dir}/${program_name} ] && chmod 755 ${str_program_dir}/${program_name}elseecho -e " ${COLOR_RED}failed${COLOR_END}"exit 1fi}function __readINI() {INIFILE=$1; SECTION=$2; ITEM=$3_readIni=`awk -F '=' '/\['$SECTION'\]/{a=1}a==1&&$1~/'$ITEM'/{print $2;exit}' $INIFILE`echo ${_readIni}}# Check portfun_check_port(){port_flag=""strCheckPort=""input_port=""port_flag="$1"strCheckPort="$2"if [ ${strCheckPort} -ge 1 ] && [ ${strCheckPort} -le 65535 ]; thencheckServerPort=`netstat -ntulp | grep "\b:${strCheckPort}\b"`if [ -n "${checkServerPort}" ]; thenecho ""echo -e "${COLOR_RED}Error:${COLOR_END} Port ${COLOR_GREEN}${strCheckPort}${COLOR_END} is ${COLOR_PINK}used${COLOR_END},view relevant port:"netstat -ntulp | grep "\b:${strCheckPort}\b"fun_input_${port_flag}_portelseinput_port="${strCheckPort}"fielseecho "Input error! Please input correct numbers."fun_input_${port_flag}_portfi}fun_check_number(){num_flag=""strMaxNum=""strCheckNum=""input_number=""num_flag="$1"strMaxNum="$2"strCheckNum="$3"if [ ${strCheckNum} -ge 1 ] && [ ${strCheckNum} -le ${strMaxNum} ]; theninput_number="${strCheckNum}"elseecho "Input error! Please input correct numbers."fun_input_${num_flag}fi}# input portfun_input_bind_port(){def_server_port="5443"echo ""echo -n -e "Please input ${program_name} ${COLOR_GREEN}bind_port${COLOR_END} [1-65535]"read -p "(Default Server Port: ${def_server_port}):" serverport[ -z "${serverport}" ] && serverport="${def_server_port}"fun_check_port "bind" "${serverport}"}fun_input_dashboard_port(){def_dashboard_port="6443"echo ""echo -n -e "Please input ${program_name} ${COLOR_GREEN}dashboard_port${COLOR_END} [1-65535]"read -p "(Default dashboard_port: ${def_dashboard_port}):" input_dashboard_port[ -z "${input_dashboard_port}" ] && input_dashboard_port="${def_dashboard_port}"fun_check_port "dashboard" "${input_dashboard_port}"}fun_input_vhost_http_port(){def_vhost_http_port="80"echo ""echo -n -e "Please input ${program_name} ${COLOR_GREEN}vhost_http_port${COLOR_END} [1-65535]"read -p "(Default vhost_http_port: ${def_vhost_http_port}):" input_vhost_http_port[ -z "${input_vhost_http_port}" ] && input_vhost_http_port="${def_vhost_http_port}"fun_check_port "vhost_http" "${input_vhost_http_port}"}fun_input_vhost_https_port(){def_vhost_https_port="443"echo ""echo -n -e "Please input ${program_name} ${COLOR_GREEN}vhost_https_port${COLOR_END} [1-65535]"read -p "(Default vhost_https_port: ${def_vhost_https_port}):" input_vhost_https_port[ -z "${input_vhost_https_port}" ] && input_vhost_https_port="${def_vhost_https_port}"fun_check_port "vhost_https" "${input_vhost_https_port}"}fun_input_log_max_days(){def_max_days="30"def_log_max_days="3"echo ""echo -e "Please input ${program_name} ${COLOR_GREEN}log_max_days${COLOR_END} [1-${def_max_days}]"read -p "(Default log_max_days: ${def_log_max_days} day):" input_log_max_days[ -z "${input_log_max_days}" ] && input_log_max_days="${def_log_max_days}"fun_check_number "log_max_days" "${def_max_days}" "${input_log_max_days}"}fun_input_max_pool_count(){def_max_pool="200"def_max_pool_count="50"echo ""echo -e "Please input ${program_name} ${COLOR_GREEN}max_pool_count${COLOR_END} [1-${def_max_pool}]"read -p "(Default max_pool_count: ${def_max_pool_count}):" input_max_pool_count[ -z "${input_max_pool_count}" ] && input_max_pool_count="${def_max_pool_count}"fun_check_number "max_pool_count" "${def_max_pool}" "${input_max_pool_count}"}pre_install_clang(){fun_clangcnecho -e "Check your server setting, please wait..."disable_selinuxif [ -s ${str_program_dir}/${program_name} ] && [ -s ${program_init} ]; thenecho "${program_name} is installed!"elseclearfun_clangcnfun_getServerfun_getVerecho -e "Loading You Server IP, please wait..."defIP=$(wget -qO- ip.clang.cn | sed -r 's/\r//')echo -e "You Server IP:${COLOR_GREEN}${defIP}${COLOR_END}"echo -e "${COLOR_YELOW}Please input your server setting:${COLOR_END}"fun_input_bind_port[ -n "${input_port}" ] && set_bind_port="${input_port}"echo "${program_name} bind_port: ${set_bind_port}"echo ""fun_input_vhost_http_port[ -n "${input_port}" ] && set_vhost_http_port="${input_port}"echo "${program_name} vhost_http_port: ${set_vhost_http_port}"echo ""fun_input_vhost_https_port[ -n "${input_port}" ] && set_vhost_https_port="${input_port}"echo "${program_name} vhost_https_port: ${set_vhost_https_port}"echo ""fun_input_dashboard_port[ -n "${input_port}" ] && set_dashboard_port="${input_port}"echo "${program_name} dashboard_port: ${set_dashboard_port}"echo ""def_dashboard_user="admin"read -p "Please input dashboard_user (Default: ${def_dashboard_user}):" set_dashboard_user[ -z "${set_dashboard_user}" ] && set_dashboard_user="${def_dashboard_user}"echo "${program_name} dashboard_user: ${set_dashboard_user}"echo ""def_dashboard_pwd=`fun_randstr 8`read -p "Please input dashboard_pwd (Default: ${def_dashboard_pwd}):" set_dashboard_pwd[ -z "${set_dashboard_pwd}" ] && set_dashboard_pwd="${def_dashboard_pwd}"echo "${program_name} dashboard_pwd: ${set_dashboard_pwd}"echo ""default_privilege_token=`fun_randstr 16`read -p "Please input privilege_token (Default: ${default_privilege_token}):" set_privilege_token[ -z "${set_privilege_token}" ] && set_privilege_token="${default_privilege_token}"echo "${program_name} privilege_token: ${set_privilege_token}"echo ""fun_input_max_pool_count[ -n "${input_number}" ] && set_max_pool_count="${input_number}"echo "${program_name} max_pool_count: ${set_max_pool_count}"echo ""echo "##### Please select log_level #####"echo "1: info (default)"echo "2: warn"echo "3: error"echo "4: debug"echo "#####################################################"read -p "Enter your choice (1, 2, 3, 4 or exit. default [1]): " str_log_levelcase "${str_log_level}" in1|[Ii][Nn][Ff][Oo])str_log_level="info";;2|[Ww][Aa][Rr][Nn])str_log_level="warn";;3|[Ee][Rr][Rr][Oo][Rr])str_log_level="error";;4|[Dd][Ee][Bb][Uu][Gg])str_log_level="debug";;[eE][xX][iI][tT])exit 1;;*)str_log_level="info";;esacecho "log_level: ${str_log_level}"echo ""fun_input_log_max_days[ -n "${input_number}" ] && set_log_max_days="${input_number}"echo "${program_name} log_max_days: ${set_log_max_days}"echo ""echo "##### Please select log_file #####"echo "1: enable (default)"echo "2: disable"echo "#####################################################"read -p "Enter your choice (1, 2 or exit. default [1]): " str_log_filecase "${str_log_file}" in1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])str_log_file="./frps.log"str_log_file_flag="enable";;0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])str_log_file="/dev/null"str_log_file_flag="disable";;[eE][xX][iI][tT])exit 1;;*)str_log_file="./frps.log"str_log_file_flag="enable";;esacecho "log_file: ${str_log_file_flag}"echo ""echo "##### Please select tcp_mux #####"echo "1: enable (default)"echo "2: disable"echo "#####################################################"read -p "Enter your choice (1, 2 or exit. default [1]): " str_tcp_muxcase "${str_tcp_mux}" in1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])set_tcp_mux="true";;0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])set_tcp_mux="false";;[eE][xX][iI][tT])exit 1;;*)set_tcp_mux="true";;esacecho "tcp_mux: ${set_tcp_mux}"echo ""echo "##### Please select kcp support #####"echo "1: enable (default)"echo "2: disable"echo "#####################################################"read -p "Enter your choice (1, 2 or exit. default [1]): " str_kcpcase "${str_kcp}" in1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])set_kcp="true";;0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])set_kcp="false";;[eE][xX][iI][tT])exit 1;;*)set_kcp="true";;esacecho "kcp support: ${set_kcp}"echo ""echo "============== Check your input =============="echo -e "You Server IP : ${COLOR_GREEN}${defIP}${COLOR_END}"echo -e "Bind port : ${COLOR_GREEN}${set_bind_port}${COLOR_END}"echo -e "kcp support : ${COLOR_GREEN}${set_kcp}${COLOR_END}"echo -e "vhost http port : ${COLOR_GREEN}${set_vhost_http_port}${COLOR_END}"echo -e "vhost https port : ${COLOR_GREEN}${set_vhost_https_port}${COLOR_END}"echo -e "Dashboard port : ${COLOR_GREEN}${set_dashboard_port}${COLOR_END}"echo -e "Dashboard user : ${COLOR_GREEN}${set_dashboard_user}${COLOR_END}"echo -e "Dashboard password : ${COLOR_GREEN}${set_dashboard_pwd}${COLOR_END}"echo -e "Privilege token : ${COLOR_GREEN}${set_privilege_token}${COLOR_END}"echo -e "tcp_mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"echo -e "Max Pool count : ${COLOR_GREEN}${set_max_pool_count}${COLOR_END}"echo -e "Log level : ${COLOR_GREEN}${str_log_level}${COLOR_END}"echo -e "Log max days : ${COLOR_GREEN}${set_log_max_days}${COLOR_END}"echo -e "Log file : ${COLOR_GREEN}${str_log_file_flag}${COLOR_END}"echo "=============================================="echo ""echo "Press any key to start...or Press Ctrl+c to cancel"char=`get_char`install_program_server_clangfi}# ====== install server ======install_program_server_clang(){[ ! -d ${str_program_dir} ] && mkdir -p ${str_program_dir}cd ${str_program_dir}echo "${program_name} install path:$PWD"echo -n "config file for ${program_name} ..."# Config fileif [[ "${set_kcp}" == "false" ]]; thencat > ${str_program_dir}/${program_config_file}<<-EOF# [common] is integral section[common]# A literal address or host name for IPv6 must be enclosed# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"bind_addr = 0.0.0.0bind_port = ${set_bind_port}# udp port used for kcp protocol, it can be same with 'bind_port'# if not set, kcp is disabled in frps#kcp_bind_port = ${set_bind_port}# if you want to configure or reload frps by dashboard, dashboard_port must be setdashboard_port = ${set_dashboard_port}# dashboard assets directory(only for debug mode)dashboard_user = ${set_dashboard_user}dashboard_pwd = ${set_dashboard_pwd}# assets_dir = ./staticvhost_http_port = ${set_vhost_http_port}vhost_https_port = ${set_vhost_https_port}# console or real logFile path like ./frps.loglog_file = ${str_log_file}# debug, info, warn, errorlog_level = ${str_log_level}log_max_days = ${set_log_max_days}# privilege mode is the only supported mode since v0.10.0privilege_token = ${set_privilege_token}# only allow frpc to bind ports you list, if you set nothing, there won't be any limit#privilege_allow_ports = 1-65535# pool_count in each proxy will change to max_pool_count if they exceed the maximum valuemax_pool_count = ${set_max_pool_count}# if tcp stream multiplexing is used, default is truetcp_mux = ${set_tcp_mux}EOFelsecat > ${str_program_dir}/${program_config_file}<<-EOF# [common] is integral section[common]# A literal address or host name for IPv6 must be enclosed# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"bind_addr = 0.0.0.0bind_port = ${set_bind_port}# udp port used for kcp protocol, it can be same with 'bind_port'# if not set, kcp is disabled in frpskcp_bind_port = ${set_bind_port}# if you want to configure or reload frps by dashboard, dashboard_port must be setdashboard_port = ${set_dashboard_port}# dashboard assets directory(only for debug mode)dashboard_user = ${set_dashboard_user}dashboard_pwd = ${set_dashboard_pwd}# assets_dir = ./staticvhost_http_port = ${set_vhost_http_port}vhost_https_port = ${set_vhost_https_port}# console or real logFile path like ./frps.loglog_file = ${str_log_file}# debug, info, warn, errorlog_level = ${str_log_level}log_max_days = ${set_log_max_days}# privilege mode is the only supported mode since v0.10.0privilege_token = ${set_privilege_token}# only allow frpc to bind ports you list, if you set nothing, there won't be any limit#privilege_allow_ports = 1-65535# pool_count in each proxy will change to max_pool_count if they exceed the maximum valuemax_pool_count = ${set_max_pool_count}# if tcp stream multiplexing is used, default is truetcp_mux = ${set_tcp_mux}EOFfiecho " done"echo -n "download ${program_name} ..."rm -f ${str_program_dir}/${program_name} ${program_init}fun_download_fileecho " done"echo -n "download ${program_init}..."if [ ! -s ${program_init} ]; thenif ! wget --no-check-certificate -q ${program_init_download_url} -O ${program_init}; thenecho -e " ${COLOR_RED}failed${COLOR_END}"exit 1fifi[ ! -x ${program_init} ] && chmod +x ${program_init}echo " done"echo -n "setting ${program_name} boot..."[ ! -x ${program_init} ] && chmod +x ${program_init}if [ "${OS}" == 'CentOS' ]; thenchmod +x ${program_init}chkconfig --add ${program_name}elsechmod +x ${program_init}update-rc.d -f ${program_name} defaultsfiecho " done"[ -s ${program_init} ] && ln -s ${program_init} /usr/bin/${program_name}${program_init} startfun_clangcn#install successfullyecho ""echo "Congratulations, ${program_name} install completed!"echo "=============================================="echo -e "You Server IP : ${COLOR_GREEN}${defIP}${COLOR_END}"echo -e "Bind port : ${COLOR_GREEN}${set_bind_port}${COLOR_END}"echo -e "KCP support : ${COLOR_GREEN}${set_kcp}${COLOR_END}"echo -e "vhost http port : ${COLOR_GREEN}${set_vhost_http_port}${COLOR_END}"echo -e "vhost https port : ${COLOR_GREEN}${set_vhost_https_port}${COLOR_END}"echo -e "Dashboard port : ${COLOR_GREEN}${set_dashboard_port}${COLOR_END}"echo -e "Privilege token : ${COLOR_GREEN}${set_privilege_token}${COLOR_END}"echo -e "tcp_mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"echo -e "Max Pool count : ${COLOR_GREEN}${set_max_pool_count}${COLOR_END}"echo -e "Log level : ${COLOR_GREEN}${str_log_level}${COLOR_END}"echo -e "Log max days : ${COLOR_GREEN}${set_log_max_days}${COLOR_END}"echo -e "Log file : ${COLOR_GREEN}${str_log_file_flag}${COLOR_END}"echo "=============================================="echo -e "${program_name} Dashboard : ${COLOR_GREEN}http://${defIP}:${set_dashboard_port}/${COLOR_END}"echo -e "Dashboard user : ${COLOR_GREEN}${set_dashboard_user}${COLOR_END}"echo -e "Dashboard password : ${COLOR_GREEN}${set_dashboard_pwd}${COLOR_END}"echo "=============================================="echo ""echo -e "${program_name} status manage : ${COLOR_PINKBACK_WHITEFONT}${program_name}${COLOR_END} {${COLOR_GREEN}start|stop|restart|status|config|version${COLOR_END}}"echo -e "Example:"echo -e " start: ${COLOR_PINK}${program_name}${COLOR_END} ${COLOR_GREEN}start${COLOR_END}"echo -e " stop: ${COLOR_PINK}${program_name}${COLOR_END} ${COLOR_GREEN}stop${COLOR_END}"echo -e "restart: ${COLOR_PINK}${program_name}${COLOR_END} ${COLOR_GREEN}restart${COLOR_END}"exit 0}############################### configure ##################################configure_program_server_clang(){if [ -s ${str_program_dir}/${program_config_file} ]; thenvi ${str_program_dir}/${program_config_file}elseecho "${program_name} configuration file not found!"exit 1fi}############################### uninstall ##################################uninstall_program_server_clang(){fun_clangcnif [ -s ${program_init} ] || [ -s ${str_program_dir}/${program_name} ] ; thenecho "============== Uninstall ${program_name} =============="str_uninstall="n"echo -n -e "${COLOR_YELOW}You want to uninstall?${COLOR_END}"read -p "[y/N]:" str_uninstallcase "${str_uninstall}" in[yY]|[yY][eE][sS])echo ""echo "You select [Yes], press any key to continue."str_uninstall="y"char=`get_char`;;*)echo ""str_uninstall="n"esacif [ "${str_uninstall}" == 'n' ]; thenecho "You select [No],shell exit!"elsecheckos${program_init} stopif [ "${OS}" == 'CentOS' ]; thenchkconfig --del ${program_name}elseupdate-rc.d -f ${program_name} removefirm -f ${program_init} /var/run/${program_name}.pid /usr/bin/${program_name}rm -fr ${str_program_dir}echo "${program_name} uninstall success!"fielseecho "${program_name} Not install!"fiexit 0}############################### update ##################################update_config_clang(){if [ ! -r "${str_program_dir}/${program_config_file}" ]; thenecho "config file ${str_program_dir}/${program_config_file} not found."elsesearch_dashboard_user=`grep "dashboard_user" ${str_program_dir}/${program_config_file}`search_dashboard_pwd=`grep "dashboard_pwd" ${str_program_dir}/${program_config_file}`search_kcp_bind_port=`grep "kcp_bind_port" ${str_program_dir}/${program_config_file}`search_tcp_mux=`grep "tcp_mux" ${str_program_dir}/${program_config_file}`if [ -z "${search_dashboard_user}" ] || [ -z "${search_dashboard_pwd}" ] || [ -z "${search_kcp_bind_port}" ] || [ -z "${search_tcp_mux}" ];thenecho -e "${COLOR_GREEN}Configuration files need to be updated, now setting:${COLOR_END}"echo ""if [ -z "${search_dashboard_user}" ] && [ -z "${search_dashboard_pwd}" ];thendef_dashboard_user_update="admin"read -p "Please input dashboard_user (Default: ${def_dashboard_user_update}):" set_dashboard_user_update[ -z "${set_dashboard_user_update}" ] && set_dashboard_user_update="${def_dashboard_user_update}"echo "${program_name} dashboard_user: ${set_dashboard_user_update}"echo ""def_dashboard_pwd_update=`fun_randstr 8`read -p "Please input dashboard_pwd (Default: ${def_dashboard_pwd_update}):" set_dashboard_pwd_update[ -z "${set_dashboard_pwd_update}" ] && set_dashboard_pwd_update="${def_dashboard_pwd_update}"echo "${program_name} dashboard_pwd: ${set_dashboard_pwd_update}"echo ""sed -i "/dashboard_port =.*/a\dashboard_user = ${set_dashboard_user_update}\ndashboard_pwd = ${set_dashboard_pwd_update}\n" ${str_program_dir}/${program_config_file}fiif [ -z "${search_kcp_bind_port}" ];thenecho "##### Please select kcp support #####"echo "1: enable (default)"echo "2: disable"echo "#####################################################"read -p "Enter your choice (1, 2 or exit. default [1]): " str_kcpcase "${str_kcp}" in1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])set_kcp="true";;0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])set_kcp="false";;[eE][xX][iI][tT])exit 1;;*)set_kcp="true";;esacecho "kcp support: ${set_kcp}"def_kcp_bind_port=( $( __readINI ${str_program_dir}/${program_config_file} common bind_port ) )if [[ "${set_kcp}" == "false" ]]; thensed -i "/^bind_port =.*/a\# udp port used for kcp protocol, it can be same with 'bind_port'\n# if not set, kcp is disabled in frps\n#kcp_bind_port = ${def_kcp_bind_port}\n" ${str_program_dir}/${program_config_file}elsesed -i "/^bind_port =.*/a\# udp port used for kcp protocol, it can be same with 'bind_port'\n# if not set, kcp is disabled in frps\nkcp_bind_port = ${def_kcp_bind_port}\n" ${str_program_dir}/${program_config_file}fifiif [ -z "${search_tcp_mux}" ];thenecho "##### Please select tcp_mux #####"echo "1: enable (default)"echo "2: disable"echo "#####################################################"read -p "Enter your choice (1, 2 or exit. default [1]): " str_tcp_muxcase "${str_tcp_mux}" in1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])set_tcp_mux="true";;0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])set_tcp_mux="false";;[eE][xX][iI][tT])exit 1;;*)set_tcp_mux="true";;esacecho "tcp_mux: ${set_tcp_mux}"sed -i "/^privilege_mode = true/d" ${str_program_dir}/${program_config_file}sed -i "/^privilege_token =.*/a\# if tcp stream multiplexing is used, default is true\ntcp_mux = ${set_tcp_mux}\n" ${str_program_dir}/${program_config_file}fifiverify_dashboard_user=`grep "^dashboard_user" ${str_program_dir}/${program_config_file}`verify_dashboard_pwd=`grep "^dashboard_pwd" ${str_program_dir}/${program_config_file}`verify_kcp_bind_port=`grep "kcp_bind_port" ${str_program_dir}/${program_config_file}`verify_tcp_mux=`grep "^tcp_mux" ${str_program_dir}/${program_config_file}`if [ ! -z "${verify_dashboard_user}" ] && [ ! -z "${verify_dashboard_pwd}" ] && [ ! -z "${verify_kcp_bind_port}" ] && [ ! -z "${verify_tcp_mux}" ];thenecho -e "${COLOR_GREEN}update configuration file successfully!!!${COLOR_END}"elseecho -e "${COLOR_RED}update configuration file error!!!${COLOR_END}"fifi}update_program_server_clang(){fun_clangcn "clear"if [ -s ${program_init} ] || [ -s ${str_program_dir}/${program_name} ] ; thenecho "============== Update ${program_name} =============="update_config_clangcheckoscheck_centosversioncheck_os_bitremote_init_version=`wget --no-check-certificate -qO- ${program_init_download_url} | sed -n '/'^version'/p' | cut -d\" -f2`local_init_version=`sed -n '/'^version'/p' ${program_init} | cut -d\" -f2`install_shell=${strPath}if [ ! -z ${remote_init_version} ];thenif [[ "${local_init_version}" != "${remote_init_version}" ]];thenecho "========== Update ${program_name} ${program_init} =========="if ! wget --no-check-certificate ${program_init_download_url} -O ${program_init}; thenecho "Failed to download ${program_name}.init file!"exit 1elseecho -e "${COLOR_GREEN}${program_init} Update successfully !!!${COLOR_END}"fififi[ ! -d ${str_program_dir} ] && mkdir -p ${str_program_dir}echo -e "Loading network version for ${program_name}, please wait..."fun_getServerfun_getVer >/dev/null 2>&1local_program_version=`${str_program_dir}/${program_name} --version`echo -e "${COLOR_GREEN}${program_name} local version ${local_program_version}${COLOR_END}"echo -e "${COLOR_GREEN}${program_name} remote version ${program_version}${COLOR_END}"if [[ "${local_program_version}" != "${program_version}" ]];thenecho -e "${COLOR_GREEN}Found a new version,update now!!!${COLOR_END}"${program_init} stopsleep 1rm -f /usr/bin/${program_name} ${str_program_dir}/${program_name}fun_download_fileif [ "${OS}" == 'CentOS' ]; thenchmod +x ${program_init}chkconfig --add ${program_name}elsechmod +x ${program_init}update-rc.d -f ${program_name} defaultsfi[ -s ${program_init} ] && ln -s ${program_init} /usr/bin/${program_name}[ ! -x ${program_init} ] && chmod 755 ${program_init}${program_init} startecho "${program_name} version `${str_program_dir}/${program_name} --version`"echo "${program_name} update success!"elseecho -e "no need to update !!!${COLOR_END}"fielseecho "${program_name} Not install!"fiexit 0}clearstrPath=`pwd`rootnessfun_set_text_colorcheckoscheck_centosversioncheck_os_bitpre_install_packsshell_update# Initializationaction=$1[ -z $1 ]case "$action" ininstall)pre_install_clang 2>&1 | tee /root/${program_name}-install.log;;config)configure_program_server_clang;;uninstall)uninstall_program_server_clang 2>&1 | tee /root/${program_name}-uninstall.log;;update)update_program_server_clang 2>&1 | tee /root/${program_name}-update.log;;*)fun_clangcnecho "Arguments error! [${action} ]"echo "Usage: `basename $0` {install|uninstall|update|config}"RET_VAL=1;;esac
支付宝 微信