#!/bin/bash

ceph_configuration(){
    ssh root@${IP_LIST[0]} "sed -i s/S3SECRET/${S3SECRET}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/STORAGEPLATFORM=0/STORAGEPLATFORM=2/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3ACCESS/${S3ACCESS}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s#S3URL#${S3URL}#g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3BUCKET/${S3BUCKET}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    if [ -n "${S3HealthUrl}" ];then 
       ssh root@${IP_LIST[0]} "sed -i s/S3HealthUrl/${S3HealthUrl}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    fi
}
s3_configuration(){
    ssh root@${IP_LIST[0]} "sed -i s/S3SECRET/${S3SECRET}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/STORAGEPLATFORM=0/STORAGEPLATFORM=1000/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3ACCESS/${S3ACCESS}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s#S3URL#${S3URL}#g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3BUCKET/${S3BUCKET}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
}
swift_configuration(){
    ssh root@${IP_LIST[0]} "sed -i s#S3URL#${SWIFT_URL}#g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/STORAGEPLATFORM=0/STORAGEPLATFORM=3/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/USERNAME=/${SWIFT_USER}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/CONTAINERID/${SWIFT_CONTAINERID}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3SECRET/${S3SECRET}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
}

oss_configuration(){
    ssh root@${IP_LIST[0]} "sed -i s/STORAGEPLATFORM=0/STORAGEPLATFORM=4/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s#S3URL#${S3URL}#g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3ACCESS/${S3ACCESS}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3SECRET/${S3SECRET}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"
    ssh root@${IP_LIST[0]} "sed -i s/S3BUCKET/${S3BUCKET}/g ${DOCKER_COMPOSE_DIR}/${ENVFILE}"

}

storage_config(){
      case ${STORAGE_MODE} in
        ceph)
            echo "config s3 storage."
            ceph_configuration
            ;;
        s3)
            echo "config s3 storage."
            s3_configuration
            ;;
        swift)
            echo "config swift storage."
            swift_configuration
            ;;
         oss)
            echo "config oss storage."
            oss_configuration
            ;;
         local|nas)
            echo "local or nas storage."
            ;;
         *) 
            echo "not support STORAGE_MODE."
            exit 1
    esac
}
