#!/usr/bin/bash

root=/
[ -e /run/ostree-booted ] && root=/sysroot
echo "Resize $root"

part=$(findmnt -no SOURCE $root)
disk="${part:0:-2}"
partition="${part: -1}"
echo "Expanding $part (parition: $partition) to the max size of $disk"
growpart $disk $partition
if [ -e /run/ostree-booted ] && mount | grep -q "${root} .*ro,"; then
  echo "Remount $root rw"
  mount -o remount,rw $root
fi
resize2fs $part
