922  
查询码:00000139
一键安装程序,expect自动交互
作者: wyasw 于 2020年03月29日 发布在分类 / Linux / 常用shell脚本 下,并于 2020年03月29日 编辑
shell

需求:一键安装程序,需要用到expect自动交互。

#!/bin/bash

basedir=`cd $(dirname $0); pwd -P`

cd $basedir


function YumDokcer(){

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum install docker-ce -y

systemctl start docker.service

systemctl enable docker.service

docker pull golang:alpine

docker pull alpine

}

rpm -qa |grep docker &>/dev/null

if [ $? -ne 0 ];then

    YumDokcer

fi

if [ $? -ne 0 ];then

    echo 'Dcoekr build error !!!'

    exit 1

fi

docker image ls|awk -F " "  '{ print $1 }'|grep golang &>/dev/null

if [ $? -ne 0 ];then

    docker pull golang:alpine

fi

if [ $? -ne 0 ] ;then

    echo 'docker pull golang:alpine error !!!'

    exit 1

fi


install_file=`ls -l bcb-node_*.tar.gz| grep ^[^d] | awk '{print $9}'`

if [ ! -f "$install_file" ];then

    echo 'The installation file does not exist !!!'

    exit 1

  else

    tar xf $install_file

fi

rpm -q expect &> /dev/null

if [ $? -ne 0 ] ;then

        yum install -y expect

fi

if [ $? -ne 0 ] ;then

    echo 'Install expect error !!!'

    exit 1

fi


#expect install.expect

/usr/bin/expect  << EOF

set timeout -1 

spawn  /bin/bash setup.sh

expect {

 "#?" {send "2\r";exp_continue}

 "node or FOLLOWER to follow:" {send "earth.testchain.io \r";exp_continue}

 "#?" {send "2\r";exp_continue}

 "nodes or FOLLOWERs to follow:" {send "earth.testchain.io \r"}

}

expect eof

EOF




 推荐知识

 历史版本

修改日期 修改人 备注
2020-03-29 21:02:00[当前版本] wyasw 创建版本

文艺知识分享平台 -V 4.9.5 -wcp
京公网安备100012199188号 京ICP备2021030911号