您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

refresh-NebulaCA 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. ######################################################
  3. # Name: refresh-NebulaCA
  4. # Description: Creates a new cert for a node based
  5. # on the node cert provided.
  6. #
  7. # Created By: HMSheets
  8. ######################################################
  9. invalid_args_msg () {
  10. echo "Invalid Parameter(s) Entered: $1"
  11. exit
  12. }
  13. help_msg () {
  14. echo "Usage of refresh-NebulaCA <flags>: refresh an existing nebula ca"
  15. echo " -n|--caname"
  16. echo " Name to use for the new CA. Used in the CA cert file and in the filename"
  17. echo " -r|--rootpath"
  18. echo " Root path of existing CA"
  19. echo " -f|--cafilename"
  20. echo " Filename of the existing CA"
  21. echo " -i|--issuer"
  22. echo " Name of the Org Issuing and authorizing the creation of the new Nebula CA"
  23. echo " -h|--help"
  24. echo " This help text, but you already knew that... right?!?!"
  25. exit
  26. }
  27. POSITIONAL=()
  28. while [[ $# -gt 0 ]]
  29. do
  30. key="$1"
  31. case $key in
  32. -h|--help)
  33. help_msg
  34. ;;
  35. -n|--caname)
  36. CANAME="$2"
  37. shift # past argument
  38. shift # past value
  39. ;;
  40. -r|--rootpath)
  41. ROOTPATH="$2"
  42. shift # past argument
  43. shift # past value
  44. ;;
  45. -f|--cafilename)
  46. CAFILENAME="$2"
  47. shift # past argument
  48. shift # past value
  49. ;;
  50. # -k|--cakeyname)
  51. # CAKEYNAME="$2"
  52. # shift # past argument
  53. # shift # past value
  54. # ;;
  55. -i|--issuer)
  56. ISSUER="$2"
  57. shift # past argument
  58. shift # past value
  59. ;;
  60. *) # unknown option
  61. invalid_args_msg #catch all
  62. ;;
  63. esac
  64. done
  65. set -- "${POSITIONAL[@]}" # restore positional parameters
  66. DATETIME=$(date '+%Y%m%d-%H%M%S')
  67. #CANAME=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s .[].details.name | sed 's/["]//g')
  68. #CAIPS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s --compact-output .[].details.ips | sed 's/[]["]//g')
  69. #NODEGROUPS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s --compact-output .[].details.groups | sed 's/[]["]//g') # | sed 's/,/ /g'))
  70. CERTISCASTATUS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${CAFILENAME} -json | jq -s --compact-output .[].details.isCa)
  71. # Create new file name variable
  72. NEWFILENAME="${CANAME}_${DATETIME}"
  73. if [[ $CERTISCASTATUS == false ]]; then
  74. echo "Certificate is a Node Certificate. Try again by providing the CA Certificate."
  75. exit
  76. fi
  77. if [[ $CERTISCASTATUS == true ]]; then
  78. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  79. echo "Node Name: ${CANAME}"
  80. echo "Node IPs: ${ISSUER}"
  81. #echo "Node Groups: ${NODEGROUPS[@]}"
  82. echo "Certificate isCa Status: ${CERTISCASTATUS}"
  83. echo "DateTime: ${DATETIME}"
  84. echo "NEWFILENAME: ${NEWFILENAME}"
  85. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  86. ${ROOTPATH}/nebula-cert sign -name ${CANAME} -out-crt ${ROOTPATH}/${NEWFILENAME}.crt -out-key ${ROOTPATH}/${NEWFILENAME}.key
  87. fi