2011-06-17 21:00:46 +00:00
|
|
|
#!/bin/sh
|
|
|
|
minixcatd.awk &
|
2011-09-16 22:55:25 +00:00
|
|
|
PUBKEY=`openssl rsa -in /etc/xcat/privkey.pem -pubout 2> /dev/null|grep -v "PUBLIC KEY"`
|
2011-08-31 14:11:49 +00:00
|
|
|
PUBKEY=`echo $PUBKEY|sed -e 's/ //g'`
|
|
|
|
export PUBKEY
|
2011-06-17 21:00:46 +00:00
|
|
|
|
|
|
|
echo "Beginning node discovery process"
|
|
|
|
waitforlink=100
|
|
|
|
while [ ! -z "$NICSTOBRINGUP" -a $waitforlink -gt 0 ]; do
|
|
|
|
NICSTOBRINGUP=`ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep -v ,LOWER_UP|awk -F: '{print $2}'`
|
2011-07-11 18:52:03 +00:00
|
|
|
waitforlink=$((waitforlink - 1))
|
2011-06-17 21:00:46 +00:00
|
|
|
sleep 0.1
|
|
|
|
if [ $waitforlink = 1 ]; then
|
|
|
|
echo "No link detected on $NICSTOBRINGUP"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
NICSGETTINGADDR=`ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep ,LOWER_UP|awk -F: '{print $2}'`
|
|
|
|
timewaiting=0
|
|
|
|
echo "Waiting for nics to get addresses"
|
|
|
|
while [ ! -z "$NICSGETTINGADDR" -a $timewaiting != 700 ]; do
|
|
|
|
NEWNICSGETTINGADDR=""
|
|
|
|
for nic in $NICSGETTINGADDR; do
|
|
|
|
if ! ip addr show dev $nic |grep -v inet6|grep inet >/dev/null; then
|
|
|
|
NEWNICSGETTINGADDR="$NEWNICSGETTINGADDR $nic"
|
|
|
|
else
|
|
|
|
echo -n "$nic|"
|
|
|
|
ip addr show dev $nic |grep -v inet6|grep inet|sed -e s/\\/.*//|awk '{print $2}'
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
sleep 0.1
|
|
|
|
timewaiting=$((timewaiting+1))
|
|
|
|
if [ $timewaiting = 699 ]; then
|
|
|
|
echo "No DHCP answer for $nic, ignoring interface"
|
|
|
|
fi
|
|
|
|
NICSGETTINGADDR=$NEWNICSGETTINGADDR
|
|
|
|
done
|
2011-09-16 22:55:25 +00:00
|
|
|
if [ $timewaiting != 700 -a $timewaiting -gt 450 ]; then
|
|
|
|
echo "Got an address, but it took inordinately long, you may want to check spanning tree configuration"
|
|
|
|
fi
|
2012-02-05 17:12:49 +00:00
|
|
|
echo "Network configuration complete, commencing transmit of discovery packets"
|
2011-07-11 18:52:03 +00:00
|
|
|
XCATPORT=3001
|
|
|
|
export XCATPORT
|
|
|
|
for parm in `cat /proc/cmdline`; do
|
|
|
|
key=`echo $parm|awk -F= '{print $1}'`
|
|
|
|
if [ "$key" = "xcatd" ]; then
|
|
|
|
XCATMASTER=`echo $parm|awk -F= '{print $2}'|awk -F: '{print $1}'`
|
|
|
|
XCATPORT=`echo $parm|awk -F= '{print $2}'|awk -F: '{print $2}'`
|
|
|
|
fi
|
|
|
|
done
|
2011-06-17 21:00:46 +00:00
|
|
|
|
|
|
|
|
2011-07-11 18:52:03 +00:00
|
|
|
#time to make our packet...
|
|
|
|
MTM=unknown
|
|
|
|
SERIAL=unknown
|
|
|
|
ARCH=unknown
|
|
|
|
ARCH=`uname -m` #32-bit only is old news
|
|
|
|
if [ -r /sys/devices/virtual/dmi/id/product_name ]; then #x86
|
|
|
|
PRODNAME=`cat /sys/devices/virtual/dmi/id/product_name`
|
|
|
|
IAMAVM=0
|
|
|
|
if [ "$PRODNAME" = "KVM" ]; then
|
|
|
|
IAMAVM=1
|
|
|
|
MTM=KVM
|
|
|
|
elif [ "$PRODNAME" = "VMware Virtual Platform" ]; then
|
|
|
|
IAMAVM=1
|
|
|
|
MTM=VMware
|
|
|
|
else
|
|
|
|
MTM=`cat /sys/devices/virtual/dmi/id/product_name|awk -F'[' '{print $2}'|awk -F']' '{print $1}'`
|
2012-04-30 13:25:19 +00:00
|
|
|
SERIAL=`cat /sys/devices/virtual/dmi/id/product_serial`
|
2011-07-11 18:52:03 +00:00
|
|
|
fi
|
|
|
|
elif [ -r /proc/device-tree/model ]; then #POWER
|
|
|
|
MTM=`cat /proc/device-tree/model |awk -F, '{print $2}'`
|
|
|
|
fi
|
|
|
|
CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l`
|
|
|
|
MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{print $2}'`
|
2012-03-06 15:55:30 +00:00
|
|
|
UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /sys/devices/virtual/dmi/id/product_uuid`
|
2011-07-11 18:52:03 +00:00
|
|
|
grep "model name" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing
|
|
|
|
echo $line > /tmp/cpumod
|
|
|
|
done
|
|
|
|
CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'`
|
|
|
|
echo '<xcatrequest>' > /tmp/discopacket
|
|
|
|
echo "<command>findme</command>" >> /tmp/discopacket
|
|
|
|
echo "<arch>$ARCH</arch>" >> /tmp/discopacket
|
2011-09-23 14:34:17 +00:00
|
|
|
if [ "$IAMAVM" = 1 ]; then
|
2011-07-11 18:52:03 +00:00
|
|
|
echo "<nodetype>virtual</nodetype>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
echo "<cpucount>$CPUCOUNT</cpucount>" >> /tmp/discopacket
|
|
|
|
echo "<cputype>$CPUTYPE</cputype>" >> /tmp/discopacket
|
|
|
|
echo "<memory>$MEMORY</memory>" >> /tmp/discopacket
|
2011-09-16 19:16:20 +00:00
|
|
|
echo "<uuid>$UUID</uuid>" >> /tmp/discopacket
|
2011-07-11 18:52:03 +00:00
|
|
|
if [ "$MTM" != "unknown" ]; then
|
|
|
|
echo "<mtm>$MTM</mtm>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
if [ "$SERIAL" != "unknown" ]; then
|
|
|
|
echo "<serial>$SERIAL</serial>"
|
|
|
|
fi
|
|
|
|
for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://`; do
|
|
|
|
DRIVER=`grep DRIVER /sys/class/net/$dev/device/uevent|awk -F= '{print $2}'`
|
|
|
|
ADDRESS=`ip address show dev $dev|grep "inet "|grep global|awk '{print $2}'`
|
2011-09-16 19:16:20 +00:00
|
|
|
MAC=`ip link show dev $dev|grep ether|awk '{print $2}'| tr /a-f/ /A-F/`
|
2011-09-12 13:48:06 +00:00
|
|
|
echo "<mac>$DRIVER|$dev|$MAC|$ADDRESS</mac>" >> /tmp/discopacket
|
2011-07-11 18:52:03 +00:00
|
|
|
done
|
|
|
|
echo "<xcatpubkey>$PUBKEY</xcatpubkey>" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security
|
|
|
|
echo "<sha512sig>" >> /tmp/discopacket
|
|
|
|
echo "</sha512sig>" >> /tmp/discopacket
|
|
|
|
echo "</xcatrequest>" >> /tmp/discopacket
|
|
|
|
openssl dgst -sha512 -out /tmp/discopacket.sha512 -sign /etc/xcat/privkey.pem /tmp/discopacket
|
|
|
|
openssl enc -e -a -in /tmp/discopacket.sha512 > /tmp/discopacket.b64sig
|
|
|
|
cat /tmp/discopacket |while read line; do
|
|
|
|
if [ "$line" = "</sha512sig>" ]; then
|
|
|
|
cat /tmp/discopacket.b64sig >> /tmp/discopacket.new
|
|
|
|
fi
|
|
|
|
echo $line >> /tmp/discopacket.new
|
|
|
|
done
|
|
|
|
mv /tmp/discopacket.new /tmp/discopacket
|
|
|
|
|
2011-06-17 21:00:46 +00:00
|
|
|
|
|
|
|
while [ ! -r /restart ]; do
|
2011-07-11 18:52:03 +00:00
|
|
|
if [ ! -z "$XCATMASTER" ]; then
|
2011-07-13 17:56:13 +00:00
|
|
|
(cat /tmp/discopacket | udpcat.awk $XCATMASTER $XCATPORT ) &
|
2011-07-11 18:52:03 +00:00
|
|
|
fi
|
|
|
|
for dhcps in `grep dhcp-server /var/lib/dhclient/dhclient.leases|awk '{print $4}'|sed -s 's/;//'`; do
|
2011-07-13 17:56:13 +00:00
|
|
|
(cat /tmp/discopacket | udpcat.awk $dhcps $XCATPORT ) &
|
2011-07-11 18:52:03 +00:00
|
|
|
done
|
2011-09-12 13:48:06 +00:00
|
|
|
#cat /tmp/discopacket
|
2011-07-11 18:52:03 +00:00
|
|
|
sleep 5
|
2011-06-17 21:00:46 +00:00
|
|
|
done
|
2011-09-02 17:18:01 +00:00
|
|
|
/bin/restart
|