#!/bin/sh
#supports_backup in PINN

# NOOBS partition setup script for Arch Linux ARM
#  - part1 == boot partition (FAT), part2 == root partitions (ext4)
#  - example usage:
#    part1=/dev/mmcblk0p7 part2=/dev/mmcblk0p8 ./partition_setup.sh

# extract and set part1 and part2 variables

if [ ${part1} == '' || ${part2} == '' ]; then
  echo "error: part1 and part2 not specified"
  exit 1
fi

# create mount points
mkdir /tmp/1
mkdir /tmp/2

# mount partitions
mount ${part1} /tmp/1
mount ${part2} /tmp/2

if [ -z $restore ]; then
    mv /tmp/2/boot/* /tmp/1/
fi

# adjust files
sed /tmp/1/cmdline.txt -i -e "s|root=[^ ]*|root=${part2}|"
sed /tmp/2/etc/fstab -i -e "s|^[^#].* /boot |${part1}  /boot |"

# clean up
umount /tmp/1
umount /tmp/2
