#!/bin/bash
#
#About this Scripts infomation
echo -e "\t\t#********************************************"
echo -e "\t\t# ScriptName: disk.sh                       #"
echo -e "\t\t# Author: Bai Shuming                       #"
echo -e "\t\t# Create Date: 2013-05-18                   #"
echo -e "\t\t# Modify Author:                            #"
echo -e "\t\t# Modify Date:                              #"
echo -e "\t\t# Function:                                 #"
echo -e "\t\t# Blog: biying.blog.51cto.com               #"
echo -e "\t\t#********************************************"

#set variable
PATH=`echo $PATH`
ID=`id |awk '{print $1}'|cut -b5`
FDISK="/sbin/fdisk"
COUNT=`cat disk.list|wc -l`
#CHECK OS SETUP
if [ $ID -ne 0 ]
   then
        echo "need root user"
        exit 10
fi

if [ ! -e $FDISK ]
   then
        echo "no found fdisk command"
fi

#set partition via fdisk command
fdisk -l |grep 'Disk'|awk '{print $2}'|cut -b8 > disk.list
for i in `cat disk.list`
do
  if [ ! -e /dev/sd$i[1-4] ]
 then        
       DISK=/dev/sd$i
       fdisk $DISK   << EOF
n
p
1


t
fd
w
EOF
fi
done

#Set Raid 5
mdadm -C /dev/md5 -l5 -n4 /dev/sd[b,c,d,e]1
echo "DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1" > /etc/mdadm.conf
mdadm -D  -s >> /etc/mdadm.conf

#Set lvm
pvcreate /dev/md5
vgcreate vfast /dev/md5
#Clean tmp file
rm -f disk.list
##
echo "disk setup OK"
exit 0