#!/bin/bash

i=1

systemctl stop minio
systemctl stop nfs-server
systemctl stop smb
systemctl stop tgtd
systemctl stop dev

umount /opt/storage/data{1..8}

disk=$(lsblk |grep -Ew "sda|sdb|sdc|sdd|sde|sdf|sdg|sdh"|wc -l)

if [ $disk -eq 4 ];then
  echo "y"|mkfs.ext4 /dev/sda1
  echo "y"|mkfs.ext4 /dev/sdb1
  echo "y"|mkfs.ext4 /dev/sdc1
  echo "y"|mkfs.ext4 /dev/sdd1
else
  echo "y"|mkfs.ext4 /dev/sda1
  echo "y"|mkfs.ext4 /dev/sdb1
  echo "y"|mkfs.ext4 /dev/sdc1
  echo "y"|mkfs.ext4 /dev/sdd1
  echo "y"|mkfs.ext4 /dev/sde1
  echo "y"|mkfs.ext4 /dev/sdf1
  echo "y"|mkfs.ext4 /dev/sdg1
  echo "y"|mkfs.ext4 /dev/sdh1
fi
sleep 3

while [ $i -le 3 ]
do
  bick=$(df |grep data|wc -l)

  if [ $bick -eq 4 ];then
     echo "break_4"
     break
  elif [ $bick -eq 8 ];then
     echo "break_8"
     break
  else
    if [ $disk -eq 4 ];then
       mount /dev/sda1 /opt/storage/data1
       mount /dev/sdb1 /opt/storage/data2
       mount /dev/sdc1 /opt/storage/data3
       mount /dev/sdd1 /opt/storage/data4
    else
       mount /dev/sda1 /opt/storage/data1
       mount /dev/sdb1 /opt/storage/data2
       mount /dev/sdc1 /opt/storage/data3
       mount /dev/sdd1 /opt/storage/data4
       mount /dev/sde1 /opt/storage/data5
       mount /dev/sdf1 /opt/storage/data6
       mount /dev/sdg1 /opt/storage/data7
       mount /dev/sdh1 /opt/storage/data8
     fi
     sleep 1
  fi
 let i++
done

echo "success"
