prepare-slot-certs 895 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. CERTS_DIR="${SNAP_DATA}/certs"
  3. if ! [[ -d "${CERTS_DIR}" ]]; then
  4. echo "Creating dir ${CERTS_DIR}"
  5. mkdir "${CERTS_DIR}"
  6. chmod 0700 "${CERTS_DIR}"
  7. fi
  8. KEYS_DIR="${SNAP_DATA}/.keys"
  9. if ! [[ "${KEYS_DIR}" ]]; then
  10. echo "Creating dir ${KEYS_DIR}"
  11. mkdir "${KEYS_DIR}"
  12. fi
  13. UUID_FILE="${KEYS_DIR}/.install-id"
  14. if ! [[ -f "${UUID_FILE}" ]]; then
  15. echo "Generating UUID"
  16. uuid > ${UUID_FILE}
  17. chmod 0600 "${UUID_FILE}"
  18. fi
  19. UUID=`cat "${UUID_FILE}"`
  20. echo "Generating RSA-keypair"
  21. gpg --list-key "${UUID}" 2> /dev/null
  22. if [[ $? -ne 0 ]]; then
  23. gpg --batch --gen-key <<< "%no-protection
  24. Key-Type: DSA
  25. Key-Length: 2048
  26. Name-Real: ${UUID}
  27. Expire-Date: 0"
  28. fi
  29. snapctl set :certs snapname="${SNAP_NAME}"
  30. snapctl set :certs uuid="${UUID}"
  31. snapctl set :certs pkey="`pgp --armor --export ${UUID}`"
  32. echo "${SNAP_NAME}:certs prepared"
  33. exit 1