#!/bin/bash
#Description:This is my ansbile init script						*
#Author:xhy                                                     *
#Version:v0.0.1                                                 *
#Time:2023/03/30                                                *
#****************************************************************

#-------------------------------------------------------------------------------------

platform=$(cat /etc/redhat-release | grep -o "[0-9]*[0-9]" | sed -n '1p;1q')

echo -n "Is it an inland host,Y or N?"
read answer1

pgversion=v6.0.5
platform=$(cat /etc/redhat-release | grep -o "[0-9]*[0-9]" | sed -n '1p;1q')
mydir="/root/"

#-------------------------------------------------------------------------------------

yum -y install vim wget tar bzip2 xz unzip
yum -y update
result01="Yes,tar bzip vim xz install completed!"

#-------------------------------------------------------------------------------------

cd ${mydir}

myshellinitpk="myshellinit${pgversion}.tar.bz2"
if [ ! -f "${myshellinitpk}" ]; then
    wget http://down.linuxsb.com/myoptions/${myshellinitpk}
fi

tar -jxvf ${myshellinitpk} 2>&1 > /dev/null
/bin/chmod u+x ./myshellinit/*.sh
sleep 1s
result01="Yes,myshellinitpk pk tar completed!"

#-------------------------------------------------------------------------------------
OS=`cat /etc/redhat-release | awk '{print $1}'`
case ${answer1} in
    y | Y | yes | Yes)
        if [ -z ${OS} ];then
            /bin/cp -rbpf ./myshellinit/CentOS${platform}*-aliyun-ustc-redhat.repo /etc/yum.repos.d/
            /bin/cp -rbpf ./myshellinit/epel${platform}*-aliyun-*.repo /etc/yum.repos.d/
        else
            if [ $OS\X == 'CentOSX' ];then
                            if [ ${platform} -eq 8 ];then
                /bin/cp -rpf ./myshellinit/CentOS${platform}*-aliyun-tencent.repo /etc/yum.repos.d/ 
                /bin/cp -rpf ./myshellinit/epel${platform}*-aliyun-*.repo /etc/yum.repos.d/
                else
                /bin/cp -rpf ./myshellinit/CentOS${platform}*-aliyun-ustc.repo /etc/yum.repos.d/
                /bin/cp -rpf ./myshellinit/epel${platform}*-aliyun-*.repo /etc/yum.repos.d/
                                fi
            else
                /bin/cp -rpf ./myshellinit/CentOS${platform}*-aliyun-ustc-redhat.repo /etc/yum.repos.d/
                /bin/cp -rpf ./myshellinit/epel${platform}*-aliyun-*.repo /etc/yum.repos.d/
            fi
        fi
    ;;
    *)
        if [ -z $OS ];then
            /bin/cp -rpf ./myshellinit/CentOS${platform}*-Base-xtom-mit-redhat.repo /etc/yum.repos.d/
            /bin/cp -rpf ./myshellinit/epel${platform}*-xtom-*.repo /etc/yum.repos.d/
        else
            if [ $OS\X == 'CentOSX' ];then
                /bin/cp -rpf ./myshellinit/CentOS${platform}*-Base-xtom-mit.repo /etc/yum.repos.d/
                /bin/cp -rpf ./myshellinit/epel${platform}*-xtom-*.repo /etc/yum.repos.d/
            else
                /bin/cp -rpf ./myshellinit/CentOS${platform}*-Base-xtom-mit-redhat.repo /etc/yum.repos.d/
                /bin/cp -rpf ./myshellinit/epel${platform}*-xtom-*.repo /etc/yum.repos.d/
            fi
        fi
esac
sleep 1s
result02="Yes,Repo install operation completed!"

#-------------------------------------------------------------------------------------
if [ ${platform} -eq 8 ];then
    /usr/bin/yum -y install wget
    rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-Official
    rpm --import https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
	rm -rf /etc/yum.repos.d/epel.repo
	rm -rf /etc/yum.repos.d/epel-testing.repo
	pip3 install ansible
else
	rm -rf /etc/yum.repos.d/epel.repo
	rm -rf /etc/yum.repos.d/epel-testing.repo
	pip3 install ansible
fi

sleep 1s
result03="Yes,Ansible install operation completed!"
#-------------------------------------------------------------------------------------
mkdir /myansibleinit
cd /myansibleinit
wget http://down.linuxsb.com/myoptions/myansibleinit/00_myvars_config.yml
wget http://down.linuxsb.com/myoptions/myansibleinit/01_grub_network_config.yaml
wget http://down.linuxsb.com/myoptions/myansibleinit/02_conname_clear.yml
wget http://down.linuxsb.com/myoptions/myansibleinit/03_system_config.yaml
wget http://down.linuxsb.com/myoptions/myansibleinit/04_python_update.yaml
wget http://down.linuxsb.com/myoptions/myansibleinit/05_clean_all.yml
wget -O .ansible.cfg http://down.linuxsb.com/myoptions/myansibleinit/00_ansible_myinit.cfg
wget http://down.linuxsb.com/myoptions/myansibleinit/00_inventory_myinit

result04="Yes,Ansible all file wget completed!"

rm -rf ${mydir}/myshellinit
echo "${result01}\n${result02}\n${result03}\n${result04}"

cd /myansibleinit
