#!/usr/bin/env python

# This script runs the --update and --abr commands from the FRU package install
# process across the entire cluster. This should be run after installing the
# update package.

import os
import sys

import isi_cto_lib as cto

UPDATE_CMD = "isi_for_array -X -s \"%s/isi_cto_update --update\""
ABR_CMD = "isi_for_array -X -s \"%s/isi_cto_update --abr --noprompt --nosendabr\""
GATHER_CMD = "isi_gather_info --nologs --group abr"

def main(argv):
    dirname = os.path.dirname(os.path.abspath(__file__))
    update_cmd = UPDATE_CMD % dirname
    abr_cmd = ABR_CMD % dirname
    err = 0
    err, out = cto.runCommand(update_cmd, needSudo = True)
    if not err:
        err, out  = cto.runCommand(abr_cmd, needSudo = True)
    if not err:
        err, out = cto.runCommand(GATHER_CMD, needSudo = True)
    return err

if __name__ == '__main__':
    main(sys.argv[1:])
