1
0

prepare-slot-certs 1.1 KB

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