secrets 838 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. set -e
  3. case "$1" in
  4. encrypt)
  5. cd /var/lib/secrets/ || exit
  6. tar -cf secrets.tar ./*
  7. cd /usr/share/secrets/ || exit
  8. mv /var/lib/secrets/secrets.tar .
  9. age -e -r age122g2ufaa494vj9yqcqh0l6390l38j0j4v80ganlx9eg7v07a3eps3te4ac <secrets.tar >secrets.tar.age
  10. shred -zu secrets.tar
  11. ;;
  12. decrypt)
  13. cd /usr/share/secrets/ || exit
  14. printf 'key: '
  15. read -r key
  16. echo "$key" >/tmp/secrets.key
  17. age -d -i /tmp/secrets.key <secrets.tar.age >secrets.tar
  18. cd /var/lib/secrets/ || exit
  19. tar -x --overwrite -f /usr/share/secrets/secrets.tar
  20. chmod g+rX /var/lib/secrets/ -R
  21. find . -type f | while IFS= read -r secret
  22. do
  23. rm -f "/$secret"
  24. ln -sf "/var/lib/secrets/$secret" "/$secret"
  25. done
  26. shred -zu /usr/share/secrets/secrets.tar
  27. shred -zu /tmp/secrets.key
  28. ;;
  29. *)
  30. echo 'secrets (encrypt|decrypt)'
  31. ;;
  32. esac