#!/bin/bash

CONFIG_FILE=deploy-config/all.conf

source scripts/config_get.sh
source scripts/global_variables.sh
source scripts/utils.sh
source scripts/hardware_perfcheck.sh


local_rockylinux_baseshell(){
    source $install_path"/scripts/"base_anolis.sh "${install_path}"
}

local_install_docker(){
    source $install_path"/scripts/"docker_install.sh "${install_path}" "${KVERSION}" "${SYSTEM}"
    echo "docker container服务启动安装完毕"
}

local_install_k8s(){
    source $install_path"/scripts/"k8s_allinone_install.sh "${install_path}"
    echo "allinone k8s 安装完毕"
}


#allinone_skywalking() {
#    get_install_path
#    source $install_path"/scripts/"cluster_skywalking.sh
#}

local_deploy_ecm(){
    rpm -ivh "$install_path"/Install_Packages/anolis-soft/fio/*
    sleep 5
    hardware_perfcheck
    source $install_path"/scripts/"k8s_allinone_deploy.sh "${install_path}"
    echo "allinone deploy 部署完毕"
}

local_destry_k8s_allinone(){
    source $install_path"/scripts/"destroy_k8s_allinone.sh
}

local_install_harbor(){
    get_install_path
    source $install_path"/scripts/"install_harbor.sh "${install_path}"
}

get_install_path() {
    find_path=`find / -name "auto_install.sh" -type f | awk -F "auto_install.sh" '{print $1}'`
    install_path="${find_path%%/}"
    #install_path=$(pwd)
    echo "${install_path}"
    cd "${install_path}"
    chmod -R +x scripts/*
}

config_info(){
    log_info "#### get config_info function start"
    log_info "[install_type] TYPE=${TYPE}"
    log_info "#### get config_info function end"
    source $install_path"/scripts/"create_remote_env.sh
}

main(){
    echo "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
    source scripts/echo_variable.sh

    echo "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
    echo "${SYSTEM}"
    if [ "${TYPE}" == "allinone" ];then
        config_info
        echo "### exec allinone choice ################################"
        #source scripts/install_requirements.sh
        if [ "${ACTION_TYPE}" == "install" ];then
            echo "### local install base shell ########################"

            local_rockylinux_baseshell

            echo "### local install docker and container ##############"
            local_install_docker

            echo "### local install k8s allinone ######################"
            local_install_k8s
        elif [ "${ACTION_TYPE}" == "destroy" ];then
            echo "### local destroy k8s allinone ######################"
            local_destry_k8s_allinone
        fi           
    elif [ "${TYPE}" == "cluster" ];then
        echo "### This is allinone install tar, cluster choice not exist! ################################"
        exit
    fi
}

get_install_path
#install_type=`cat conf/default.conf|grep -vE '^$|#|\[' | grep type | grep "=" | awk -v FS='=' '{print $2}'`
#system_type=`cat conf/default.conf|grep -vE '^$|#|\[' | grep system | grep "=" | awk -v FS='=' '{print $2}'`
#system_version=`cat conf/default.conf|grep -vE '^$|#|\[' | grep version | grep "=" | awk -v FS='=' '{print $2}'`
#time_server=`cat conf/default.conf|grep -vE '^$|#|\[' | grep timeserver | grep "=" | awk -v FS='=' '{print $2}'`
#k8s_version=`cat conf/default.conf|grep -vE '^$|#|\[' | grep kversion | grep "=" | awk -v FS='=' '{print $2}'`
main

