Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

97 righe
2.9 KiB

  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. POSITIONAL=()
  10. while [[ $# -gt 0 ]]
  11. do
  12. key="$1"
  13. case $key in
  14. -h|--help)
  15. help_msg
  16. ;;
  17. -n|--caname)
  18. CANAME="$2"
  19. shift # past argument
  20. shift # past value
  21. ;;
  22. -r|--rootpath)
  23. ROOTPATH="$2"
  24. shift # past argument
  25. shift # past value
  26. ;;
  27. -f|--cafilename)
  28. CAFILENAME="$2"
  29. shift # past argument
  30. shift # past value
  31. ;;
  32. # -k|--cakeyname)
  33. # CAKEYNAME="$2"
  34. # shift # past argument
  35. # shift # past value
  36. # ;;
  37. -i|--issuer)
  38. ISSUER="$2"
  39. shift # past argument
  40. shift # past value
  41. ;;
  42. *) # unknown option
  43. invalid_args_msg #catch all
  44. ;;
  45. esac
  46. done
  47. set -- "${POSITIONAL[@]}" # restore positional parameters
  48. invalid_args_msg () {
  49. echo "Invalid Parameter(s) Entered: $1"
  50. exit
  51. }
  52. help_msg () {
  53. echo "Usage of refresh-NebulaCA <flags>: refresh an existing nebula ca"
  54. echo " -n|--caname"
  55. echo " Name to use for the new CA. Used in the CA cert file and in the filename"
  56. echo " -r|--rootpath"
  57. echo " Root path of existing CA"
  58. echo " -f|--cafilename"
  59. echo " Filename of the existing CA"
  60. echo " -i|--issuer"
  61. echo " Name of the Org Issuing and authorizing the creation of the new Nebula CA"
  62. echo " -h|--help"
  63. echo " This help text, but you already knew that... right?!?!"
  64. exit
  65. }
  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