# This file is part of the 'dragora-installer'.
#
# Purpose: Mount root partition, device from declared fstab.

dialog --colors \
 --backtitle "\ZbRoot partition" \
 --title "ROOT MOUNT" --sleep 2 \
 --infobox "Preparing to mount designated root partition for installation..." 3 68

# Figure out device name from fstab
ROOT_DEVICE="$(awk '$2 == "/" { print $1 }' ${SUBTMPDIR}/fstab | cut -f 1 -d ' ')"

# Expose 'ROOT_DEVICE' for MenuBootloader
echo $ROOT_DEVICE > ${SUBTMPDIR}/root_device

# Create mount-point destination
mkdir -p -- /media/dragora-root

if mountpoint -q /media/dragora-root
then
    umount /media/dragora-root
fi
umount $ROOT_DEVICE > /dev/null 2>&1 || true

mount -v $ROOT_DEVICE /media/dragora-root | \
 dialog --colors \
  --backtitle "\ZbRoot partition: $ROOT_DEVICE" \
  --title "ROOT MOUNT" --sleep 1 \
  --programbox 5 58 || :

# This will be used later (e.g bootloader entry)
export ROOT_DEVICE

