#!/bin/bash

group=tke
hostname=$(hostname -I)
if [  ! -f "/etc/redhat-release" ]; then
        os="ubuntu"
        os_ver=`cat /etc/lsb-release |grep -w 'DISTRIB_RELEASE' |awk -F '=' '{print $2}'`
else
        os="centos"
fi

if [ $os == 'centos' ];then
    yum  install  git -y
elif [ $os == 'ubuntu' ];then
    apt install git -y
fi

[ -d /usr/local/os_unify_script ] && rm -rf /usr/local/os_unify_script
cd /usr/local &&  git clone https://sa-public:goodluck1234@git-sa.gyyx.cn/SA-Private/os_unify_script.git
if [ $? != 0 ];then
	echo "项目克隆失败，请检查！！"
	exit 1
fi
chmod +x 777 /tmp
chmod +x /usr/local/os_unify_script/*
if [ $os == 'centos' ];then
    #/bin/sh /usr/local/os_unify_script/osinit_centos.sh
    /bin/sh /usr/local/os_unify_script/os_new_v2.sh $group  $hostname >>/tmp/osinstall.log
elif [ $os == 'ubuntu' ];then
    if [ $os_ver == '20.04' ];then
    	sed -i  '/needrestart.conf/d' /usr/local/os_unify_script/osinit_ubuntu.sh
	#sed -i  '/python2.7.18.zip/d' /usr/local/os_unify_script/config.ini
    fi
    bash /usr/local/os_unify_script/osinit_ubuntu.sh $group $hostname >>/tmp/osinstall.log
fi

if [ $os == 'centos' ];then
    cd /usr/local/os_unify_script  && python   maininit.py all  $group  $hostname >>/tmp/osinstallpackage.log
elif [ $os == 'ubuntu' ];then
    cd /usr/local/os_unify_script  && python3   maininit.py all  $group  $hostname >>/tmp/osinstallpackage.log
fi
