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.

67 lines
2.1 KiB

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