-
Notifications
You must be signed in to change notification settings - Fork 2
/
updateCRLs.sh
executable file
·94 lines (77 loc) · 2.26 KB
/
updateCRLs.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
printHelp ()
{
echo "usage: $0 [-h]"
echo ""
echo "https://elbosso.github.io/expect-dialog-ca/"
echo ""
echo -e "-h\t\tPrint this help text\n"
}
dialog_exe=dialog
. `dirname $0`/logging.sh
. `dirname $0`/configure_gui.sh
optionerror=0
while getopts ":h" opt; do
case $opt in
h)
printHelp
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
printHelp
optionerror=1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
printHelp
optionerror=1
;;
esac
done
if [ "$optionerror" = "1" ]
then
exit 1
fi
script_dir=`dirname $0`
script=`basename $0`
cas=$(find . -type f -path '*ca/private/*' -name '*.key' ! -path '*trash*/*' ! -path '*revoked*/*')
#Set the field separator to new line
IFS=$'\n'
rootOfAllEvil=$(realpath "$script_dir")
calpresetd=$(date --date "+2 weeks" +"%d")
calpresetm=$(date --date "+2 weeks" +"%m")
calpresety=$(date --date "+2 weeks" +"%Y")
stichtag=$($dialog_exe --calendar --stdout "Planned expiration" 0 0 ${calpresetd} ${calpresetm} ${calpresety})
if [ $? -ne 0 ]; then exit 127; fi
#$dialog_exe --backtitle "CRLENDOFLIFE" --msgbox "$stichtag" 9 52
y=`echo -n "${stichtag}"|cut -d "/" -f 3`
m=`echo -n "${stichtag}"|cut -d "/" -f 2`
d=`echo -n "${stichtag}"|cut -d "/" -f 1`
#$dialog_exe --backtitle "yms" --msgbox "$y $m $d" 9 52
#st=$(date --date "${y}-${m}-${d}")
#$dialog_exe --backtitle "st" --msgbox "$st" 9 52
for ca in ${cas}
do
cap=$(realpath -s "$ca")
rp=$(dirname "$cap")
rp="$rp/../../"
cd "$rp"
# ca_=`readlink -f ${rp}`
# ca_=`basename ${ca_}`
ca_=`basename ${cap}|cut -d "." -f 1 |rev| cut -d "-" -f 2-|rev`
#$dialog_exe --backtitle "cap" --msgbox "$cap" 9 52
# $dialog_exe --backtitle "ca_" --msgbox "$ca_" 9 52
crl="${rp}/crl/${ca_}-ca.crl"
#$dialog_exe --backtitle "crl" --msgbox "$crl" 9 52
CRLENDOFLIFE=$(openssl crl -in "${crl}" -nextupdate -noout|cut -d '=' -f 2)
# $dialog_exe --backtitle "CRLENDOFLIFE" --msgbox "$CRLENDOFLIFE" 9 52
DATEFUTURE=$(date --date="$CRLENDOFLIFE" "+%s")
DATENOW=$(date --date "${y}${m}${d}" "+%s")
SECONDSDIFF=$(($DATEFUTURE - $DATENOW))
if [ $SECONDSDIFF -le 0 ]; then
"$rootOfAllEvil/refresh_crl.sh" -k "$cap"
# $dialog_exe --backtitle "tobedone" --msgbox "$ca_" 9 52
fi
cd "$rootOfAllEvil"
done