You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update-NebulaNodeCert 2.0 KiB

3 年之前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. POSITIONAL=()
  3. while [[ $# -gt 0 ]]
  4. do
  5. key="$1"
  6. case $key in
  7. -c|--nodecertpath)
  8. NODECERTPATH="$2"
  9. shift # past argument
  10. shift # past value
  11. ;;
  12. -b|--nebulacertbinpath)
  13. NEBULACERTBINPATH="$2"
  14. shift # past argument
  15. shift # past value
  16. ;;
  17. -r|--rootpath)
  18. ROOTPATH="$2"
  19. shift # past argument
  20. shift # past value
  21. ;;
  22. *) # unknown option
  23. POSITIONAL+=("$1") # save it in an array for later
  24. shift # past argument
  25. ;;
  26. esac
  27. done
  28. set -- "${POSITIONAL[@]}" # restore positional parameters
  29. if [[ -n $1 ]]; then
  30. echo "Invalid Parameter(s) Entered: $1"
  31. exit
  32. fi
  33. DATETIME=$(date '+%Y%m%d-%H%M%S')
  34. NODENAME=$(${ROOTPATH}/nebula-cert print -path ${NODECERTPATH} -json | jq -s .[].details.name | sed 's/["]//g')
  35. NODEIPS=$(${ROOTPATH}/nebula-cert print -path ${NODECERTPATH} -json | jq -s --compact-output .[].details.ips | sed 's/[]["]//g')
  36. NODEGROUPS=$(${ROOTPATH}/nebula-cert print -path ${NODECERTPATH} -json | jq -s --compact-output .[].details.groups | sed 's/[]["]//g') # | sed 's/,/ /g'))
  37. CERTISCASTATUS=$(${ROOTPATH}/nebula-cert print -path ${NODECERTPATH} -json | jq -s --compact-output .[].details.isCa)
  38. # Create new file name variable
  39. NEWFILENAME="${NODENAME}_${DATETIME}"
  40. if [[ $CERTISCASTATUS == true ]]; then
  41. echo "Certificate is the root CA Certificate. Try again with a node certificate."
  42. exit
  43. fi
  44. if [[ $CERTISCASTATUS == false ]]; then
  45. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  46. echo "Node Name: ${NODENAME}"
  47. echo "Node IPs: ${NODEIPS}"
  48. echo "Node Groups: ${NODEGROUPS[@]}"
  49. echo "Certificate isCa Status: ${CERTISCASTATUS}"
  50. echo "DateTime: ${DATETIME}"
  51. echo "NEWFILENAME: ${NEWFILENAME}"
  52. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  53. ${ROOTPATH}/nebula-cert sign -groups ${NODEGROUPS[@]} -ip ${NODEIPS} -name ${NODENAME} -ca-crt ${ROOTPATH}/ca.crt -ca-key ${ROOTPATH}/ca.key -out-crt ${ROOTPATH}/${NEWFILENAME}.crt -out-key ${ROOTPATH}/${NEWFILENAME}.key
  54. fi