From 8e104c564bc43f9efc3d0a52ea6e07690048f121 Mon Sep 17 00:00:00 2001 From: Clang Date: Sat, 26 Mar 2016 17:53:35 +0800 Subject: [PATCH] 增加开机启动功能 --- ngrok_install.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/ngrok_install.sh b/ngrok_install.sh index deb0b38..2752f1d 100644 --- a/ngrok_install.sh +++ b/ngrok_install.sh @@ -1,8 +1,15 @@ #!/bin/bash +#=============================================================================================== +# System Required: CentOS Debian or Ubuntu (32bit/64bit) +# Description: Install Ngrok for CentOS Debian or Ubuntu +# Author: Clang +# Intro: http://clang.cn +#=============================================================================================== PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH shell_run_start=`date "+%Y-%m-%d %H:%M:%S"` #shell run start time -version="V4.0" +version="V5.0" +str_ngrok_dir="/usr/local/ngrok" # Check if user is root function rootness(){ if [[ $EUID -ne 0 ]]; then @@ -10,9 +17,7 @@ function rootness(){ exit 1 fi } - -get_char() -{ +function get_char(){ SAVEDSTTY=`stty -g` stty -echo stty cbreak @@ -21,11 +26,10 @@ get_char() stty echo stty $SAVEDSTTY } - function fun_clangcn.com(){ echo "" echo "#######################################################################" -echo "# On key install Ngrok ${version} for Debian/Ubuntu/CentOS Linux Server" +echo "# install Ngrok ${version} for Debian/Ubuntu/CentOS Linux Server" echo "# Intro: http://clang.cn/blog/" echo "#" echo "# Author: Clang " @@ -33,7 +37,6 @@ echo "# version:${version}" echo "#######################################################################" echo "" } - # Check OS function checkos(){ if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then @@ -47,7 +50,6 @@ function checkos(){ exit 1 fi } - # Get version function getversion(){ if [[ -s /etc/redhat-release ]];then @@ -56,7 +58,6 @@ function getversion(){ grep -oE "[0-9.]+" /etc/issue fi } - # CentOS version function centosversion(){ local code=$1 @@ -68,7 +69,6 @@ function centosversion(){ return 1 fi } - # Check OS bit function check_os_bit(){ if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then @@ -77,14 +77,12 @@ function check_os_bit(){ Is_64bit='n' fi } - function check_centosversion(){ if centosversion 5; then echo "Not support CentOS 5.x, please change to CentOS 6,7 or Debian or Ubuntu and try again." exit 1 fi } - # Disable selinux function disable_selinux(){ if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then @@ -92,22 +90,29 @@ function disable_selinux(){ setenforce 0 fi } - - - function fun_set_ngrok_domain(){ # Set ngrok domain NGROK_DOMAIN="" read -p "Please input domain for Ngrok(e.g.:ngrok.clang.cn):" NGROK_DOMAIN check_input } - +function fun_randstr(){ + index=0 + strRandomPass="" + for i in {a..z}; do arr[index]=$i; index=`expr ${index} + 1`; done + for i in {A..Z}; do arr[index]=$i; index=`expr ${index} + 1`; done + for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done + for i in {1..16}; do strRandomPass="$strRandomPass${arr[$RANDOM%$index]}"; done + echo $strRandomPass +} function fun_set_ngrok_pass(){ # Set ngrok pass - ngrok_pass="" - read -p "Please input password for Ngrok:" ngrok_pass + ngrokpass=`fun_randstr` + read -p "Please input password for Ngrok(Default Password: ${ngrokpass}):" ngrok_pass + if [ "${ngrok_pass}" = "" ]; then + ngrok_pass="${ngrokpass}" + fi } - function check_input(){ # check ngrok domain if [ "$NGROK_DOMAIN" = "" ]; then @@ -128,9 +133,8 @@ function check_input(){ pre_install fi } - function config_runshell_ngrok(){ -cat > /root/.ngrok_config.sh < ${str_ngrok_dir}/.ngrok_config.sh <