#!/bin/bash

systemctl stop minio nfs-server smb tgtd
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

        dd if=/dev/zero of=/dev/sda bs=10M count=1
        dd if=/dev/zero of=/dev/sdb bs=10M count=1
        dd if=/dev/zero of=/dev/sdc bs=10M count=1
        dd if=/dev/zero of=/dev/sdd bs=10M count=1

        sleep 1

        /opt/tool/saturn-device-id.sh -w 0x0 $1 16

        echo "yes" |parted /dev/sda mklabel gpt
        echo "Ignore" | parted /dev/sda "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdb mklabel gpt
        echo "Ignore" | parted /dev/sdb "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdc mklabel gpt
        echo "Ignore" | parted /dev/sdc "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdd mklabel gpt
        echo "Ignore" | parted /dev/sdd "mkpart primary ext4 2048s -1"

        partprobe

elif [ $disk -eq 8 ];then
        dd if=/dev/zero of=/dev/sda bs=10M count=1
        dd if=/dev/zero of=/dev/sdb bs=10M count=1
        dd if=/dev/zero of=/dev/sdc bs=10M count=1
        dd if=/dev/zero of=/dev/sdd bs=10M count=1
        dd if=/dev/zero of=/dev/sde bs=10M count=1
        dd if=/dev/zero of=/dev/sdf bs=10M count=1
        dd if=/dev/zero of=/dev/sdg bs=10M count=1
        dd if=/dev/zero of=/dev/sdh bs=10M count=1


        sleep 1

        /opt/tool/saturn-device-id.sh -w 0x0 $1 16

        echo "yes" |parted /dev/sda mklabel gpt
        echo "Ignore" | parted /dev/sda "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdb mklabel gpt
        echo "Ignore" | parted /dev/sdb "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdc mklabel gpt
        echo "Ignore" | parted /dev/sdc "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdd mklabel gpt
        echo "Ignore" | parted /dev/sdd "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sde mklabel gpt
        echo "Ignore" | parted /dev/sde "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdf mklabel gpt
        echo "Ignore" | parted /dev/sdf "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdg mklabel gpt
        echo "Ignore" | parted /dev/sdg "mkpart primary ext4 2048s -1"

        echo "yes" |parted /dev/sdh mklabel gpt
        echo "Ignore" | parted /dev/sdh "mkpart primary ext4 2048s -1"

        partprobe
else
        exit
fi

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

if [ $fisk -ne 4 ] && [ $fisk -ne 8 ] ;then
   echo "error"
else
   echo "success"
fi


