#!/bin/bash

#stop server
systemctl stop minio smb nfs-server tgtd minio-colony glusterd

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

if [ $disk -eq 4 ];then
   umount /opt/storage/data{1..4}
   parted /dev/sda set 1 raid on
   parted /dev/sdb set 1 raid on
   parted /dev/sdc set 1 raid on
   parted /dev/sdd set 1 raid on
elif [ $disk -eq 8 ];then
   umount /opt/storage/data{1..8}
   parted /dev/sda set 1 raid on
   parted /dev/sdb set 1 raid on
   parted /dev/sdc set 1 raid on
   parted /dev/sdd set 1 raid on
   parted /dev/sde set 1 raid on
   parted /dev/sdf set 1 raid on
   parted /dev/sdg set 1 raid on
   parted /dev/sdh set 1 raid on
else
   echo "disk_not_found"
fi

#set 1 lvm on
if [ ${disk} -eq 4 ];then
   echo 'yes' |mdadm -C -v /dev/md5 -l${1} -n4 /dev/sd[a-d]1
elif [ ${disk} -eq 8 ];then
   echo 'yes' |mdadm -C -v /dev/md5 -l${1} -n8 /dev/sd[a-h]1
fi

#if md device
md="/dev/md5"
if [ ! -e "$md" ];then
   echo "md5_not_found"
   exit
fi

mdadm -Ds >> /etc/mdadm.conf

sleep 1

#mkfs
echo "yes" |mkfs.ext4 /dev/md5

sleep 1

/opt/tool/saturn-mount.py --raid

echo "success"
