#!/bin/bash

install_path=$1
function remote_install_base() {
    IP_LIST_CLONE=(IP ${IP_LIST[@]})
    #string_check ${IP_LIST_CLONE[@]}
    for ip in ${IP_LIST[@]}; do
        echo "============"$ip
        echo $SSH_PORT
        echo ${SSH_OPT}
        USER=$(get_node_attribute "$REGION" $ip user)
        PASSWORD=$(get_node_attribute "$REGION" $ip password)
        echo ${USER}
        echo ${PASSWORD}
        sshpass scp -P $SSH_PORT -r "$install_path"/soft ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/scripts ${USER}@${ip}:/tmp/; 
        #sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/beats.metricbeat.6.7.1.tar ${USER}@${ip}:/tmp/;
        #sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/minio.tar ${USER}@${ip}:/tmp/;

        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/mpfr-3.1.1-4.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libmpc-1.0.1-3.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/kernel-headers-3.10.0-1160.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/glibc-headers-2.17-317.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/glibc-devel-2.17-317.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/cpp-4.8.5-44.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/gcc-4.8.5-44.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libstdc++-devel-4.8.5-44.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/gcc-c++-4.8.5-44.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libnfnetlink-1.0.1-4.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libnfnetlink-devel-1.0.1-4.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libnl-1.1.4-3.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libnl-devel-1.1.4-3.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        #sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libnl3-3.2.28-4.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        #sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/libnl3-devel-3.2.28-4.el7.x86_64.rpm ${USER}@${ip}:/tmp/;

        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/net-snmp-libs-5.7.2-49.el7_9.2.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/net-snmp-agent-libs-5.7.2-49.el7_9.2.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/keepalived-1.3.5-19.el7.x86_64.rpm ${USER}@${ip}:/tmp/;
        sshpass scp -P $SSH_PORT -r "$install_path"/Install_Packages/haproxy-1.5.18-9.el7_9.1.x86_64.rpm ${USER}@${ip}:/tmp/;

        sshpass scp -P $SSH_PORT -r /etc/hosts ${USER}@${ip}:/etc/;
        sleep 1
        sshpass ssh -p $SSH_PORT ${SSH_OPT} ${USER}@${ip} 'source /tmp/scripts/remote_env.sh && cat /tmp/scripts/remote_env.sh && source /tmp/scripts/base_centos7.sh';
    done
}

remote_install_base
