#!/bin/bash # Copyright (C) 2019 Mellanox Technologies Ltd. # Copyright (C) 2019 Michael Shych # # SPDX-License-Identifier: GPL-2.0 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 system_reboot 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}