2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-05-17 11:54:16 +00:00
Files
xcat-core/xCAT-genesis-scripts/usr/bin/nextdestiny
T
Vinícius Ferrão e239e04843 genesis-scripts: improve shell quoting and syntax hygiene
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>
2026-05-07 18:17:00 -03:00

37 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
if [ -z "$XCATDEST" ]; then
XCATDEST=$1
fi
echo "<xcatrequest>
<command>nextdestiny</command>
<callback_port>300</callback_port>
</xcatrequest>" > /tmp/destreq.xml
if [ -f /tmp/destiny.xml ]; then rm /tmp/destiny.xml; fi
timer=0
while [ ! -f /tmp/destiny.xml ]; do
while [ $timer -gt 0 ]; do
echo -en "No destiny command received, retrying in $timer seconds \r" >&2
sleep 1
timer=$(($timer-1));
done
echo " " >&2;
if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available
openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/destreq.xml > /tmp/destiny.xml
else
openssl s_client -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/destreq.xml > /tmp/destiny.xml
fi
timer=60
done
rm /tmp/destreq.xml
DESTINY="$(grep '<destiny>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}')"
if [ -z "$DESTINY" ]; then
ERROR="$(grep '<error>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}')"
if [ ! -z "$ERROR" ]; then
DESTINY="error=$ERROR"
else
DESTINY="error=No destiny command received"
fi
fi
rm /tmp/destiny.xml
echo "$DESTINY"