#!/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)

level=${1}

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${level} -n4 /dev/sd[a-d]1
elif [ ${disk} -eq 8 ];then
   echo 'yes' |mdadm -C -v /dev/md5 -l${level} -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

sleep 1

mdisk=$(df |grep /dev/md5|wc -l)

if [ $mdisk -eq 1 ];then
   echo "success"
else
   echo "error"
fi


