# -*- mode: shell-script; sh-shell: sh -*-

################################################################################
#
# Copyright (C) 2014 Cumulus Networks Inc. All rights reserved
#
################################################################################

# Common shell script functions for interacting with ONIE

onie_boot_mnt="/mnt/onie-boot"
onie_tool_dir="${onie_boot_mnt}/onie/tools/bin"
onie_grub_d_dir="${onie_boot_mnt}/onie/grub.d"

# Clean up mounted ONIE partition on exit
cl_umount_onie_tools()
{
    umount $onie_boot_mnt > /dev/null 2>&1
}

# Prepare the onie tools for use
cl_mount_onie_tools()
{
    local mount_opt="${1:-ro}"

    mkdir -p "$onie_boot_mnt"
    trap cl_umount_onie_tools EXIT

    mount -o defaults,$mount_opt LABEL=ONIE-BOOT $onie_boot_mnt > /dev/null 2>&1 || {
        echo "ERROR: Problems mounting ONIE-BOOT on $onie_boot_mnt"
        return  1
    }
}
