function kgencert () { local node=$1 local ip=$2 local pwd pwd=$(pwd) base=$(basename "$pwd") if [[ -z $XENDIR ]]; then echo XENDIR must be set return 1 fi if [[ $pwd != "$XENDIR/guests/$base" ]]; then echo You should be in a guests subdirectory! return 1 fi if [[ ! -f "$XENDIR/guests/$base/$node.cfg" ]]; then echo "$node.cfg" not found! return 1 fi if [[ -z $ip ]]; then if [[ ! -f /var/lib/dnsmasq/virbr1/hostsfile ]]; then echo Missing dnsmasq hosts file and no IP passed return 1 fi mac=$(awk "\$1 == \"vif\" { gsub(/'mac=/, \"\"); gsub(/,*model.*/, \"\"); print \$4 }" < "$1.cfg") ip=$(grep "$mac" /var/lib/dnsmasq/virbr1/hostsfile) if [[ -z $ip ]]; then echo The node\'s mac address "$mac" is not present in the dnsmasq hosts file return 1 fi IFS=',' read -ra IPS <<< "$ip" ip=${IPS[1]} fi mkdir -p ./certs if [[ ! -f ./certs/ca-csr.json ]]; then cat > ./certs/ca-csr.json < ./certs/ca-config.json <