Commit 9f93d2ae13d717461aa2f97230ce82d8e8843b4a
Committed by
GitHub
1 parent
1e20cff1
Exists in
master
Update install_ngrok.sh
Showing
1 changed file
with
75 additions
and
64 deletions
Show diff stats
install_ngrok.sh
... | ... | @@ -8,32 +8,69 @@ |
8 | 8 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
9 | 9 | export PATH |
10 | 10 | shell_run_start=`date "+%Y-%m-%d %H:%M:%S"` #shell run start time |
11 | -version="4.0" | |
12 | - | |
11 | +version="4.1" | |
13 | 12 | program_download_url=https://raw.githubusercontent.com/clangcn/ngrok-one-key-install/master/latest/ |
14 | 13 | x64_file=server_ngrokd_linux_amd64 |
15 | 14 | x86_file=server_ngrokd_linux_386 |
16 | 15 | md5sum_file=md5sum.md |
17 | 16 | program_init_download_url=https://raw.githubusercontent.com/clangcn/ngrok-one-key-install/master/ngrokd.init |
18 | 17 | str_install_shell=https://raw.githubusercontent.com/clangcn/ngrok-one-key-install/master/install_ngrok.sh |
19 | - | |
20 | 18 | str_ngrok_dir="/usr/local/ngrok" |
21 | - | |
22 | -function fun_clang.cn(){ | |
19 | +contact_us="http://koolshare.cn/forum-72-1.html" | |
20 | +function 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 ${action}${COLOR_END}" | |
37 | + echo | |
38 | + exit 1 | |
39 | + fi | |
40 | + exit 1 | |
41 | + fi | |
42 | + fi | |
43 | +} | |
44 | +function fun_clangcn(){ | |
45 | + local clear_flag="" | |
46 | + clear_flag=$1 | |
47 | + if [[ ${clear_flag} == "clear" ]]; then | |
48 | + clear | |
49 | + fi | |
23 | 50 | echo "" |
24 | 51 | echo "+------------------------------------------------------------+" |
25 | 52 | echo "| Ngrok for Linux Server, Written by Clang |" |
26 | 53 | echo "+------------------------------------------------------------+" |
27 | 54 | echo "| A tool to auto-compile & install Ngrok on Linux |" |
28 | 55 | echo "+------------------------------------------------------------+" |
29 | - echo "| Author: Clang <admin@clang.cn> | Intro: http://clang.cn/ |" | |
56 | + echo "| Intro: http://koolshare.cn/forum-72-1.html |" | |
30 | 57 | echo "+------------------------------------------------------------+" |
31 | 58 | echo "" |
32 | 59 | } |
60 | +function 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 | +} | |
33 | 70 | # Check if user is root |
34 | 71 | function rootness(){ |
35 | 72 | if [[ $EUID -ne 0 ]]; then |
36 | - fun_clang.cn | |
73 | + fun_clangcn | |
37 | 74 | echo "Error:This script must be run as root!" 1>&2 |
38 | 75 | exit 1 |
39 | 76 | fi |
... | ... | @@ -47,16 +84,6 @@ function get_char(){ |
47 | 84 | stty echo |
48 | 85 | stty $SAVEDSTTY |
49 | 86 | } |
50 | -function fun_set_text_color(){ | |
51 | - COLOR_RED='\E[1;31m' | |
52 | - COLOR_GREEN='\E[1;32m' | |
53 | - COLOR_YELOW='\E[1;33m' | |
54 | - COLOR_BLUE='\E[1;34m' | |
55 | - COLOR_PINK='\E[1;35m' | |
56 | - COLOR_PINKBACK_WHITEFONT='\033[45;37m' | |
57 | - COLOR_GREEN_LIGHTNING='\033[32m \033[05m' | |
58 | - COLOR_END='\E[0m' | |
59 | -} | |
60 | 87 | # Check OS |
61 | 88 | function checkos(){ |
62 | 89 | if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then |
... | ... | @@ -247,7 +274,7 @@ function pre_install(){ |
247 | 274 | openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000 |
248 | 275 | config_runshell_ngrok |
249 | 276 | clear |
250 | - fun_clang.cn | |
277 | + fun_clangcn | |
251 | 278 | echo "Install Ngrok completed! enjoy it." |
252 | 279 | echo "=========================================================================" |
253 | 280 | echo "On key install Ngrok ${version} for Debian/Ubuntu/CentOS Linux Server" |
... | ... | @@ -367,7 +394,7 @@ function check_killall(){ |
367 | 394 | } |
368 | 395 | ############################### uninstall function ################################## |
369 | 396 | function fun_install_ngrok(){ |
370 | - fun_clang.cn | |
397 | + fun_clangcn | |
371 | 398 | checkos |
372 | 399 | check_centosversion |
373 | 400 | check_os_bit |
... | ... | @@ -387,7 +414,7 @@ function fun_configure_ngrok(){ |
387 | 414 | fi |
388 | 415 | } |
389 | 416 | function fun_uninstall_ngrok(){ |
390 | - fun_clang.cn | |
417 | + fun_clangcn | |
391 | 418 | if [ -s ${str_ngrok_dir}/bin/ngrokd ] && [ -s /etc/init.d/ngrokd ]; then |
392 | 419 | echo "============== Uninstall Ngrok ==============" |
393 | 420 | save_config="n" |
... | ... | @@ -430,71 +457,54 @@ function fun_uninstall_ngrok(){ |
430 | 457 | echo "" |
431 | 458 | } |
432 | 459 | function fun_update_ngrok(){ |
433 | - fun_clang.cn | |
460 | + fun_clangcn | |
434 | 461 | if [ -s ${str_ngrok_dir}/bin/ngrokd ] && [ -s /etc/init.d/ngrokd ]; then |
435 | 462 | echo "============== Update Ngrok ==============" |
436 | 463 | checkos |
437 | 464 | check_centosversion |
438 | 465 | check_os_bit |
439 | - remote_shell_version=`curl -s ${str_install_shell} | sed -n '/'^version'/p' | cut -d\" -f2` | |
440 | 466 | remote_init_version=`curl -s ${program_init_download_url} | sed -n '/'^version'/p' | cut -d\" -f2` |
441 | 467 | local_init_version=`sed -n '/'^version'/p' /etc/init.d/ngrokd | cut -d\" -f2` |
442 | 468 | install_shell=${strPath} |
443 | 469 | cd ${str_ngrok_dir} |
444 | - update_flag="false" | |
445 | - if [ ! -z ${remote_shell_version} ] || [ ! -z ${remote_init_version} ];then | |
446 | - if [[ "${local_init_version}" < "${remote_init_version}" ]];then | |
470 | + if [ ! -z ${remote_init_version} ];then | |
471 | + if [[ "${local_init_version}" != "${remote_init_version}" ]];then | |
447 | 472 | echo "========== Update ngrokd /etc/init.d/ngrokd ==========" |
448 | 473 | if ! wget --no-check-certificate ${program_init_download_url} -O /etc/init.d/ngrokd; then |
449 | 474 | echo "Failed to download ngrokd.init file!" |
450 | 475 | exit 1 |
451 | 476 | else |
452 | 477 | echo -e "${COLOR_GREEN}/etc/init.d/ngrokd Update successfully !!!${COLOR_END}" |
453 | - update_flag="true" | |
454 | - fi | |
455 | - fi | |
456 | - if [[ "${version}" < "${remote_shell_version}" ]];then | |
457 | - echo "========== Update ngrokd install_ngrok.sh ==========" | |
458 | - if ! wget --no-check-certificate ${str_install_shell} -O ${install_shell}/$0; then | |
459 | - echo "Failed to download install_ngrok.sh file!" | |
460 | - exit 1 | |
461 | - else | |
462 | - echo -e "${COLOR_GREEN}install_ngrok.sh Update successfully !!!${COLOR_END}" | |
463 | - update_flag="true" | |
478 | + [ ! -x /etc/init.d/ngrokd ] && chmod 755 /etc/init.d/ngrokd | |
479 | + [ -s /etc/init.d/ngrokd ] && ln -s /etc/init.d/ngrokd /usr/bin/ngrokd | |
464 | 480 | fi |
465 | 481 | fi |
466 | - if [ "${update_flag}" == 'true' ]; then | |
467 | - echo -e "${COLOR_GREEN}Update shell successfully !!!${COLOR_END}" | |
468 | - echo "" | |
469 | - echo -e "${COLOR_GREEN}Please Re-run${COLOR_END} ${COLOR_PINKBACK_WHITEFONT}$0 update${COLOR_END}" | |
470 | - echo "" | |
471 | - exit 1 | |
472 | - fi | |
473 | 482 | fi |
474 | - if [ "${update_flag}" == 'false' ]; then | |
475 | - [ ! -d ${str_ngrok_dir}/bin/ ] && mkdir -p ${str_ngrok_dir}/bin/ | |
483 | + [ ! -d ${str_ngrok_dir}/bin/ ] && mkdir -p ${str_ngrok_dir}/bin/ | |
484 | + ps -ef | grep -v grep | grep -i "${str_ngrok_dir}/bin/ngrokd" > /dev/null 2>&1 | |
485 | + if [ $? -eq 0 ]; then | |
486 | + /etc/init.d/ngrokd stop | |
487 | + else | |
476 | 488 | check_killall |
477 | 489 | killall ngrokd |
478 | - rm -f ${str_ngrok_dir}/bin/ngrokd /usr/bin/ngrokd /var/run/ngrok_clang.pid /root/ngrok_install.log /root/ngrok_uninstall.log | |
479 | - # Download ngrok file | |
480 | - fun_download_file | |
481 | - [ ! -x /etc/init.d/ngrokd ] && chmod 755 /etc/init.d/ngrokd | |
482 | - [ -s /etc/init.d/ngrokd ] && ln -s /etc/init.d/ngrokd /usr/bin/ngrokd | |
483 | - if [ "${OS}" == 'CentOS' ]; then | |
484 | - if [ -s /etc/init.d/ngrokd ]; then | |
485 | - chmod +x /etc/init.d/ngrokd | |
486 | - chkconfig --add ngrokd | |
487 | - fi | |
488 | - else | |
489 | - if [ -s /etc/init.d/ngrokd ]; then | |
490 | - chmod +x /etc/init.d/ngrokd | |
491 | - update-rc.d -f ngrokd defaults | |
492 | - fi | |
490 | + fi | |
491 | + rm -f ${str_ngrok_dir}/bin/ngrokd /usr/bin/ngrokd /var/run/ngrok_clang.pid /root/ngrok_install.log /root/ngrok_uninstall.log | |
492 | + # Download ngrok file | |
493 | + fun_download_file | |
494 | + if [ "${OS}" == 'CentOS' ]; then | |
495 | + if [ -s /etc/init.d/ngrokd ]; then | |
496 | + chmod +x /etc/init.d/ngrokd | |
497 | + chkconfig --add ngrokd | |
498 | + fi | |
499 | + else | |
500 | + if [ -s /etc/init.d/ngrokd ]; then | |
501 | + chmod +x /etc/init.d/ngrokd | |
502 | + update-rc.d -f ngrokd defaults | |
493 | 503 | fi |
494 | - clear | |
495 | - /etc/init.d/ngrokd start | |
496 | - echo "Ngrok update success!" | |
497 | 504 | fi |
505 | + clear | |
506 | + /etc/init.d/ngrokd start | |
507 | + echo "Ngrok update success!" | |
498 | 508 | else |
499 | 509 | echo "Ngrok Not install!" |
500 | 510 | fi |
... | ... | @@ -505,6 +515,7 @@ rootness |
505 | 515 | strPath=`pwd` |
506 | 516 | fun_set_text_color |
507 | 517 | action=$1 |
518 | +shell_update | |
508 | 519 | [ -z $1 ] |
509 | 520 | case "$action" in |
510 | 521 | install) |
... | ... | @@ -521,7 +532,7 @@ update) |
521 | 532 | fun_update_ngrok 2>&1 | tee /root/ngrok_update.log |
522 | 533 | ;; |
523 | 534 | *) |
524 | - fun_clang.cn | |
535 | + fun_clangcn | |
525 | 536 | echo "Arguments error! [${action} ]" |
526 | 537 | echo "Usage: `basename $0` {install|uninstall|update|config}" |
527 | 538 | ;; | ... | ... |