Commit 66474277c7d62e9ac72770f156f05130ac556449

Authored by Clang
1 parent 504d8ca3
Exists in master

Update install_ngrok.sh

Showing 1 changed file with 211 additions and 32 deletions   Show diff stats
install_ngrok.sh
... ... @@ -8,13 +8,26 @@
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="V1.1"
  11 +version="V2.0"
12 12 str_ngrok_dir="/usr/local/ngrok"
  13 +
  14 +function fun_clang.cn(){
  15 +echo ""
  16 +echo "#######################################################################"
  17 +echo "# install Ngrok for Debian/Ubuntu/CentOS Linux Server"
  18 +echo "# Intro: http://clang.cn/blog/"
  19 +echo "#"
  20 +echo "# Author: Clang <admin@clangcn.com>"
  21 +echo "# version:${version}"
  22 +echo "#######################################################################"
  23 +echo ""
  24 +}
13 25 # Check if user is root
14 26 function rootness(){
15 27 if [[ $EUID -ne 0 ]]; then
16   - echo "Error:This script must be run as root!" 1>&2
17   - exit 1
  28 + fun_clang.cn
  29 + echo "Error:This script must be run as root!" 1>&2
  30 + exit 1
18 31 fi
19 32 }
20 33 function get_char(){
... ... @@ -26,17 +39,6 @@ function get_char(){
26 39 stty echo
27 40 stty $SAVEDSTTY
28 41 }
29   -function fun_clangcn.com(){
30   -echo ""
31   -echo "#######################################################################"
32   -echo "# install Ngrok ${version} for Debian/Ubuntu/CentOS Linux Server"
33   -echo "# Intro: http://clang.cn/blog/"
34   -echo "#"
35   -echo "# Author: Clang <admin@clangcn.com>"
36   -echo "# version:${version}"
37   -echo "#######################################################################"
38   -echo ""
39   -}
40 42 # Check OS
41 43 function checkos(){
42 44 if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
... ... @@ -156,14 +158,14 @@ function pre_install(){
156 158 echo "install ngrok,please wait..."
157 159 if [ "${OS}" == 'CentOS' ]; then
158 160 #yum -y update
159   - yum -y install unzip nano net-tools zlib-devel openssl-devel perl hg cpio expat-devel gettext-devel curl curl-devel perl-ExtUtils-MakeMaker wget gcc gcc-c++
  161 + yum -y install nano net-tools openssl-devel curl curl-devel psmisc wget
160 162 else
161 163 apt-get update -y
162   - apt-get install -y wget build-essential mercurial nano curl openssl libcurl4-openssl-dev
  164 + apt-get install -y wget build-essential mercurial nano curl psmisc openssl libcurl4-openssl-dev
163 165 fi
164 166 [ ! -d ${str_ngrok_dir}/bin/ ] && mkdir -p ${str_ngrok_dir}/bin/
165 167 cd ${str_ngrok_dir}
166   - # Download shadowsocks chkconfig file
  168 + # Download ngrok file
167 169 if [ "${Is_64bit}" == 'y' ] ; then
168 170 if [ ! -s ${str_ngrok_dir}/bin/ngrokd ]; then
169 171 if ! wget --no-check-certificate https://github.com/clangcn/ngrok-one-key-install/raw/master/ngrokd/ngrokd.x86_64 -O ${str_ngrok_dir}/bin/ngrokd; then
... ... @@ -179,18 +181,17 @@ function pre_install(){
179 181 fi
180 182 fi
181 183 fi
182   - [ ! -x ${str_ngrok_dir}/bin/ngrokd ] && chmod 755 ${str_ngrok_dir}/bin/ngrokd
183   - cd /usr/local/ngrok
184   - openssl genrsa -out rootCA.key 2048
185   - openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem
186   - openssl genrsa -out server.key 2048
187   - openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
188   - openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000
189   -
190 184 if [ -s ${str_ngrok_dir}/bin/ngrokd ]; then
  185 + [ ! -x ${str_ngrok_dir}/bin/ngrokd ] && chmod 755 ${str_ngrok_dir}/bin/ngrokd
  186 + cd ${str_ngrok_dir}
  187 + openssl genrsa -out rootCA.key 2048
  188 + openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem
  189 + openssl genrsa -out server.key 2048
  190 + openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
  191 + openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000
191 192 config_runshell_ngrok
192 193 clear
193   - fun_clangcn.com
  194 + fun_clang.cn
194 195 echo "Install Ngrok completed! enjoy it."
195 196 echo "========================================================================="
196 197 echo "On key install Ngrok ${version} for Debian/Ubuntu/CentOS Linux Server"
... ... @@ -206,7 +207,9 @@ function pre_install(){
206 207 echo -e "remote_port: \033[32m\033[01m4443\033[0m"
207 208 echo -e "Config file: \033[32m\033[01m${str_ngrok_dir}/.ngrok_config.sh\033[0m"
208 209 echo ""
  210 + /etc/init.d/ngrokd start
209 211 echo "========================================================================="
  212 + exit 0
210 213 else
211 214 echo ""
212 215 echo "Sorry,Failed to install Ngrok!"
... ... @@ -272,18 +275,194 @@ else
272 275 update-rc.d -f ngrokd defaults
273 276 fi
274 277 fi
275   -/etc/init.d/ngrokd start
276 278 }
  279 +function check_nano(){
  280 + nano -V
  281 + #echo $?
  282 + if [[ $? -le 1 ]] ;then
  283 + echo " Run nano success"
  284 + else
  285 + echo " Run nano failed"
  286 + if [ "${OS}" == 'CentOS' ]; then
  287 + echo " Install centos nano ..."
  288 + #yum -y update
  289 + yum -y install nano
  290 + else
  291 + echo " Install debian/ubuntu nano ..."
  292 + apt-get update -y
  293 + apt-get install -y nano
  294 + fi
  295 + fi
  296 + # if [[ ! -d "$result" ]]; then
  297 + # echo "not found"
  298 + # else
  299 + # echo "found"
  300 + # fi
  301 + echo $result
  302 +}
  303 +function check_killall(){
  304 + killall -V
  305 + #echo $?
  306 + if [[ $? -le 1 ]] ;then
  307 + echo " Run killall success"
  308 + else
  309 + echo " Run killall failed"
  310 + if [ "${OS}" == 'CentOS' ]; then
  311 + echo " Install centos killall ..."
  312 + #yum -y update
  313 + yum -y install psmisc
  314 + else
  315 + echo " Install debian/ubuntu killall ..."
  316 + apt-get update -y
  317 + apt-get install -y psmisc
  318 + fi
  319 + fi
  320 + # if [[ ! -d "$result" ]]; then
  321 + # echo "not found"
  322 + # else
  323 + # echo "found"
  324 + # fi
  325 + echo $result
  326 +}
  327 +############################### uninstall function ##################################
277 328 function fun_install_ngrok(){
  329 + fun_clang.cn
278 330 checkos
279 331 check_centosversion
280 332 check_os_bit
281 333 disable_selinux
282   - fun_set_ngrok_user_env
  334 + if [ -s ${str_ngrok_dir}/bin/ngrokd ] && [ -s /etc/init.d/ngrokd ]; then
  335 + echo "Ngrok is installed!"
  336 + else
  337 + fun_set_ngrok_user_env
  338 + fi
  339 +}
  340 +function fun_configure_ngrok(){
  341 + check_nano
  342 + if [ -s ${str_ngrok_dir}/.ngrok_config.sh ]; then
  343 + nano ${str_ngrok_dir}/.ngrok_config.sh
  344 + else
  345 + echo "Ngrok configuration file not found!"
  346 + fi
  347 +}
  348 +function fun_uninstall_ngrok(){
  349 + fun_clang.cn
  350 + if [ -s ${str_ngrok_dir}/bin/ngrokd ] && [ -s /etc/init.d/ngrokd ]; then
  351 + echo "============== Uninstall Ngrok =============="
  352 + save_config="n"
  353 + echo -e "\033[33mDo you want to keep the configuration file?\033[0m"
  354 + read -p "(if you want please input: y,Default [no]):" save_config
  355 +
  356 + case "${save_config}" in
  357 + y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)
  358 + echo ""
  359 + echo "You will keep the configuration file!"
  360 + save_config="y"
  361 + ;;
  362 + n|N|No|NO|no|nO)
  363 + echo ""
  364 + echo "You will NOT to keep the configuration file!"
  365 + save_config="n"
  366 + ;;
  367 + *)
  368 + echo ""
  369 + echo "will NOT to keep the configuration file!"
  370 + save_config="n"
  371 + esac
  372 + checkos
  373 + /etc/init.d/ngrokd stop
  374 + if [ "${OS}" == 'CentOS' ]; then
  375 + chkconfig --del ngrokd
  376 + else
  377 + update-rc.d -f ngrokd remove
  378 + fi
  379 + rm -f /etc/init.d/ngrokd /var/run/ngrok_clang.pid /root/ngrok_install.log /root/ngrok_update.log
  380 + if [ "${save_config}" == 'n' ]; then
  381 + rm -fr ${str_ngrok_dir}
  382 + else
  383 + rm -fr ${str_ngrok_dir}/bin/ ${str_ngrok_dir}/ngrok.log ${str_ngrok_dir}/rootCA.* ${str_ngrok_dir}/server.*
  384 + fi
  385 + echo "Ngrok uninstall success!"
  386 + else
  387 + echo "Ngrok Not install!"
  388 + fi
  389 + echo ""
  390 +}
  391 +function fun_update_ngrok(){
  392 + fun_clang.cn
  393 + if [ -s ${str_ngrok_dir}/bin/ngrokd ] && [ -s /etc/init.d/ngrokd ]; then
  394 + echo "============== Update Ngrok =============="
  395 + checkos
  396 + check_centosversion
  397 + check_os_bit
  398 + check_killall
  399 + killall ngrokd
  400 + [ ! -d ${str_ngrok_dir}/bin/ ] && mkdir -p ${str_ngrok_dir}/bin/
  401 + rm -f ${str_ngrok_dir}/bin/ngrokd /etc/init.d/ngrokd /var/run/ngrok_clang.pid /root/ngrok_install.log /root/ngrok_uninstall.log
  402 + cd ${str_ngrok_dir}
  403 + # Download ngrok file
  404 + if [ "${Is_64bit}" == 'y' ] ; then
  405 + if [ ! -s ${str_ngrok_dir}/bin/ngrokd ]; then
  406 + if ! wget --no-check-certificate https://github.com/clangcn/ngrok-one-key-install/raw/master/ngrokd/ngrokd.x86_64 -O ${str_ngrok_dir}/bin/ngrokd; then
  407 + echo "Failed to download ngrokd.x86_64 file!"
  408 + exit 1
  409 + fi
  410 + fi
  411 + else
  412 + if [ ! -s ${str_ngrok_dir}/bin/ngrokd ]; then
  413 + if ! wget --no-check-certificate https://github.com/clangcn/ngrok-one-key-install/raw/master/ngrokd/ngrokd.x86 -O ${str_ngrok_dir}/bin/ngrokd; then
  414 + echo "Failed to download ngrokd.x86 file!"
  415 + exit 1
  416 + fi
  417 + fi
  418 + fi
  419 + [ ! -x ${str_ngrok_dir}/bin/ngrokd ] && chmod 755 ${str_ngrok_dir}/bin/ngrokd
  420 + if ! wget --no-check-certificate https://github.com/clangcn/ngrok-one-key-install/raw/master/ngrokd.init -O /etc/init.d/ngrokd; then
  421 + echo "Failed to download ngrokd.init file!"
  422 + exit 1
  423 + fi
  424 + [ ! -x /etc/init.d/ngrokd ] && chmod 755 /etc/init.d/ngrokd
  425 + if [ "${OS}" == 'CentOS' ]; then
  426 + if [ -s /etc/init.d/ngrokd ]; then
  427 + chmod +x /etc/init.d/ngrokd
  428 + chkconfig --add ngrokd
  429 + fi
  430 + else
  431 + if [ -s /etc/init.d/ngrokd ]; then
  432 + chmod +x /etc/init.d/ngrokd
  433 + update-rc.d -f ngrokd defaults
  434 + fi
  435 + fi
  436 + clear
  437 + /etc/init.d/ngrokd start
  438 + echo "Ngrok update success!"
  439 + else
  440 + echo "Ngrok Not install!"
  441 + fi
  442 + echo ""
283 443 }
284 444 clear
285   -fun_clangcn.com
286 445 rootness
287   -rm -f /root/ngrok_install.log
288   -fun_install_ngrok 2>&1 | tee /root/ngrok_install.log
289   -exit 0
  446 +
  447 +action=$1
  448 +[ -z $1 ]
  449 +case "$action" in
  450 +install)
  451 + rm -f /root/ngrok_install.log
  452 + fun_install_ngrok 2>&1 | tee /root/ngrok_install.log
  453 + ;;
  454 +config)
  455 + fun_configure_ngrok
  456 + ;;
  457 +uninstall)
  458 + fun_uninstall_ngrok 2>&1 | tee /root/ngrok_uninstall.log
  459 + ;;
  460 +update)
  461 + fun_update_ngrok 2>&1 | tee /root/ngrok_update.log
  462 + ;;
  463 +*)
  464 + fun_clang.cn
  465 + echo "Arguments error! [${action} ]"
  466 + echo "Usage: `basename $0` {install|uninstall|update|config}"
  467 + ;;
  468 +esac
... ...