mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-05-17 19:57:18 +00:00
e239e04843
Replace backtick command substitutions with $(), quote variable
expansions to prevent word splitting, replace useless cat pipes with
redirections, use grep -q instead of redirecting to /dev/null, and use
bash parameter expansion for case conversion.
Based on the work from PR #6366, rebased and adapted to current master.
Shebangs already merged separately via df64bf8fe are excluded.
Co-Authored-By: Samveen <samveen@yahoo.com>
111 lines
4.1 KiB
Bash
Executable File
111 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
XCATPORT=3001
|
|
export XCATPORT
|
|
|
|
ADAPTERFILE="/tmp/adapterinfo"
|
|
SCANNICLOG="/tmp/adapterscan.log"
|
|
|
|
rm -f "$SCANNICLOG" >/dev/null 2>&1
|
|
|
|
if [ -f "$ADAPTERFILE" ]; then
|
|
echo "rm -f $ADAPTERFILE" > "$SCANNICLOG"
|
|
rm -f "$ADAPTERFILE" >> "$SCANNICLOG" 2>&1
|
|
fi
|
|
|
|
echo "<xcatrequest>
|
|
<command>getadapter</command>
|
|
<action>update</action>" >> "$ADAPTERFILE"
|
|
|
|
# scan adapters that are recognized by operating system
|
|
for n in /sys/class/net/*; do
|
|
nic=${n##/sys/class/net/}
|
|
if [ "$nic" == "lo" ]; then
|
|
continue
|
|
else
|
|
echo '<nic>' >> "$ADAPTERFILE"
|
|
tmp="$(udevadm info "/sys/class/net/$nic" | awk -F '=' '/ INTERFACE/{print $2}')"
|
|
if [ -n "$tmp" ]; then
|
|
echo "<interface>$tmp</interface>" >> "$ADAPTERFILE"
|
|
fi
|
|
tmp="$(udevadm info "/sys/class/net/$nic" | awk -F '=' '/ID_NET_NAME/{print $2}'|sort -u| tr -s "\n" "/" | sed 's#/$##g')"
|
|
if [ -n "$tmp" ]; then
|
|
echo "<predictablename>$tmp</predictablename>" >> "$ADAPTERFILE"
|
|
fi
|
|
tmp="$(udevadm info "/sys/class/net/$nic" | awk -F 'devices' '/DEVPATH/{print $2}')"
|
|
if [ -n "$tmp" ]; then
|
|
echo "<pcilocation>${tmp%/net*}</pcilocation>" >> "$ADAPTERFILE"
|
|
fi
|
|
echo "<mac>$(cat "/sys/class/net/$nic/address")</mac>" >> "$ADAPTERFILE"
|
|
tmp="$(udevadm info "/sys/class/net/$nic" | awk -F '=' '/ID_VENDOR_FROM_DATABASE/{print $2}' | tr -s "\n" "/" | sed 's#/$##g')"
|
|
if [ -n "$tmp" ]; then
|
|
echo "<vendor>$tmp</vendor>" >> "$ADAPTERFILE"
|
|
fi
|
|
tmp="$(udevadm info /sys/class/net/"$nic" | awk -F '=' '/ID_MODEL_FROM_DATABASE/{print $2}')"
|
|
if [ -n "$tmp" ]; then
|
|
echo "<model>$tmp</model>" >> "$ADAPTERFILE"
|
|
fi
|
|
tmp="$(ip link show "$nic")"
|
|
if [ -n "$tmp" ]; then
|
|
tmp=${tmp#*state }
|
|
echo "<linkstate>${tmp% mode*}</linkstate>" >> "$ADAPTERFILE"
|
|
fi
|
|
echo '</nic>' >> "$ADAPTERFILE"
|
|
fi
|
|
done
|
|
|
|
for pci in $(lspci |awk '/Ethernet/ {print $1}'); do
|
|
if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then
|
|
tmp="$(lspci |grep "$pci")"
|
|
echo "<nic>
|
|
<pcilocation>$pci</pcilocation>
|
|
<model>${tmp##*:}</model>
|
|
</nic>" >> "$ADAPTERFILE"
|
|
fi
|
|
done
|
|
|
|
for pci in $(lspci |awk '/Network/ {print $1}'); do
|
|
if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then
|
|
tmp="$(lspci |grep "$pci")"
|
|
echo "<nic>
|
|
<pcilocation>$pci</pcilocation>
|
|
<model>${tmp##*: }</model>
|
|
</nic>" >> "$ADAPTERFILE"
|
|
fi
|
|
done
|
|
|
|
for pci in $(lspci |awk '/Mellanox/ {print $1}'); do
|
|
if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then
|
|
tmp="$(lspci |grep "$pci")"
|
|
echo "<nic>
|
|
<pcilocation>$pci</pcilocation>
|
|
<model>${tmp##*: }</model>
|
|
</nic>" >> "$ADAPTERFILE"
|
|
fi
|
|
done
|
|
|
|
echo "</xcatrequest>" >> "$ADAPTERFILE"
|
|
|
|
#cat "$ADAPTERFILE"
|
|
|
|
if [ -n "$XCATMASTER" ]; then
|
|
if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available
|
|
echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $XCATMASTER" >> "$SCANNICLOG"
|
|
openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1
|
|
else
|
|
echo "transmit scan result without customer certificate to $XCATMASTER" >> "$SCANNICLOG"
|
|
openssl s_client -connect $XCATMASTER:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1
|
|
fi
|
|
else
|
|
dhcps="$(awk -F ' |;' '/dhcp-server/ { print $(NF-1) }' /var/lib/dhclient/dhclient.leases | tail -n 1)"
|
|
if [ -n "$dhcps" ]; then
|
|
if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available
|
|
echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG"
|
|
openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1
|
|
else
|
|
echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG"
|
|
openssl s_client -connect $dhcps:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1
|
|
fi
|
|
fi
|
|
fi
|