logo

dotfiles

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

minisign-rotate (2054B)


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