#!/bin/bash
vg_name=$(vgdisplay |awk '/VG Name/{print $NF}'| head -n 1)
pv_num=$(lsblk | grep -c "vda")
lv_name=$(lvdisplay |awk '/LV Name/{print $NF}'| head -n 1)
disk_size=$(lsblk | awk '/^vda/{print $4}')
if [ "20G" = "${disk_size}" ]; then
rm -f $0
exit 0
fi
fdisk -l 2>/tmp/status
if [ -s "/tmp/status" ]; then
/usr/bin/expect <<EOF
spawn parted -l
expect {
    "OK/Cancel? " {send "OK\n"}
    "Fix/Ignore? " {send "Fix\n"}
}
expect off
EOF
fi
rm -rf /tmp/status
cat > /tmp/partition << EOF
n
p
${pv_num}


w
q
EOF
fdisk /dev/vda < /tmp/partition
partprobe
rm -rf /tmp/partition
pvcreate /dev/vda${pv_num}
vgextend ${vg_name} /dev/vda${pv_num}
lvextend -l +100%FREE /dev/${vg_name}/${lv_name}
file_sys=$(grep -Ev '^$|^#' /etc/fstab | awk '/boot/{print $3}')
if [ "xfs" = "${file_sys}" ];then
xfs_growfs /dev/${vg_name}/${lv_name}
else
resize2fs /dev/${vg_name}/${lv_name}
fi
rm -f $0
