#!/bin/bash
BMCUpdating() {
	bin_file=`ls *_BMC_*`
	chmod +x socflash_x64
	ipmitool raw 0x3c 0x3a 0x1e 0x00
	echo YY|./socflash.sh if=$bin_file
}

UserSetting() {
	ipmitool user list 1 |grep root
	if [ $? = 0 ];then
		echo "Root user is existed..."
	else
		#//Delete the default user "Admin"
		ipmitool raw 0x06 0x45 0x01 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
		sleep 3
		echo "*** Config User related settings ***"
		#//Create new user named "root"
		ipmitool user set name 2 root
		#//Enabled the new user
		ipmitool user enable 2
		#//Set new password to root
		ipmitool user set password 2 ucloud.cn
		#//Set the administrator priv to root
		ipmitool user priv 2 4 1
		#//Set the highest access priv to root
		ipmitool channel setaccess 1 2 callin=on link=on ipmi=on
		echo "Modified KVM using privilege"
		if [ $(ipmitool raw 0x32 0xa4 0x02 |awk -F " " '{print$1}') = 03 ];then
        		echo "The KVM privilege has been set for root user"
		else
        		ipmitool raw 0x32 0xA3 0x02 0x03 0x00 0x00 0x00   #附予kvm权限
		fi
	fi
}

Changeimage() {
	ipmitool raw 0x32 0x8F 0x01 0x04
}

BMCUpdating
sleep 100
UserSetting	
sleep 3
Changeimage
