bin/check-key-ring-expiry
branchrsync
changeset 40 5f159c41e8a3
equal deleted inserted replaced
39:c2e97355a239 40:5f159c41e8a3
       
     1 #!/bin/sh
       
     2 
       
     3 WARNTIME=$(expr 30 \* 24 \* 60 \* 60) # seconds
       
     4 TODAY=$(date +%s)
       
     5 #TODAY=$(date -d '2013-04-03' +%s)
       
     6 UPLOADERS=~/repo/conf/uploaders/*
       
     7 #UPLOADERS=/tmp/test
       
     8 
       
     9 EXPIRY=
       
    10 ADDRESS=
       
    11 
       
    12 set_key_data() {
       
    13 
       
    14     e=
       
    15     a=
       
    16     k=${1}
       
    17     EXPIRY=
       
    18     ADDRESS=
       
    19     IFS=':' read e a <<EOO
       
    20 $(LC_ALL= LANG= gpg -k --with-colons $k|grep '^pub'|cut -d: -f7,10)
       
    21 EOO
       
    22 
       
    23     [ -n "$e" ] && EXPIRY=$(date -d $e +%s)
       
    24     [ -n "$a" ] && ADDRESS=$a
       
    25 
       
    26 }
       
    27 
       
    28 about_to_expire() {
       
    29     [ -n "$EXPIRY" -a \( $(( $EXPIRY - $TODAY )) -le $WARNTIME \) ] || return 1;
       
    30 }
       
    31 
       
    32 expired() { 
       
    33     [ -n "$EXPIRY" -a \( $(( $EXPIRY - $TODAY )) -le 0 \) ] || return 1;
       
    34 }
       
    35 
       
    36 for f in $UPLOADERS; do
       
    37     while read first second third fourth k; do
       
    38 	if [ \( "$first" = 'allow' \) \
       
    39 	    -a \( "$second" = '*' \) \
       
    40 	    -a \( "$third" = 'by' \) \
       
    41 	    -a \( "$fourth" = 'key' \) \
       
    42 	    -a \( -n "$k" \) ]; then
       
    43 	    SUBJECT=
       
    44 	    set_key_data $k
       
    45 	    { about_to_expire || expired; } && gpg --refresh-keys $k
       
    46 	    set_key_data $k
       
    47 	    if expired; then
       
    48 		SUBJECT='Your published Package Signing Key is expired'
       
    49 	    elif about_to_expire; then
       
    50 		SUBJECT='Your published Package Signing Key is about to expire'
       
    51 	    fi
       
    52 	    if [ -n "$SUBJECT" ]; then
       
    53 		#echo "$ADDRESS: Subject: $SUBJECT"
       
    54 		#cat <<EOM | gpg --encrypt -a --batch --trust-model always --recipient $k| /usr/sbin/sendmail "$ADDRESS"
       
    55 		cat <<EOM | /usr/sbin/sendmail "$ADDRESS"
       
    56 Subject: $SUBJECT
       
    57 
       
    58 Please extend the expiration date and send the updated key to the keyserver.
       
    59 Reply to this mail if you want us to remove your key from our list.
       
    60 
       
    61 $(gpg -k $k)
       
    62 
       
    63 Best regards
       
    64 EOM
       
    65 	    fi
       
    66 	fi
       
    67     done <$f
       
    68 done