Skip to content

Instantly share code, notes, and snippets.

@utdemir
Created August 24, 2020 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utdemir/df48da37860711cb7905d44c98ccb2ea to your computer and use it in GitHub Desktop.
Save utdemir/df48da37860711cb7905d44c98ccb2ea to your computer and use it in GitHub Desktop.
#!/usr/bine/env bash
# Save this script as $PASSWORD_STORE_EXTENSIONS_DIR/rotate.bash to use.
set -o errexit
set -o nounset
set -o pipefail
cd "$PREFIX"
oldest="$(
find . -name '*.gpg' \
-exec stat -c '%Y {}' {} \; \
| sort | head -n 1
)"
timestamp="$(echo "$oldest" | cut -d ' ' -f 1)"
secret="$(echo "$oldest" | cut -d ' ' -f 2- | sed -e 's/\.gpg$//' -e 's|^\./||g' )"
now="$(date +%s)"
let "seconds_diff = $now - $timestamp"
let "date_diff = $seconds_diff / 60 / 60 / 24"
bold=$(tput bold)
normal=$(tput sgr0)
echo "Secret: $bold$secret$normal"
echo "Last modification: $bold$date_diff$normal days ago."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment