prepare-slot-certs 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. source "${SNAP}/init"
  3. if ! [[ -d "${SSL_DIR}" ]]; then
  4. logger "Creating local cert dir ${SSL_DIR}"
  5. mkdir "${SSL_DIR}"
  6. fi
  7. logger "Creating connection from ${SNAP_NAME} (uuid: ${UUID})"
  8. KEY=`gpg --armor --export "${UUID}"`
  9. if [ -z "${KEY}" ]; then
  10. gpg_start_agent
  11. logger "Create GPG-key"
  12. gpg --batch --no-tty --gen-key <<< "
  13. %echo Generating a basic OpenPGP key
  14. Key-Type: default
  15. Subkey-Type: default
  16. Name-Real: ${SNAP_NAME}
  17. Name-Email: ${UUID}@${SNAP_NAME}.gpg
  18. Name-comment: Generated from ${SNAP_NAME} for certs-slot
  19. Expire-Date: 0
  20. %no-protection
  21. %commit
  22. %echo done"
  23. gpg_close_agent
  24. fi
  25. KEY=`gpg --armor --export "${UUID}"`
  26. if [ $? -ne 0 ]; then
  27. echo "Failed to create GPG-key"
  28. logger "Failed to create GPG-key for ${UUID}"
  29. exit 1
  30. fi
  31. snapctl set :certs snapname="${SNAP_NAME}"
  32. snapctl set :certs uuid="${UUID}"
  33. snapctl set :certs pkey="${KEY}"
  34. logger "${SNAP_NAME}:certs (uuid: ${UUID}) prepared"
  35. logger "KEY: ${KEY}"