98 lines
2.7 KiB
Bash
Executable File
98 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
error_exit() {
|
|
echo "ERROR: $*"
|
|
exit 1
|
|
}
|
|
|
|
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
|
|
|
|
set -x
|
|
|
|
IP="{{$.IpmiIpaddr}}"
|
|
NETMASK="{{$.IpmiNetmask}}"
|
|
[ -z "$NETMASK" ] && NETMASK="{{$.NetDevs.eth0.Netmask}}"
|
|
GATEWAY="{{$.IpmiGateway}}"
|
|
[ -z "$GATEWAY" ] && GATEWAY="{{$.NetDevs.eth0.Gateway}}"
|
|
USER="{{$.IpmiUserName}}"
|
|
PASS="{{$.IpmiPassword}}"
|
|
|
|
echo IP is $IP
|
|
echo NETMASK is $NETMASK
|
|
echo GATEWAY is $GATEWAY
|
|
echo USER is $USER
|
|
echo PASS is $PASS
|
|
|
|
if [ -z "$IP" ]; then
|
|
error_exit "No IPMI IP address supplied, skipping IPMI configuration"
|
|
fi
|
|
|
|
modprobe ipmi_si
|
|
modprobe ipmi_ssif
|
|
modprobe ipmi_devintf
|
|
modprobe ipmi_msghandler
|
|
|
|
if [ ! -e /dev/ipmi0 ]; then
|
|
sleep 1
|
|
ipmi_dev=$(grep ipmidev /proc/devices | awk '{ print $1; }')
|
|
mknod -m 0666 /dev/ipmi0 c $ipmi_dev 0
|
|
ls -la /dev/ipmi0
|
|
fi
|
|
|
|
x=$(ipmitool lan print 1)
|
|
PREV_IP=$(echo "$x" | grep "^IP Address " | awk '{ print $4; }')
|
|
PREV_NETMASK=$(echo "$x" | grep "^Subnet Mask" | awk '{ print $4; }')
|
|
PREV_GATEWAY=$(echo "$x" | grep "^Default Gateway IP" | awk '{ print $5; }')
|
|
echo PREV_IP is $PREV_IP
|
|
echo PREV_NETMASK is $PREV_NETMASK
|
|
echo PREV_GATEWAY is $PREV_GATEWAY
|
|
|
|
# Network
|
|
if [ "$PREV_IP" != "$IP" -o "$PREV_NETMASK" != "$NETMASK" -o "$PREV_GATEWAY" != "$GATEWAY" ]; then
|
|
ipmitool lan set 1 access on
|
|
ipmitool lan set 1 ipsrc static
|
|
ipmitool lan set 1 ipaddr $IP
|
|
ipmitool lan set 1 netmask $NETMASK
|
|
ipmitool lan set 1 defgw ipaddr $GATEWAY
|
|
fi
|
|
|
|
# User
|
|
if [ "$USER" != "" ]; then
|
|
PREV_USER=$(ipmitool user list | grep "^2 " | awk '{ print $2; }')
|
|
TEST_PASSWORD=$(ipmitool user test 2 20 $PASS)
|
|
if [ "$USER" != "$PREV_USER" -o "$TEST_PASSWORD" != "Success" ]; then
|
|
ipmitool user set name 2 $USER
|
|
ipmitool user set password 2 $PASS
|
|
sleep 1
|
|
ipmitool user priv 2 4 1
|
|
ipmitool user enable 2
|
|
fi
|
|
fi
|
|
|
|
# Authentication
|
|
#ipmitool lan set 1 auth user md5,password
|
|
#ipmitool lan set 1 auth operator md5,password
|
|
#ipmitool lan set 1 auth admin md5,password
|
|
#ipmitool user enable 1
|
|
#ipmitool user priv 1 4 1
|
|
|
|
# Authentication (allow None)
|
|
#ipmitool lan set 1 auth user none,md5,password
|
|
#ipmitool lan set 1 auth operator none,md5,password
|
|
#ipmitool lan set 1 auth admin none,md5,password
|
|
#ipmitool user enable 1
|
|
#ipmitool user priv 1 4 1
|
|
|
|
# Serial Over LAN
|
|
ipmitool channel setaccess 1 2 link=on ipmi=on callin=on privilege=4
|
|
ipmitool sol set force-encryption true 1
|
|
ipmitool sol set force-authentication true 1
|
|
ipmitool sol set privilege-level admin 1
|
|
#ipmitool sol payload enable 1 4
|
|
ipmitool sol payload enable 1 2 1
|
|
ipmitool sol set enabled true 1 1
|
|
speed=38.4 # 19.2 38.4 115.2
|
|
ipmitool sol set non-volatile-bit-rate $speed 1
|
|
ipmitool sol set volatile-bit-rate $speed 1
|
|
|