#!/bin/bash # # Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES. # Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # this_script="$(basename $(realpath ${0}))" lock_file="/var/run/${this_script%.*}.lock" onie_mount=/mnt/onie-boot onie_lib=/lib/onie os_boot=/host print_help() { cat <${lock_file} /usr/bin/flock -x ${lock_fd} register_unlock_handler ${lock_fd} } # Multiprocessing synchronization lock_script_state_change # Process command arguments cmd="${1}" # Optional argument arg="${2}" if [[ -z "${cmd}" ]]; then # Default to 'show' if no command is specified. cmd="show" fi case "${cmd}" in add|remove) if [[ -z "${arg}" ]]; then echo "ERROR: This command requires a firmware update file name" echo "Run: '${this_script} help' for complete details" exit 1 fi ;; update) enable_onie_access show_pending rc=$? if [[ ${rc} -ne 0 ]]; then enable_onie_fw_update_mode rc=$? disable_onie_access if [[ ${rc} -eq 0 ]]; then if [[ "${arg}" == "--no-reboot" ]]; then echo "INFO: ONIE firmware update successfully STAGED for install at NEXT reboot. Please reboot manually to complete installation." exit 0 else system_reboot fi else echo "ERROR: failed to enable ONIE firmware update mode" exit ${rc} fi else echo "ERROR: No firmware images for update" echo "Run: '${this_script} add ' before update" disable_onie_access exit 1 fi ;; purge|show-pending|show-results|show|show-log|help) ;; *) echo "ERROR: Unknown command: ${cmd}" exit 1 ;; esac enable_onie_access ${onie_mount}/onie/tools/bin/onie-fwpkg "$@" rc=$? if [[ "${cmd}" = "help" ]]; then print_help fi disable_onie_access exit ${rc}