#!/bin/bash

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

#if device number
disk=$(fdisk -l | egrep -c "Disk /dev/sd.*: *.*TiB")

level=${1}

if [ $disk -eq 4 ];then
   wipefs -a -f /dev/sda
   wipefs -a -f /dev/sdb
   wipefs -a -f /dev/sdc
   wipefs -a -f /dev/sdd
elif [ $disk -eq 8 ];then
   wipefs -a -f /dev/sda
   wipefs -a -f /dev/sdb
   wipefs -a -f /dev/sdc
   wipefs -a -f /dev/sdd
   wipefs -a -f /dev/sde
   wipefs -a -f /dev/sdf
   wipefs -a -f /dev/sdg
   wipefs -a -f /dev/sdh
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]
elif [ ${disk} -eq 8 ];then
   echo 'yes' |mdadm -C -v /dev/md5 -l${level} -n8 /dev/sd[a-h]
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
ext=`lsblk -f|grep sd|grep ext4|wc -l`

if [ "$ext" -eq 1 ];then
   echo "磁盘文件系统已存在"
else
   echo "y" | mkfs.ext4 /dev/md5
fi

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


