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