Use xxd or hexdump, depending on OS

This commit is contained in:
Michael Boelen 2019-07-14 12:18:05 +02:00
parent 4829ae9722
commit ba32b1a001
No known key found for this signature in database
GPG Key ID: 26141F77A09D7F04
1 changed files with 12 additions and 2 deletions

View File

@ -43,8 +43,18 @@ if [ $# -gt 0 ]; then
fi
# Generate random host IDs
HOSTID=$(head -c20 < /dev/urandom | xxd -c 20 -p)
HOSTID2=$(head -c32 < /dev/urandom | xxd -c 32 -p)
case "${OS}" in
"AIX")
# hexdump does not exist on AIX
HOSTID=$(head -c20 < /dev/urandom | xxd -c 20 -p)
HOSTID2=$(head -c32 < /dev/urandom | xxd -c 32 -p)
;;
*)
# xxd does not exist on FreeBSD
HOSTID=$(head -c20 < /dev/urandom | hexdump -ve '"%.2x"')
HOSTID2=$(head -c32 < /dev/urandom | hexdump -ve '"%.2x"')
;;
esac
${ECHOCMD} "Generated host identifiers"
${ECHOCMD} "- hostid: ${HOSTID}"