#!/bin/bash

get_env_info() {
    find_path=`find / -name "auto_install.sh" -type f | awk -F "auto_install.sh" '{print $1}'`
    install_path="${find_path%%/}"
    echo "================================================"
    echo `"${install_path}"/scripts/remote_env.sh`
    source "${install_path}"/scripts/remote_env.sh
}   

install_allinone_rancher() {
    get_env_info
    echo "==============================="
    docker pull registry.edoc2.com:5000/library/rancher-agent:v2.7.0
    docker pull registry.edoc2.com:5000/library/mirrored-bci-micro:15.4.14.3
    docker pull registry.edoc2.com:5000/library/shell:v0.1.18
    docker pull registry.edoc2.com:5000/library/busybox:1.28
    docker pull registry.edoc2.com:5000/library/rancher:v2.7.0
    docker pull registry.edoc2.com:5000/rancher/rancher-agent:v2.7.0
    docker pull registry.edoc2.com:5000/rancher/rancher:v2.7.0
    docker pull registry.edoc2.com:5000/rancher/shell:v0.1.18
    docker pull registry.edoc2.com:5000/rancher/fleet:v0.5.0
    docker pull registry.edoc2.com:5000/rancher/gitjob:v0.1.32
    docker pull registry.edoc2.com:5000/rancher/fleet-agent:v0.5.0
    sleep 3
    cd "${install_path}"/Template/rancher/
    kubectl -n cattle-system create secret tls tls-rancher-ingress --cert=./tls.crt --key=./tls.key
    kubectl -n cattle-system create secret generic tls-ca --from-file=./cacerts.pem
    cd "${install_path}"/Template/rancher/rancher
    helm install rancher --namespace cattle-system --create-namespace --set systemDefaultRegistry=registry.cn-hangzhou.aliyuncs.com --set ingress.tls.source=secret --set hostname=edoc2v5.rancher.pre.com --set privateCA=false -f values.yaml .    
}

install_allinone_rancher
