12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #!/usr/bin/env bash
- CERTS_DIR="${SNAP_DATA}/certs"
- if ! [[ -d "${CERTS_DIR}" ]]; then
- echo "Creating dir ${CERTS_DIR}"
- mkdir "${CERTS_DIR}"
- chmod 0700 "${CERTS_DIR}"
- fi
- KEYS_DIR="${SNAP_DATA}/.keys"
- if ! [[ "${KEYS_DIR}" ]]; then
- echo "Creating dir ${KEYS_DIR}"
- mkdir "${KEYS_DIR}"
- fi
- UUID_FILE="${KEYS_DIR}/.install-id"
- if ! [[ -f "${UUID_FILE}" ]]; then
- echo "Generating UUID"
- uuid > ${UUID_FILE}
- chmod 0600 "${UUID_FILE}"
- fi
- UUID=`cat "${UUID_FILE}"`
- echo "Generating RSA-keypair"
- gpg --list-key "${UUID}" 2> /dev/null
- if [[ $? -ne 0 ]]; then
- gpg --batch --gen-key <<< "%no-protection
- Key-Type: DSA
- Key-Length: 2048
- Name-Real: ${UUID}
- Expire-Date: 0"
- fi
- snapctl set :certs snapname="${SNAP_NAME}"
- snapctl set :certs uuid="${UUID}"
- snapctl set :certs pkey="`pgp --armor --export ${UUID}`"
- echo "${SNAP_NAME}:certs prepared"
- exit 1
|