init 958 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env bash
  2. CERTS_DIR="${SNAP_DATA}/certs"
  3. SSL_DIR="${SNAP_DATA}/.ssl"
  4. UUID_FILE="${SNAP_DATA}/.install-id"
  5. if ! [[ -f "${UUID_FILE}" ]]; then
  6. logger "Generate UUID for ${SNAP_NAME}"
  7. uuid > "${UUID_FILE}"
  8. logger "${SNAP_NAME} (uuid: `cat ${UUID_FILE}`)"
  9. fi
  10. UUID=`cat ${UUID_FILE}`
  11. DOMAIN=`snapctl get domain`
  12. if [ -z "${DOMAIN}" ]; then
  13. DOMAIN="--not-set"
  14. fi
  15. snapctl set domain="${DOMAIN}"
  16. function gpg_start_agent {
  17. gpg-agent 2> /dev/null
  18. if [ $? -ne 0 ]; then
  19. logger "GPG-agent not here"
  20. gpg-agent --daemon 2> /dev/null
  21. if [ $? -eq 0 ]; then
  22. logger "GPG-agent started"
  23. else
  24. logger "Failed starting GPG-agent, trying anyway"
  25. fi
  26. fi
  27. return 0
  28. }
  29. function gpg_close_agent {
  30. PID=`ps -T | grep gpg-agent | head -n 1 | cut -d' ' -f1`
  31. if [ -n "${PID}" ]; then
  32. logger "Kill GPG-agent: ${PID}"
  33. kill -9 "${PID}" >> /dev/null
  34. fi
  35. }