[关闭]
@cyysu 2017-10-07T08:32:00.000000Z 字数 26701 阅读 831

frp自动安装脚本

  • 时间:2017年10月7日
  • 作者:Kali
  • 邮箱:cyysu.github.io@gmail.com
  • 版本:3.0
  • 描述:frp内网穿透自动安装

脚本编写


脚本内容

  1. #! /bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. #===============================================================================================
  5. # System Required: CentOS Debian or Ubuntu (32bit/64bit)
  6. # Description: A tool to auto-compile & install frps on Linux
  7. # Author: Clang
  8. # Intro: http://koolshare.cn/forum-72-1.html
  9. #===============================================================================================
  10. program_name="frps"
  11. version="1.6"
  12. str_program_dir="/usr/local/${program_name}"
  13. aliyun_download_url="https://code.aliyun.com/clangcn/frp/raw/master"
  14. github_download_url="https://github.com/fatedier/frp/releases/download"
  15. program_version="0.13.0"
  16. program_init="/etc/init.d/${program_name}"
  17. program_config_file="frps.ini"
  18. program_init_download_url=https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/frps.init
  19. str_install_shell=https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh
  20. shell_update(){
  21. fun_clangcn "clear"
  22. echo "Check updates for shell..."
  23. remote_shell_version=`wget --no-check-certificate -qO- ${str_install_shell} | sed -n '/'^version'/p' | cut -d\" -f2`
  24. if [ ! -z ${remote_shell_version} ]; then
  25. if [[ "${version}" != "${remote_shell_version}" ]];then
  26. echo -e "${COLOR_GREEN}Found a new version,update now!!!${COLOR_END}"
  27. echo
  28. echo -n "Update shell ..."
  29. if ! wget --no-check-certificate -qO $0 ${str_install_shell}; then
  30. echo -e " [${COLOR_RED}failed${COLOR_END}]"
  31. echo
  32. exit 1
  33. else
  34. echo -e " [${COLOR_GREEN}OK${COLOR_END}]"
  35. echo
  36. echo -e "${COLOR_GREEN}Please Re-run${COLOR_END} ${COLOR_PINK}$0 ${clang_action}${COLOR_END}"
  37. echo
  38. exit 1
  39. fi
  40. exit 1
  41. fi
  42. fi
  43. }
  44. fun_clangcn(){
  45. local clear_flag=""
  46. clear_flag=$1
  47. if [[ ${clear_flag} == "clear" ]]; then
  48. clear
  49. fi
  50. echo ""
  51. echo "+---------------------------------------------------------+"
  52. echo "| frps for Linux Server, Written by Clang |"
  53. echo "+---------------------------------------------------------+"
  54. echo "| A tool to auto-compile & install frps on Linux |"
  55. echo "+---------------------------------------------------------+"
  56. echo "| Intro: http://koolshare.cn/thread-65379-1-1.html |"
  57. echo "+---------------------------------------------------------+"
  58. echo ""
  59. }
  60. fun_set_text_color(){
  61. COLOR_RED='\E[1;31m'
  62. COLOR_GREEN='\E[1;32m'
  63. COLOR_YELOW='\E[1;33m'
  64. COLOR_BLUE='\E[1;34m'
  65. COLOR_PINK='\E[1;35m'
  66. COLOR_PINKBACK_WHITEFONT='\033[45;37m'
  67. COLOR_GREEN_LIGHTNING='\033[32m \033[05m'
  68. COLOR_END='\E[0m'
  69. }
  70. # Check if user is root
  71. rootness(){
  72. if [[ $EUID -ne 0 ]]; then
  73. fun_clangcn
  74. echo "Error:This script must be run as root!" 1>&2
  75. exit 1
  76. fi
  77. }
  78. get_char(){
  79. SAVEDSTTY=`stty -g`
  80. stty -echo
  81. stty cbreak
  82. dd if=/dev/tty bs=1 count=1 2> /dev/null
  83. stty -raw
  84. stty echo
  85. stty $SAVEDSTTY
  86. }
  87. # Check OS
  88. checkos(){
  89. if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
  90. OS=CentOS
  91. elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
  92. OS=Debian
  93. elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
  94. OS=Ubuntu
  95. else
  96. echo "Not support OS, Please reinstall OS and retry!"
  97. exit 1
  98. fi
  99. }
  100. # Get version
  101. getversion(){
  102. if [[ -s /etc/redhat-release ]];then
  103. grep -oE "[0-9.]+" /etc/redhat-release
  104. else
  105. grep -oE "[0-9.]+" /etc/issue
  106. fi
  107. }
  108. # CentOS version
  109. centosversion(){
  110. local code=$1
  111. local version="`getversion`"
  112. local main_ver=${version%%.*}
  113. if [ $main_ver == $code ];then
  114. return 0
  115. else
  116. return 1
  117. fi
  118. }
  119. # Check OS bit
  120. check_os_bit(){
  121. ARCHS=""
  122. if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then
  123. Is_64bit='y'
  124. ARCHS="amd64"
  125. else
  126. Is_64bit='n'
  127. ARCHS="386"
  128. fi
  129. }
  130. check_centosversion(){
  131. if centosversion 5; then
  132. echo "Not support CentOS 5.x, please change to CentOS 6,7 or Debian or Ubuntu and try again."
  133. exit 1
  134. fi
  135. }
  136. # Disable selinux
  137. disable_selinux(){
  138. if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
  139. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  140. setenforce 0
  141. fi
  142. }
  143. pre_install_packs(){
  144. local wget_flag=''
  145. local killall_flag=''
  146. local netstat_flag=''
  147. wget --version > /dev/null 2>&1
  148. wget_flag=$?
  149. killall -V >/dev/null 2>&1
  150. killall_flag=$?
  151. netstat --version >/dev/null 2>&1
  152. netstat_flag=$?
  153. if [[ ${wget_flag} -gt 1 ]] || [[ ${killall_flag} -gt 1 ]] || [[ ${netstat_flag} -gt 6 ]];then
  154. echo -e "${COLOR_GREEN} Install support packs...${COLOR_END}"
  155. if [ "${OS}" == 'CentOS' ]; then
  156. yum install -y wget psmisc net-tools
  157. else
  158. apt-get -y update && apt-get -y install wget psmisc net-tools
  159. fi
  160. fi
  161. }
  162. # Random password
  163. fun_randstr(){
  164. strNum=$1
  165. [ -z "${strNum}" ] && strNum="16"
  166. strRandomPass=""
  167. strRandomPass=`tr -cd '[:alnum:]' < /dev/urandom | fold -w ${strNum} | head -n1`
  168. echo ${strRandomPass}
  169. }
  170. fun_getServer(){
  171. def_server_url="aliyun"
  172. echo ""
  173. echo -e "Please select ${program_name} download url:"
  174. echo -e "[1].aliyun (default)"
  175. echo -e "[2].github"
  176. read -p "Enter your choice (1, 2 or exit. default [${def_server_url}]): " set_server_url
  177. [ -z "${set_server_url}" ] && set_server_url="${def_server_url}"
  178. case "${set_server_url}" in
  179. 1|[Aa][Ll][Ii][Yy][Uu][Nn])
  180. program_download_url=${aliyun_download_url}
  181. ;;
  182. 2|[Gg][Ii][Tt][Hh][Uu][Bb])
  183. program_download_url=${github_download_url}
  184. ;;
  185. [eE][xX][iI][tT])
  186. exit 1
  187. ;;
  188. *)
  189. program_download_url=${aliyun_download_url}
  190. ;;
  191. esac
  192. echo "---------------------------------------"
  193. echo "Your select: ${set_server_url}"
  194. echo "---------------------------------------"
  195. }
  196. fun_getVer(){
  197. echo -e "Loading network version for ${program_name}, please wait..."
  198. program_latest_filename="frp_${program_version}_linux_${ARCHS}.tar.gz"
  199. program_latest_file_url="${program_download_url}/v${program_version}/${program_latest_filename}"
  200. if [ -z "${program_latest_filename}" ]; then
  201. echo -e "${COLOR_RED}Load network version failed!!!${COLOR_END}"
  202. else
  203. echo -e "${program_name} Latest release file ${COLOR_GREEN}${program_latest_filename}${COLOR_END}"
  204. fi
  205. }
  206. fun_download_file(){
  207. # download
  208. if [ ! -s ${str_program_dir}/${program_name} ]; then
  209. rm -fr ${program_latest_filename} frp_${program_version}_linux_${ARCHS}
  210. if ! wget --no-check-certificate -q ${program_latest_file_url} -O ${program_latest_filename}; then
  211. echo -e " ${COLOR_RED}failed${COLOR_END}"
  212. exit 1
  213. fi
  214. tar xzf ${program_latest_filename}
  215. mv frp_${program_version}_linux_${ARCHS}/frps ${str_program_dir}/${program_name}
  216. rm -fr ${program_latest_filename} frp_${program_version}_linux_${ARCHS}
  217. fi
  218. chown root:root -R ${str_program_dir}
  219. if [ -s ${str_program_dir}/${program_name} ]; then
  220. [ ! -x ${str_program_dir}/${program_name} ] && chmod 755 ${str_program_dir}/${program_name}
  221. else
  222. echo -e " ${COLOR_RED}failed${COLOR_END}"
  223. exit 1
  224. fi
  225. }
  226. function __readINI() {
  227. INIFILE=$1; SECTION=$2; ITEM=$3
  228. _readIni=`awk -F '=' '/\['$SECTION'\]/{a=1}a==1&&$1~/'$ITEM'/{print $2;exit}' $INIFILE`
  229. echo ${_readIni}
  230. }
  231. # Check port
  232. fun_check_port(){
  233. port_flag=""
  234. strCheckPort=""
  235. input_port=""
  236. port_flag="$1"
  237. strCheckPort="$2"
  238. if [ ${strCheckPort} -ge 1 ] && [ ${strCheckPort} -le 65535 ]; then
  239. checkServerPort=`netstat -ntulp | grep "\b:${strCheckPort}\b"`
  240. if [ -n "${checkServerPort}" ]; then
  241. echo ""
  242. echo -e "${COLOR_RED}Error:${COLOR_END} Port ${COLOR_GREEN}${strCheckPort}${COLOR_END} is ${COLOR_PINK}used${COLOR_END},view relevant port:"
  243. netstat -ntulp | grep "\b:${strCheckPort}\b"
  244. fun_input_${port_flag}_port
  245. else
  246. input_port="${strCheckPort}"
  247. fi
  248. else
  249. echo "Input error! Please input correct numbers."
  250. fun_input_${port_flag}_port
  251. fi
  252. }
  253. fun_check_number(){
  254. num_flag=""
  255. strMaxNum=""
  256. strCheckNum=""
  257. input_number=""
  258. num_flag="$1"
  259. strMaxNum="$2"
  260. strCheckNum="$3"
  261. if [ ${strCheckNum} -ge 1 ] && [ ${strCheckNum} -le ${strMaxNum} ]; then
  262. input_number="${strCheckNum}"
  263. else
  264. echo "Input error! Please input correct numbers."
  265. fun_input_${num_flag}
  266. fi
  267. }
  268. # input port
  269. fun_input_bind_port(){
  270. def_server_port="5443"
  271. echo ""
  272. echo -n -e "Please input ${program_name} ${COLOR_GREEN}bind_port${COLOR_END} [1-65535]"
  273. read -p "(Default Server Port: ${def_server_port}):" serverport
  274. [ -z "${serverport}" ] && serverport="${def_server_port}"
  275. fun_check_port "bind" "${serverport}"
  276. }
  277. fun_input_dashboard_port(){
  278. def_dashboard_port="6443"
  279. echo ""
  280. echo -n -e "Please input ${program_name} ${COLOR_GREEN}dashboard_port${COLOR_END} [1-65535]"
  281. read -p "(Default dashboard_port: ${def_dashboard_port}):" input_dashboard_port
  282. [ -z "${input_dashboard_port}" ] && input_dashboard_port="${def_dashboard_port}"
  283. fun_check_port "dashboard" "${input_dashboard_port}"
  284. }
  285. fun_input_vhost_http_port(){
  286. def_vhost_http_port="80"
  287. echo ""
  288. echo -n -e "Please input ${program_name} ${COLOR_GREEN}vhost_http_port${COLOR_END} [1-65535]"
  289. read -p "(Default vhost_http_port: ${def_vhost_http_port}):" input_vhost_http_port
  290. [ -z "${input_vhost_http_port}" ] && input_vhost_http_port="${def_vhost_http_port}"
  291. fun_check_port "vhost_http" "${input_vhost_http_port}"
  292. }
  293. fun_input_vhost_https_port(){
  294. def_vhost_https_port="443"
  295. echo ""
  296. echo -n -e "Please input ${program_name} ${COLOR_GREEN}vhost_https_port${COLOR_END} [1-65535]"
  297. read -p "(Default vhost_https_port: ${def_vhost_https_port}):" input_vhost_https_port
  298. [ -z "${input_vhost_https_port}" ] && input_vhost_https_port="${def_vhost_https_port}"
  299. fun_check_port "vhost_https" "${input_vhost_https_port}"
  300. }
  301. fun_input_log_max_days(){
  302. def_max_days="30"
  303. def_log_max_days="3"
  304. echo ""
  305. echo -e "Please input ${program_name} ${COLOR_GREEN}log_max_days${COLOR_END} [1-${def_max_days}]"
  306. read -p "(Default log_max_days: ${def_log_max_days} day):" input_log_max_days
  307. [ -z "${input_log_max_days}" ] && input_log_max_days="${def_log_max_days}"
  308. fun_check_number "log_max_days" "${def_max_days}" "${input_log_max_days}"
  309. }
  310. fun_input_max_pool_count(){
  311. def_max_pool="200"
  312. def_max_pool_count="50"
  313. echo ""
  314. echo -e "Please input ${program_name} ${COLOR_GREEN}max_pool_count${COLOR_END} [1-${def_max_pool}]"
  315. read -p "(Default max_pool_count: ${def_max_pool_count}):" input_max_pool_count
  316. [ -z "${input_max_pool_count}" ] && input_max_pool_count="${def_max_pool_count}"
  317. fun_check_number "max_pool_count" "${def_max_pool}" "${input_max_pool_count}"
  318. }
  319. pre_install_clang(){
  320. fun_clangcn
  321. echo -e "Check your server setting, please wait..."
  322. disable_selinux
  323. if [ -s ${str_program_dir}/${program_name} ] && [ -s ${program_init} ]; then
  324. echo "${program_name} is installed!"
  325. else
  326. clear
  327. fun_clangcn
  328. fun_getServer
  329. fun_getVer
  330. echo -e "Loading You Server IP, please wait..."
  331. defIP=$(wget -qO- ip.clang.cn | sed -r 's/\r//')
  332. echo -e "You Server IP:${COLOR_GREEN}${defIP}${COLOR_END}"
  333. echo -e "${COLOR_YELOW}Please input your server setting:${COLOR_END}"
  334. fun_input_bind_port
  335. [ -n "${input_port}" ] && set_bind_port="${input_port}"
  336. echo "${program_name} bind_port: ${set_bind_port}"
  337. echo ""
  338. fun_input_vhost_http_port
  339. [ -n "${input_port}" ] && set_vhost_http_port="${input_port}"
  340. echo "${program_name} vhost_http_port: ${set_vhost_http_port}"
  341. echo ""
  342. fun_input_vhost_https_port
  343. [ -n "${input_port}" ] && set_vhost_https_port="${input_port}"
  344. echo "${program_name} vhost_https_port: ${set_vhost_https_port}"
  345. echo ""
  346. fun_input_dashboard_port
  347. [ -n "${input_port}" ] && set_dashboard_port="${input_port}"
  348. echo "${program_name} dashboard_port: ${set_dashboard_port}"
  349. echo ""
  350. def_dashboard_user="admin"
  351. read -p "Please input dashboard_user (Default: ${def_dashboard_user}):" set_dashboard_user
  352. [ -z "${set_dashboard_user}" ] && set_dashboard_user="${def_dashboard_user}"
  353. echo "${program_name} dashboard_user: ${set_dashboard_user}"
  354. echo ""
  355. def_dashboard_pwd=`fun_randstr 8`
  356. read -p "Please input dashboard_pwd (Default: ${def_dashboard_pwd}):" set_dashboard_pwd
  357. [ -z "${set_dashboard_pwd}" ] && set_dashboard_pwd="${def_dashboard_pwd}"
  358. echo "${program_name} dashboard_pwd: ${set_dashboard_pwd}"
  359. echo ""
  360. default_privilege_token=`fun_randstr 16`
  361. read -p "Please input privilege_token (Default: ${default_privilege_token}):" set_privilege_token
  362. [ -z "${set_privilege_token}" ] && set_privilege_token="${default_privilege_token}"
  363. echo "${program_name} privilege_token: ${set_privilege_token}"
  364. echo ""
  365. fun_input_max_pool_count
  366. [ -n "${input_number}" ] && set_max_pool_count="${input_number}"
  367. echo "${program_name} max_pool_count: ${set_max_pool_count}"
  368. echo ""
  369. echo "##### Please select log_level #####"
  370. echo "1: info (default)"
  371. echo "2: warn"
  372. echo "3: error"
  373. echo "4: debug"
  374. echo "#####################################################"
  375. read -p "Enter your choice (1, 2, 3, 4 or exit. default [1]): " str_log_level
  376. case "${str_log_level}" in
  377. 1|[Ii][Nn][Ff][Oo])
  378. str_log_level="info"
  379. ;;
  380. 2|[Ww][Aa][Rr][Nn])
  381. str_log_level="warn"
  382. ;;
  383. 3|[Ee][Rr][Rr][Oo][Rr])
  384. str_log_level="error"
  385. ;;
  386. 4|[Dd][Ee][Bb][Uu][Gg])
  387. str_log_level="debug"
  388. ;;
  389. [eE][xX][iI][tT])
  390. exit 1
  391. ;;
  392. *)
  393. str_log_level="info"
  394. ;;
  395. esac
  396. echo "log_level: ${str_log_level}"
  397. echo ""
  398. fun_input_log_max_days
  399. [ -n "${input_number}" ] && set_log_max_days="${input_number}"
  400. echo "${program_name} log_max_days: ${set_log_max_days}"
  401. echo ""
  402. echo "##### Please select log_file #####"
  403. echo "1: enable (default)"
  404. echo "2: disable"
  405. echo "#####################################################"
  406. read -p "Enter your choice (1, 2 or exit. default [1]): " str_log_file
  407. case "${str_log_file}" in
  408. 1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])
  409. str_log_file="./frps.log"
  410. str_log_file_flag="enable"
  411. ;;
  412. 0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])
  413. str_log_file="/dev/null"
  414. str_log_file_flag="disable"
  415. ;;
  416. [eE][xX][iI][tT])
  417. exit 1
  418. ;;
  419. *)
  420. str_log_file="./frps.log"
  421. str_log_file_flag="enable"
  422. ;;
  423. esac
  424. echo "log_file: ${str_log_file_flag}"
  425. echo ""
  426. echo "##### Please select tcp_mux #####"
  427. echo "1: enable (default)"
  428. echo "2: disable"
  429. echo "#####################################################"
  430. read -p "Enter your choice (1, 2 or exit. default [1]): " str_tcp_mux
  431. case "${str_tcp_mux}" in
  432. 1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])
  433. set_tcp_mux="true"
  434. ;;
  435. 0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])
  436. set_tcp_mux="false"
  437. ;;
  438. [eE][xX][iI][tT])
  439. exit 1
  440. ;;
  441. *)
  442. set_tcp_mux="true"
  443. ;;
  444. esac
  445. echo "tcp_mux: ${set_tcp_mux}"
  446. echo ""
  447. echo "##### Please select kcp support #####"
  448. echo "1: enable (default)"
  449. echo "2: disable"
  450. echo "#####################################################"
  451. read -p "Enter your choice (1, 2 or exit. default [1]): " str_kcp
  452. case "${str_kcp}" in
  453. 1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])
  454. set_kcp="true"
  455. ;;
  456. 0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])
  457. set_kcp="false"
  458. ;;
  459. [eE][xX][iI][tT])
  460. exit 1
  461. ;;
  462. *)
  463. set_kcp="true"
  464. ;;
  465. esac
  466. echo "kcp support: ${set_kcp}"
  467. echo ""
  468. echo "============== Check your input =============="
  469. echo -e "You Server IP : ${COLOR_GREEN}${defIP}${COLOR_END}"
  470. echo -e "Bind port : ${COLOR_GREEN}${set_bind_port}${COLOR_END}"
  471. echo -e "kcp support : ${COLOR_GREEN}${set_kcp}${COLOR_END}"
  472. echo -e "vhost http port : ${COLOR_GREEN}${set_vhost_http_port}${COLOR_END}"
  473. echo -e "vhost https port : ${COLOR_GREEN}${set_vhost_https_port}${COLOR_END}"
  474. echo -e "Dashboard port : ${COLOR_GREEN}${set_dashboard_port}${COLOR_END}"
  475. echo -e "Dashboard user : ${COLOR_GREEN}${set_dashboard_user}${COLOR_END}"
  476. echo -e "Dashboard password : ${COLOR_GREEN}${set_dashboard_pwd}${COLOR_END}"
  477. echo -e "Privilege token : ${COLOR_GREEN}${set_privilege_token}${COLOR_END}"
  478. echo -e "tcp_mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"
  479. echo -e "Max Pool count : ${COLOR_GREEN}${set_max_pool_count}${COLOR_END}"
  480. echo -e "Log level : ${COLOR_GREEN}${str_log_level}${COLOR_END}"
  481. echo -e "Log max days : ${COLOR_GREEN}${set_log_max_days}${COLOR_END}"
  482. echo -e "Log file : ${COLOR_GREEN}${str_log_file_flag}${COLOR_END}"
  483. echo "=============================================="
  484. echo ""
  485. echo "Press any key to start...or Press Ctrl+c to cancel"
  486. char=`get_char`
  487. install_program_server_clang
  488. fi
  489. }
  490. # ====== install server ======
  491. install_program_server_clang(){
  492. [ ! -d ${str_program_dir} ] && mkdir -p ${str_program_dir}
  493. cd ${str_program_dir}
  494. echo "${program_name} install path:$PWD"
  495. echo -n "config file for ${program_name} ..."
  496. # Config file
  497. if [[ "${set_kcp}" == "false" ]]; then
  498. cat > ${str_program_dir}/${program_config_file}<<-EOF
  499. # [common] is integral section
  500. [common]
  501. # A literal address or host name for IPv6 must be enclosed
  502. # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
  503. bind_addr = 0.0.0.0
  504. bind_port = ${set_bind_port}
  505. # udp port used for kcp protocol, it can be same with 'bind_port'
  506. # if not set, kcp is disabled in frps
  507. #kcp_bind_port = ${set_bind_port}
  508. # if you want to configure or reload frps by dashboard, dashboard_port must be set
  509. dashboard_port = ${set_dashboard_port}
  510. # dashboard assets directory(only for debug mode)
  511. dashboard_user = ${set_dashboard_user}
  512. dashboard_pwd = ${set_dashboard_pwd}
  513. # assets_dir = ./static
  514. vhost_http_port = ${set_vhost_http_port}
  515. vhost_https_port = ${set_vhost_https_port}
  516. # console or real logFile path like ./frps.log
  517. log_file = ${str_log_file}
  518. # debug, info, warn, error
  519. log_level = ${str_log_level}
  520. log_max_days = ${set_log_max_days}
  521. # privilege mode is the only supported mode since v0.10.0
  522. privilege_token = ${set_privilege_token}
  523. # only allow frpc to bind ports you list, if you set nothing, there won't be any limit
  524. #privilege_allow_ports = 1-65535
  525. # pool_count in each proxy will change to max_pool_count if they exceed the maximum value
  526. max_pool_count = ${set_max_pool_count}
  527. # if tcp stream multiplexing is used, default is true
  528. tcp_mux = ${set_tcp_mux}
  529. EOF
  530. else
  531. cat > ${str_program_dir}/${program_config_file}<<-EOF
  532. # [common] is integral section
  533. [common]
  534. # A literal address or host name for IPv6 must be enclosed
  535. # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
  536. bind_addr = 0.0.0.0
  537. bind_port = ${set_bind_port}
  538. # udp port used for kcp protocol, it can be same with 'bind_port'
  539. # if not set, kcp is disabled in frps
  540. kcp_bind_port = ${set_bind_port}
  541. # if you want to configure or reload frps by dashboard, dashboard_port must be set
  542. dashboard_port = ${set_dashboard_port}
  543. # dashboard assets directory(only for debug mode)
  544. dashboard_user = ${set_dashboard_user}
  545. dashboard_pwd = ${set_dashboard_pwd}
  546. # assets_dir = ./static
  547. vhost_http_port = ${set_vhost_http_port}
  548. vhost_https_port = ${set_vhost_https_port}
  549. # console or real logFile path like ./frps.log
  550. log_file = ${str_log_file}
  551. # debug, info, warn, error
  552. log_level = ${str_log_level}
  553. log_max_days = ${set_log_max_days}
  554. # privilege mode is the only supported mode since v0.10.0
  555. privilege_token = ${set_privilege_token}
  556. # only allow frpc to bind ports you list, if you set nothing, there won't be any limit
  557. #privilege_allow_ports = 1-65535
  558. # pool_count in each proxy will change to max_pool_count if they exceed the maximum value
  559. max_pool_count = ${set_max_pool_count}
  560. # if tcp stream multiplexing is used, default is true
  561. tcp_mux = ${set_tcp_mux}
  562. EOF
  563. fi
  564. echo " done"
  565. echo -n "download ${program_name} ..."
  566. rm -f ${str_program_dir}/${program_name} ${program_init}
  567. fun_download_file
  568. echo " done"
  569. echo -n "download ${program_init}..."
  570. if [ ! -s ${program_init} ]; then
  571. if ! wget --no-check-certificate -q ${program_init_download_url} -O ${program_init}; then
  572. echo -e " ${COLOR_RED}failed${COLOR_END}"
  573. exit 1
  574. fi
  575. fi
  576. [ ! -x ${program_init} ] && chmod +x ${program_init}
  577. echo " done"
  578. echo -n "setting ${program_name} boot..."
  579. [ ! -x ${program_init} ] && chmod +x ${program_init}
  580. if [ "${OS}" == 'CentOS' ]; then
  581. chmod +x ${program_init}
  582. chkconfig --add ${program_name}
  583. else
  584. chmod +x ${program_init}
  585. update-rc.d -f ${program_name} defaults
  586. fi
  587. echo " done"
  588. [ -s ${program_init} ] && ln -s ${program_init} /usr/bin/${program_name}
  589. ${program_init} start
  590. fun_clangcn
  591. #install successfully
  592. echo ""
  593. echo "Congratulations, ${program_name} install completed!"
  594. echo "=============================================="
  595. echo -e "You Server IP : ${COLOR_GREEN}${defIP}${COLOR_END}"
  596. echo -e "Bind port : ${COLOR_GREEN}${set_bind_port}${COLOR_END}"
  597. echo -e "KCP support : ${COLOR_GREEN}${set_kcp}${COLOR_END}"
  598. echo -e "vhost http port : ${COLOR_GREEN}${set_vhost_http_port}${COLOR_END}"
  599. echo -e "vhost https port : ${COLOR_GREEN}${set_vhost_https_port}${COLOR_END}"
  600. echo -e "Dashboard port : ${COLOR_GREEN}${set_dashboard_port}${COLOR_END}"
  601. echo -e "Privilege token : ${COLOR_GREEN}${set_privilege_token}${COLOR_END}"
  602. echo -e "tcp_mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"
  603. echo -e "Max Pool count : ${COLOR_GREEN}${set_max_pool_count}${COLOR_END}"
  604. echo -e "Log level : ${COLOR_GREEN}${str_log_level}${COLOR_END}"
  605. echo -e "Log max days : ${COLOR_GREEN}${set_log_max_days}${COLOR_END}"
  606. echo -e "Log file : ${COLOR_GREEN}${str_log_file_flag}${COLOR_END}"
  607. echo "=============================================="
  608. echo -e "${program_name} Dashboard : ${COLOR_GREEN}http://${defIP}:${set_dashboard_port}/${COLOR_END}"
  609. echo -e "Dashboard user : ${COLOR_GREEN}${set_dashboard_user}${COLOR_END}"
  610. echo -e "Dashboard password : ${COLOR_GREEN}${set_dashboard_pwd}${COLOR_END}"
  611. echo "=============================================="
  612. echo ""
  613. echo -e "${program_name} status manage : ${COLOR_PINKBACK_WHITEFONT}${program_name}${COLOR_END} {${COLOR_GREEN}start|stop|restart|status|config|version${COLOR_END}}"
  614. echo -e "Example:"
  615. echo -e " start: ${COLOR_PINK}${program_name}${COLOR_END} ${COLOR_GREEN}start${COLOR_END}"
  616. echo -e " stop: ${COLOR_PINK}${program_name}${COLOR_END} ${COLOR_GREEN}stop${COLOR_END}"
  617. echo -e "restart: ${COLOR_PINK}${program_name}${COLOR_END} ${COLOR_GREEN}restart${COLOR_END}"
  618. exit 0
  619. }
  620. ############################### configure ##################################
  621. configure_program_server_clang(){
  622. if [ -s ${str_program_dir}/${program_config_file} ]; then
  623. vi ${str_program_dir}/${program_config_file}
  624. else
  625. echo "${program_name} configuration file not found!"
  626. exit 1
  627. fi
  628. }
  629. ############################### uninstall ##################################
  630. uninstall_program_server_clang(){
  631. fun_clangcn
  632. if [ -s ${program_init} ] || [ -s ${str_program_dir}/${program_name} ] ; then
  633. echo "============== Uninstall ${program_name} =============="
  634. str_uninstall="n"
  635. echo -n -e "${COLOR_YELOW}You want to uninstall?${COLOR_END}"
  636. read -p "[y/N]:" str_uninstall
  637. case "${str_uninstall}" in
  638. [yY]|[yY][eE][sS])
  639. echo ""
  640. echo "You select [Yes], press any key to continue."
  641. str_uninstall="y"
  642. char=`get_char`
  643. ;;
  644. *)
  645. echo ""
  646. str_uninstall="n"
  647. esac
  648. if [ "${str_uninstall}" == 'n' ]; then
  649. echo "You select [No],shell exit!"
  650. else
  651. checkos
  652. ${program_init} stop
  653. if [ "${OS}" == 'CentOS' ]; then
  654. chkconfig --del ${program_name}
  655. else
  656. update-rc.d -f ${program_name} remove
  657. fi
  658. rm -f ${program_init} /var/run/${program_name}.pid /usr/bin/${program_name}
  659. rm -fr ${str_program_dir}
  660. echo "${program_name} uninstall success!"
  661. fi
  662. else
  663. echo "${program_name} Not install!"
  664. fi
  665. exit 0
  666. }
  667. ############################### update ##################################
  668. update_config_clang(){
  669. if [ ! -r "${str_program_dir}/${program_config_file}" ]; then
  670. echo "config file ${str_program_dir}/${program_config_file} not found."
  671. else
  672. search_dashboard_user=`grep "dashboard_user" ${str_program_dir}/${program_config_file}`
  673. search_dashboard_pwd=`grep "dashboard_pwd" ${str_program_dir}/${program_config_file}`
  674. search_kcp_bind_port=`grep "kcp_bind_port" ${str_program_dir}/${program_config_file}`
  675. search_tcp_mux=`grep "tcp_mux" ${str_program_dir}/${program_config_file}`
  676. if [ -z "${search_dashboard_user}" ] || [ -z "${search_dashboard_pwd}" ] || [ -z "${search_kcp_bind_port}" ] || [ -z "${search_tcp_mux}" ];then
  677. echo -e "${COLOR_GREEN}Configuration files need to be updated, now setting:${COLOR_END}"
  678. echo ""
  679. if [ -z "${search_dashboard_user}" ] && [ -z "${search_dashboard_pwd}" ];then
  680. def_dashboard_user_update="admin"
  681. read -p "Please input dashboard_user (Default: ${def_dashboard_user_update}):" set_dashboard_user_update
  682. [ -z "${set_dashboard_user_update}" ] && set_dashboard_user_update="${def_dashboard_user_update}"
  683. echo "${program_name} dashboard_user: ${set_dashboard_user_update}"
  684. echo ""
  685. def_dashboard_pwd_update=`fun_randstr 8`
  686. read -p "Please input dashboard_pwd (Default: ${def_dashboard_pwd_update}):" set_dashboard_pwd_update
  687. [ -z "${set_dashboard_pwd_update}" ] && set_dashboard_pwd_update="${def_dashboard_pwd_update}"
  688. echo "${program_name} dashboard_pwd: ${set_dashboard_pwd_update}"
  689. echo ""
  690. sed -i "/dashboard_port =.*/a\dashboard_user = ${set_dashboard_user_update}\ndashboard_pwd = ${set_dashboard_pwd_update}\n" ${str_program_dir}/${program_config_file}
  691. fi
  692. if [ -z "${search_kcp_bind_port}" ];then
  693. echo "##### Please select kcp support #####"
  694. echo "1: enable (default)"
  695. echo "2: disable"
  696. echo "#####################################################"
  697. read -p "Enter your choice (1, 2 or exit. default [1]): " str_kcp
  698. case "${str_kcp}" in
  699. 1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])
  700. set_kcp="true"
  701. ;;
  702. 0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])
  703. set_kcp="false"
  704. ;;
  705. [eE][xX][iI][tT])
  706. exit 1
  707. ;;
  708. *)
  709. set_kcp="true"
  710. ;;
  711. esac
  712. echo "kcp support: ${set_kcp}"
  713. def_kcp_bind_port=( $( __readINI ${str_program_dir}/${program_config_file} common bind_port ) )
  714. if [[ "${set_kcp}" == "false" ]]; then
  715. sed -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}
  716. else
  717. sed -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}
  718. fi
  719. fi
  720. if [ -z "${search_tcp_mux}" ];then
  721. echo "##### Please select tcp_mux #####"
  722. echo "1: enable (default)"
  723. echo "2: disable"
  724. echo "#####################################################"
  725. read -p "Enter your choice (1, 2 or exit. default [1]): " str_tcp_mux
  726. case "${str_tcp_mux}" in
  727. 1|[yY]|[yY][eE][sS]|[oO][nN]|[tT][rR][uU][eE]|[eE][nN][aA][bB][lL][eE])
  728. set_tcp_mux="true"
  729. ;;
  730. 0|2|[nN]|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE]|[dD][iI][sS][aA][bB][lL][eE])
  731. set_tcp_mux="false"
  732. ;;
  733. [eE][xX][iI][tT])
  734. exit 1
  735. ;;
  736. *)
  737. set_tcp_mux="true"
  738. ;;
  739. esac
  740. echo "tcp_mux: ${set_tcp_mux}"
  741. sed -i "/^privilege_mode = true/d" ${str_program_dir}/${program_config_file}
  742. 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}
  743. fi
  744. fi
  745. verify_dashboard_user=`grep "^dashboard_user" ${str_program_dir}/${program_config_file}`
  746. verify_dashboard_pwd=`grep "^dashboard_pwd" ${str_program_dir}/${program_config_file}`
  747. verify_kcp_bind_port=`grep "kcp_bind_port" ${str_program_dir}/${program_config_file}`
  748. verify_tcp_mux=`grep "^tcp_mux" ${str_program_dir}/${program_config_file}`
  749. if [ ! -z "${verify_dashboard_user}" ] && [ ! -z "${verify_dashboard_pwd}" ] && [ ! -z "${verify_kcp_bind_port}" ] && [ ! -z "${verify_tcp_mux}" ];then
  750. echo -e "${COLOR_GREEN}update configuration file successfully!!!${COLOR_END}"
  751. else
  752. echo -e "${COLOR_RED}update configuration file error!!!${COLOR_END}"
  753. fi
  754. fi
  755. }
  756. update_program_server_clang(){
  757. fun_clangcn "clear"
  758. if [ -s ${program_init} ] || [ -s ${str_program_dir}/${program_name} ] ; then
  759. echo "============== Update ${program_name} =============="
  760. update_config_clang
  761. checkos
  762. check_centosversion
  763. check_os_bit
  764. remote_init_version=`wget --no-check-certificate -qO- ${program_init_download_url} | sed -n '/'^version'/p' | cut -d\" -f2`
  765. local_init_version=`sed -n '/'^version'/p' ${program_init} | cut -d\" -f2`
  766. install_shell=${strPath}
  767. if [ ! -z ${remote_init_version} ];then
  768. if [[ "${local_init_version}" != "${remote_init_version}" ]];then
  769. echo "========== Update ${program_name} ${program_init} =========="
  770. if ! wget --no-check-certificate ${program_init_download_url} -O ${program_init}; then
  771. echo "Failed to download ${program_name}.init file!"
  772. exit 1
  773. else
  774. echo -e "${COLOR_GREEN}${program_init} Update successfully !!!${COLOR_END}"
  775. fi
  776. fi
  777. fi
  778. [ ! -d ${str_program_dir} ] && mkdir -p ${str_program_dir}
  779. echo -e "Loading network version for ${program_name}, please wait..."
  780. fun_getServer
  781. fun_getVer >/dev/null 2>&1
  782. local_program_version=`${str_program_dir}/${program_name} --version`
  783. echo -e "${COLOR_GREEN}${program_name} local version ${local_program_version}${COLOR_END}"
  784. echo -e "${COLOR_GREEN}${program_name} remote version ${program_version}${COLOR_END}"
  785. if [[ "${local_program_version}" != "${program_version}" ]];then
  786. echo -e "${COLOR_GREEN}Found a new version,update now!!!${COLOR_END}"
  787. ${program_init} stop
  788. sleep 1
  789. rm -f /usr/bin/${program_name} ${str_program_dir}/${program_name}
  790. fun_download_file
  791. if [ "${OS}" == 'CentOS' ]; then
  792. chmod +x ${program_init}
  793. chkconfig --add ${program_name}
  794. else
  795. chmod +x ${program_init}
  796. update-rc.d -f ${program_name} defaults
  797. fi
  798. [ -s ${program_init} ] && ln -s ${program_init} /usr/bin/${program_name}
  799. [ ! -x ${program_init} ] && chmod 755 ${program_init}
  800. ${program_init} start
  801. echo "${program_name} version `${str_program_dir}/${program_name} --version`"
  802. echo "${program_name} update success!"
  803. else
  804. echo -e "no need to update !!!${COLOR_END}"
  805. fi
  806. else
  807. echo "${program_name} Not install!"
  808. fi
  809. exit 0
  810. }
  811. clear
  812. strPath=`pwd`
  813. rootness
  814. fun_set_text_color
  815. checkos
  816. check_centosversion
  817. check_os_bit
  818. pre_install_packs
  819. shell_update
  820. # Initialization
  821. action=$1
  822. [ -z $1 ]
  823. case "$action" in
  824. install)
  825. pre_install_clang 2>&1 | tee /root/${program_name}-install.log
  826. ;;
  827. config)
  828. configure_program_server_clang
  829. ;;
  830. uninstall)
  831. uninstall_program_server_clang 2>&1 | tee /root/${program_name}-uninstall.log
  832. ;;
  833. update)
  834. update_program_server_clang 2>&1 | tee /root/${program_name}-update.log
  835. ;;
  836. *)
  837. fun_clangcn
  838. echo "Arguments error! [${action} ]"
  839. echo "Usage: `basename $0` {install|uninstall|update|config}"
  840. RET_VAL=1
  841. ;;
  842. esac

打赏

                    支付宝                                                         微信

微信与支付宝支付

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注