#!/usr/bin/env bash

# this is almost just a list of commands to run and the order to run them in. All manners of checks need
# to be written, and we are obviously operating in a way that involves deleting partitions - so
# -------------- THIS IS NOT PRODuCTION SAFE ------------

# ----- SERIOUSLY CHRIS, READ THE NOTE ABOVE

ROOT_DEVICE_PATH="/dev/vda"
ROOT_PART_TO_EXPAND="3"

sfdisk --delete $"ROOT_PART_TO_EXPAND"

# resize partition table
echo ", +" | sfdisk --no-reread -N $ROOT_PART_TO_EXPAND $ROOT_DEVICE_PATH

#call partprobe to make sure we re-read the new parition table
partprobe
# resize physical volume
pvresize /dev/vda3
#resize logical volume
lvm lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
#extend partition
resize2fs -p /dev/mapper/ubuntu--vg-ubuntu--lv
