#!/bin/sh

# Copyright (C) 2018 Cumulus Networks, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# https://www.gnu.org/licenses/gpl-2.0-standalone.html

# set/query ONIE NOS install mode

# This operation requires root privileges
if [ $(id -u) -ne 0 ] ; then
    echo "ERROR: This command requires root privileges"
    exit 1
fi

. /usr/lib/cumulus/onie/onie-tools-common

cl_mount_onie_tools rw || {
    echo "ERROR: Mounting ONIE tools read-write failed" >&2
    exit 1
}

if [ -x "$onie_tool_dir/onie-nos-mode" ] ; then
    # Use the onie-nos-mode command that comes with the ONIE tools
    # package from the ONIE distribution.
    $onie_tool_dir/onie-nos-mode "$@"
else
    echo "Notice: The current ONIE installation does not support this operation."
fi

cl_umount_onie_tools
