#!/bin/bash

#zookeeper
aioplugzookeeperdir=/root/aioplug/aioplug_zookeeper
aioplugzookeepertarfile=aioplug_zookeeper.so.1.0.2.tar.gz
aioplugzookeeperversion=$aioplugzookeeperdir/aioplug_zookeeper.so.1.0.2
aioplugzookeepersofile=$aioplugzookeeperdir/aioplug_zookeeper.so
aioplugzookeeper_md5sum=26570800cbbdfcb420d5df5ba2c1a463
aioplugzookeeper_md5sum2=1c0d7bc8cec6db67edcea9af91203ff4

#opentsdb
aioplugopentsdbdir=/root/aioplug/aioplug_opentsdb
aioplugopentsdbtarfile=aioplug_opentsdb.so.1.0.3.tar.gz
aioplugopentsdbversion=$aioplugopentsdbdir/aioplug_opentsdb.so.1.0.3
aioplugopentsdbsofile=$aioplugopentsdbdir/aioplug_opentsdb.so
aioplugopentsdb_md5sum=9e4f86966dd79113a917636050c1d685

_install() {

    if [ ! -d $aioplugzookeeperdir ]; then
        mkdir -p $aioplugzookeeperdir
    fi
    if [ ! -d $aioplugopentsdbdir ]; then
        mkdir -p $aioplugopentsdbdir
    fi
    if [[ $ARCH == 'x86_64' ]];then
        #zookeeper
        tar zxvf $BASEDIR/configs/aioplug/$aioplugzookeepertarfile -C $aioplugzookeeperdir > /dev/null 2>&1
        chown root:root $aioplugzookeeperversion
        install $aioplugzookeeperversion $aioplugzookeepersofile > /dev/null 2>&1
    
        #opentsdb
        tar zxvf $BASEDIR/configs/aioplug/$aioplugopentsdbtarfile -C $aioplugopentsdbdir > /dev/null 2>&1
        chown root:root $aioplugopentsdbversion
        install $aioplugopentsdbversion $aioplugopentsdbsofile > /dev/null 2>&1
    elif [[ $ARCH == 'aarch64' ]];then
        yum -y install libaio
        wget -P $BASEDIR -c http://softlib.service.ucloud.cn/usa/ucloud-basic-init/aioplug_zookeeper.so.aarch64.tar.gz > /dev/null 2>&1
        tar xf $BASEDIR/aioplug_zookeeper.so.aarch64.tar.gz -C $aioplugzookeeperdir
        chown root:root $aioplugzookeepersofile
    fi

}

_check() {
    _check="PASS"

    if [ ! -f $aioplugzookeepersofile ]; then
        _check="FAIL"
        PRINT_ERR "[ERROR] File $aioplugzookeepersofile Not Found."
    fi

    if [ ! -f $aioplugopentsdbsofile ] && [[ $ARCH == "x86_64" ]]; then
        _check="FAIL"
        PRINT_ERR "[ERROR] File $aioplugopentsdbsofile Not Found."
    fi

}
