summaryrefslogtreecommitdiff
path: root/bin/load-trustdb
blob: 5d8508ffc3c8b61ee89c9519562ebc199860d17c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

STAMP="$HOME/.gnupg/.load-trustdb"

mkdir -p "$HOME/.gnupg"

if [ -f "$STAMP" ]; then
    last_script_run="$(stat -c '%Y' $STAMP)"
else
    last_script_run=0
fi
if [ -f "$HOME/.gnupg/trustdb.gpg" ]; then
    last_trustdb_mod="$(stat -c '%Y' $HOME/.gnupg/trustdb.gpg)"
else
    last_trustdb_mod=0
fi

if [ ! -f "$HOME/.gnupg/trustdb.gpg" \
       -o "$last_trustdb_mod" -le "$last_script_run" \
   ]; then
    gpg --import-ownertrust "$HOME/lib/priv/.gnupg/otrust.lst"
    # ensure that a check doesn't happen which set the trustdb mtime
    # to newer than this script's last run time with no changes we
    # have to backup
    gpg --batch --check-trustdb
    touch "$STAMP"
else
    echo >&2 "WARNING: The trustdb has been modified.  You should probably run:"
    echo >&2
    echo >&2 "    gpg --export-ownertrust >~/lib/priv/.gnupg/otrust.lst"
    echo >&2
    echo >&2 "to back it up. (or discard changes: rm ~/.gnupg/trustdb.gpg && load-trustdb)."
fi