github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/tools/deploy/check-system.sh (about)

     1  #!/bin/bash
     2  #主机操作系统
     3  hostOS=""
     4  function checkHostOS(){
     5  	#文件存在,可能是ubuntu
     6  	if [ -f "/etc/lsb-release" ]; then
     7  		#显示一下
     8  		cat /etc/lsb-release
     9  	    if [ -f "/etc/issue" ]; then
    10  	        issue=$(cat "/etc/issue"|grep "Ubuntu"|awk '{print $1}')
    11  	        if [[ $issue == *Ubuntu* ]];then
    12  	            hostOS="Ubuntu"
    13  	        fi
    14  	    fi
    15  	fi
    16  
    17  	if [ -f "/etc/redhat-release" ]; then
    18  		#显示一下
    19  		cat /etc/redhat-release
    20  		release=$(cat "/etc/redhat-release"|awk '{print $1}')
    21  		if [[ $release == *CentOS* ]];then
    22  		    hostOS="CentOS"
    23  		fi
    24  	fi
    25  }
    26  
    27  #安装时间同步软件
    28  function installNtpdateOnCentOS(){
    29  	if [ ! -f "/usr/sbin/ntpdate" ]; then
    30  		sudo yum install ntpdate -y
    31      fi
    32  }
    33  #安装时间同步软件
    34  function installNtpdateOnUbuntu(){
    35      if [ ! -f "/usr/sbin/ntpdate" ]; then
    36  		sudo apt-get install ntpdate -y
    37  	fi
    38  }
    39  #设置为北京时间,并同步时间
    40  function setTimeZone(){
    41  	if [ -f "/usr/share/zoneinfo/Asia/Shanghai" ]; then
    42  		rm -rf /etc/localtime
    43  		ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    44      fi
    45      #同步时间
    46      ntpdate cn.ntp.org.cn
    47  }
    48  
    49  #检查操作系统发行版本
    50  checkHostOS
    51  
    52  if [[ $hostOS == "Ubuntu" ]];then
    53  	echo "I am Ubuntu"
    54  	installNtpdateOnUbuntu
    55  	setTimeZone
    56  
    57  fi
    58  
    59  if [[ $hostOS == "CentOS" ]];then
    60  	echo "I am CentOS"
    61  	installNtpdateOnCentOS
    62  	setTimeZone
    63  fi