#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
# set -o xtrace

BASE=$(cd `dirname $0`; cd ../; pwd)

TOKEN="7p3ogq9FlWxF3ygez29049KfJRotlezkcAQ1GnvWrADN3ZaqiZStPLKlJLVcUT631LoWCI9R9DgZvzWoQ4xX0A=="
ROOT_PASS=powerone@monitordb

DATA=${DB_DATA:-${BASE}/data}

ARCH=
rs=`arch`
if [[ "$rs" = "x86_64" ]]; then
    ARCH=x86_64
elif [[ "$rs" = "arm64" ]]; then
    ARCH=arm64
elif [[ "$rs" = "aarch64" ]]; then
    ARCH=arm64
fi

if [[ ! -f "$BASE/down/influxdb.tar" ]];then
    echo "influxdb image not exist."
    exit 1
fi
docker load -i "$BASE/down/influxdb.tar"

docker tag influxdb:2.6-alpine easzlab.io.local:5000/influxdb:2.6-alpine
docker push easzlab.io.local:5000/influxdb:2.6-alpine
if [[ -f $BASE/kubedb/kubedb.yaml ]]; then
    rm -rf $BASE/kubedb/kubedb.yaml
fi
cp $BASE/kubedb/kubedb.yaml.tpl $BASE/kubedb/kubedb.yaml
sed -i "s#__BASE_PATH__#$DATA#g" $BASE/kubedb/kubedb.yaml
sed -i "s/__TOKEN__/$TOKEN/g" $BASE/kubedb/kubedb.yaml
sed -i "s/__ROOT_PASS__/$ROOT_PASS/g" $BASE/kubedb/kubedb.yaml
kubectl apply -f $BASE/kubedb/kubedb.yaml
