logo

dotfiles

My dotfiles, one branch per machine, rebased on base git clone https://anongit.hacktivis.me/git/dotfiles.git/

minisign-rotate (1951B)


  1. #!/bin/sh
  2. set -u
  3. set -o pipefail
  4. set -e
  5. getpass() {
  6. gpg --decrypt /home/haelwenn/.password-store/minisign.gpg
  7. }
  8. path_key="${HOME}/.minisign/minisign.sec"
  9. path_pub="${HOME}/.minisign/minisign.pub"
  10. path_real_key="$(realpath "${path_key}")"
  11. date_real_key="$(basename "${path_prev_key%.sec}")"
  12. path_real_pub="$(realpath "${path_pub}")"
  13. date_real_pub="$(basename "${path_prev_pub%.pub}")"
  14. if [ "${date_real_key}" != "${date_real_pub}" ]; then
  15. echo "minisign-rotate: Date mismatch between private-key(${date_real_key}) and public-key(${date_real_pub}), exiting..." >&2
  16. exit 1
  17. fi
  18. date_real="${date_real_key}"
  19. date_cur="$(date +%Y)"
  20. path_cur_key="${HOME}/.minisign/${date_cur}.sec"
  21. path_cur_pub="${HOME}/.minisign/${date_cur}.pub"
  22. path_cur_pub_sig="${HOME}/.minisign/${date_cur}.pub.${date_real}.sig"
  23. if [ "${path_cur_key}" = "${path_real_key}" ]; then
  24. echo "minisign-rotate: Signify current key symlink is up-to-date"
  25. else
  26. echo "minisign-rotate: Updating signify key symlinks"
  27. set -x
  28. # Update key symlinks
  29. ln -sf "${path_cur_key}" "${path_key}"
  30. ln -sf "${path_cur_pub}" "${path_pub}"
  31. fi
  32. # Only generate once to be sure, releases at new year can happen
  33. date_next="$((date_cur+1))"
  34. path_next_key="${HOME}/.minisign/${date_next}.sec"
  35. path_next_pub="${HOME}/.minisign/${date_next}.pub"
  36. path_next_pub_sig="${HOME}/.minisign/${date_next}.pub.${date_cur}.sig"
  37. if [ -e "${path_next_key}" ]; then
  38. echo "minisign-rotate: Next year key seems to be present"
  39. else
  40. echo "minisign-rotate: Need to generate key for next year, press enter to continue"
  41. set -x
  42. read foo
  43. # Generate new key (password needs to be inserted twice for confirmation)
  44. ( getpass ; getpass ) | signify -G -p "${path_next_pub}" -s "${path_next_key}"
  45. # Sign next pubkey with still current key
  46. getpass | signify -S -x "${path_next_pub_sig}" -s "${path_cur_key}" -m "${path_next_pub}"
  47. # Publish
  48. publish-release --subdir=signify "${path_next_pub}" "${path_next_pub_sig}"
  49. fi