#!/bin/bash

uuid_of_partition() {
    local label="$1"
    blkid | grep "LABEL=\"$label\"" | sed -e 's/^.* UUID="//' -e 's/".*$//'
}

createMountPointForNextBootPartition()
{
    mountpoint=$1
    mkdir -p $mountpoint

    # Determine the next boot partition UUID and update cmdline accordingly
    next_boot_uuid=$( grep UUID= /boot/grub/grub.cfg | head -1 | sed -e 's/^.*root=UUID=//' -e 's/ .*$//' )
    echo "Next boot UUID is $next_boot_uuid"

    # Determine the label corresponding to the next boot partition
    if [ "$next_boot_uuid" = "$(uuid_of_partition CL-SYSTEM-1)" ]; then
        next_boot_partition_label="LABEL=CL-SYSTEM-1"
    else
        next_boot_partition_label="LABEL=CL-SYSTEM-2"
    fi

    # Mount the label corresponding to the next boot partition
    echo "Next boot partition label: ${next_boot_partition_label} Mount point: ${mountpoint}"
    mount $next_boot_partition_label $mountpoint
}
