#!/bin/bash
#
# ======================================================
# VI editor settings
# set shiftwidth=4
# set tabstop=4
# ======================================================
# Title: List ILOM/BMC users and permissions on a node
# Author: Mike Gore
# Author: Mike Gore
# Date: 25 Oct 2016
# Depends: 
#   package: openmpi
#   scripts: ipmifunctions, common_host,common_vars,common_functions and NODES found in /usr/local/bin
#
#
# Example: ./ipmiuserlist host-ilom
#           - Where host-ilom is the node ILOM/BMC interface
#           - needs and AMDIN user and password to function
# Result: List ILOM/BMC users permissions on  a node
#
# Notes:
#        The script will prompt for ADMIN user and password unless the following environment variables are set:
# ADMIN - userid of ADMIN user
# ADMINPASS - Password of "ADMIN" user
# ======================================================
# BASH functions
. common_functions
#IPMI functions
. ipmifunctions

#VARS:
export ADMIN ADMINPASS OLDADMINPASS CSCFADM CSCFADMPASS OTHERUSER OTHERPASS
# ======================================================
#Check if LOM is online
LOM="$1"
if ! lom_check "$LOM"
then
        fatal "LOM $LOM is not responding"
fi

if [ -z "$2" ]
then
	fatal "expected user number"
fi
USERNUM="$2"


# Set admin password
setadmin
echo Set Privilege Levels for user $USERNUM
#  1=Callback level, 2=User level, 3= Operator level, 4=Administrator level
# priv <userid> <privilege level> [<channel number>]
if ! ipmitool $LOMHOST -U "$ADMIN" -P "$ADMINPASS" user priv "$USERNUM" 2 1
then
	warn "user privilage update failed for $USERNAME"
fi

echo User disable $USERNUM
if ! ipmitool $LOMHOST -U "$ADMIN" -P "$ADMINPASS" user disable "$2"
then
	warn "user disable failed for [$2]"
fi
echo User List
ipmiuserlist "$LOM"