Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

64 rindas
2.0 KiB

  1. #!/bin/bash
  2. POSITIONAL=()
  3. while [[ $# -gt 0 ]]
  4. do
  5. key="$1"
  6. case $key in
  7. -c|--certpath)
  8. CERTPATH="$2"
  9. shift # past argument
  10. shift # past value
  11. ;;
  12. -p|--nebulacertbinpath)
  13. NEBULACERTBINPATH="$2"
  14. shift # past argument
  15. shift # past value
  16. ;;
  17. -o|--outpath)
  18. OUTPATH="$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=$(${NEBULACERTBINPATH} print -path ${CERTPATH} -json | jq -s .[].details.name | sed 's/["]//g')
  35. #### TO-DO ####
  36. # Make NODEIPS an Array like NODEGROUPS
  37. NODEIPS=$(${NEBULACERTBINPATH} print -path ${CERTPATH} -json | jq -s --compact-output .[].details.ips | sed 's/[]["]//g')
  38. NODEGROUPS=$(${NEBULACERTBINPATH} print -path ${CERTPATH} -json | jq -s --compact-output .[].details.groups | sed 's/[]["]//g') # | sed 's/,/ /g'))
  39. CERTISCASTATUS=$(${NEBULACERTBINPATH} print -path ${CERTPATH} -json | jq -s --compact-output .[].details.isCa)
  40. # Create new file name variable
  41. NEWFILENAME="${NODENAME}_${DATETIME}"
  42. if [[ $CERTISCASTATUS == true ]]; then
  43. echo "Certificate is the root CA Certificate. Try again with a node certificate."
  44. exit
  45. fi
  46. if [[ $CERTISCASTATUS == false ]]; then
  47. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  48. echo "Node Name: ${NODENAME}"
  49. echo "Node IPs: ${NODEIPS}"
  50. echo "Node Groups: ${NODEGROUPS[@]}"
  51. echo "Certificate isCa Status: ${CERTISCASTATUS}"
  52. echo "DateTime: ${DATETIME}"
  53. echo "NEWFILENAME: ${NEWFILENAME}"
  54. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  55. ${NEBULACERTBINPATH} sign -groups ${NODEGROUPS[@]} -ip ${NODEIPS} -name ${NODENAME} -out-crt ${OUTPATH}/${NEWFILENAME}.crt -out-key ${OUTPATH}/${NEWFILENAME}.key
  56. fi