pass-check-age.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. ## By demure (demuredemeanor)
  3. ## Version 0.4
  4. ## This script is intended to make it easy to see which passwords need updating due to age with the password manager `pass`.
  5. ## Usage: This script will display .gpg files with modification dates older than 300 days by default.
  6. ## NOTE: Editing the pass entry without changing the password itself will also change the file's modification date
  7. if [ $# -gt 1 ]; then
  8. echo "Too many inputs. Only expecting integer of how many days old to display."
  9. exit
  10. fi
  11. if [ $# -eq 1 ]; then
  12. if [ "$1" -ge 0 ] 2>/dev/null; then
  13. DAYS="$1"
  14. else
  15. echo "Bad input. Expecting integer of how many days old to display."
  16. fi
  17. fi
  18. if [ $# -eq 0 ]; then
  19. DAYS=300
  20. fi
  21. ## Test if pass default dir overridden
  22. if [ -z ${PASSWORD_STORE_DIR} ]; then
  23. DIR="$HOME/.password-store"
  24. else
  25. DIR="${PASSWORD_STORE_DIR}"
  26. fi
  27. ## Before we check modification times, we need to ensure that the local password store's file modification dates match git
  28. ## Citation: https://stackoverflow.com/a/55609950/2327476
  29. cd ${DIR}
  30. git ls-tree -r --name-only HEAD | while read filename; do
  31. unixtime=$(git log -1 --format="%at" -- "${filename}")
  32. touchtime=$(date -d @$unixtime +'%Y%m%d%H%M.%S')
  33. touch -t ${touchtime} "${filename}"
  34. done
  35. ## Match .gpg files other that X days, sort by date, cut off the extra bits before the parent dir, output in cols and display in less
  36. find "${DIR}" -name '*.gpg' -mtime +300 -printf '%TY-%Tm-%Td %TH:%TM %h %f\n' | sort -n | sed 's/\/.*\///' | column -t | less