2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-21 23:28:19 +00:00
Files
xcat-core/xCAT-genesis-scripts/usr/bin/nextdestiny
T
2026-10-13 22:16:49 -03:00

89 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -u
metadata_file=
metadata_temporary=
once=0
destination=${XCATDEST:-}
request_pid=
usage() {
printf '%s\n' 'Usage: nextdestiny [ENDPOINT] [--metadata FILE] [--once]' >&2
exit 2
}
while (($# > 0)); do
case "$1" in
--metadata)
(($# >= 2)) || usage
metadata_file=$2
shift 2
;;
--once)
once=1
shift
;;
--)
shift
(($# <= 1)) || usage
if (($# == 1)); then
destination=$1
fi
break
;;
-*) usage ;;
*)
if [[ -z $destination ]]; then
destination=$1
fi
shift
;;
esac
done
[[ -n $destination ]] || usage
source "$(dirname -- "${BASH_SOURCE[0]}")/../lib/xcat/destiny.sh" || exit 1
temporary_dir=$(mktemp -d "${TMPDIR:-/tmp}/nextdestiny.XXXXXX") || exit 1
request_file=$temporary_dir/request.xml
response_file=$temporary_dir/response.xml
trap cleanup EXIT
trap 'terminate 129' HUP
trap 'terminate 130' INT
trap 'terminate 143' TERM
printf '%s\n' \
'<xcatrequest>' \
'<command>nextdestiny</command>' \
'<callback_port>300</callback_port>' \
'</xcatrequest>' >"$request_file"
request_destiny() {
send_destiny_request || true
[[ -s $response_file ]]
}
if ((once)); then
request_destiny \
&& { grep -q '<destiny>' "$response_file" \
|| grep -q '<error>' "$response_file"; } \
|| exit 1
else
request_destiny || true
fi
destiny=$(extract_element destiny)
if [[ -z $destiny ]]; then
error=$(extract_element error)
[[ -n $error ]] || error='No destiny command received'
destiny="error=$error"
fi
if [[ -n $metadata_file ]]; then
write_metadata nextdestiny
fi
printf '%s\n' "$destiny"