#!/bin/bash

sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/50-cloud-init.conf
service sshd restart


device=`fdisk -l |grep LVM | awk '{print $1}'`

if [[ ${device} == "/dev/sda3" ]]; then

   Current_Size_S=$(df -Th |grep sysvg | awk '{print $3}'| cut -f 1 -d 'G' | cut -f 1 -d '.')
   size1=`expr $Current_Size_S`
   newsize=$(fdisk -l | grep "Disk /dev/sda" | awk '{print $3}'| cut -f 1 -d '.')
   size2=`expr $newsize`

   if [ $size1 -lt $size2 ]; then
        echo "need expand disk"
	    printf "fix\n" | parted ---pretend-input-tty /dev/sda print
        parted /dev/sda resizepart 3 100%
	    lvm pvresize -v /dev/sda3
	    lvextend -l +100%FREE /dev/sysvg/root
	    xfs_growfs /dev/sysvg/root
    else
	  echo "no need expand disk"
    fi
elif [[ ${device} == "/dev/vda3" ]]; then
      Current_Size_S=$(df -Th |grep sysvg | awk '{print $3}'| cut -f 1 -d 'G' | cut -f 1 -d '.')
   size1=`expr $Current_Size_S`
   newsize=$(fdisk -l | grep "Disk /dev/vda" | awk '{print $3}'| cut -f 1 -d '.')
   size2=`expr $newsize`

   if [ $size1 -lt $size2 ]; then
        echo "need expand disk"
	    printf "fix\n" | parted ---pretend-input-tty /dev/vda print
        parted /dev/vda resizepart 3 100%
	    lvm pvresize -v /dev/vda3
	    lvextend -l +100%FREE /dev/sysvg/root
	    xfs_growfs /dev/sysvg/root
    else
	  echo "no need expand disk"
    fi
else
    echo "Is there third way?"
fi

