#!/bin/sh
# This script will attempt to resize the partition in order to fill the sdcard
# Credits to rpi-distro https://github.com/RPi-Distro/raspi-config/
# Based on resize-fs from manjaro-system package
# https://gitlab.manjaro.org/manjaro-arm/packages/core/manjaro-system
# For resize rootfs use systemd-growfs@-.service
# Set x-systemd.growfs option in /etc/fstab for rootfs, like this:
# /dev/mmcblk0p2	/	ext4	defaults,x-systemd.growfs	1 1

# Get device and partition numbers/names
 # Root Partition
  PART_DEV=`findmnt / -o source -n`
 
 # Remove '/dev/' from the name 
  PART_NAME=`echo $PART_DEV | cut -d "/" -f 3`
 
 # Set just the name of the device, usually mmcblk0
  DEV_NAME=`echo /sys/block/*/${PART_NAME} | cut -d "/" -f 4`

 # Add /dev/ to device name
  DEV="/dev/${DEV_NAME}"

 # Get Number of device as single digit integer
  PART_NUM=`cat /sys/block/${DEV_NAME}/${PART_NAME}/partition`

# resize the partition
echo ", +" | sfdisk --no-reread -N $PART_NUM $DEV
