summaryrefslogtreecommitdiffstats
path: root/sync-certs
blob: 724b76c2df199e92627dd2e16c275bd90733ec42 (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
34
35
36
37
38
39
#!/bin/bash

FILE_REGEXP='\(.*\)-\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\).crt'
REPO="$1"

if [[ -z "$REPO" || ! -d "$REPO/SSL/" || ! -d "$REPO/.git" ]]; then
    echo "Usage: $0 <repo>" >&2
    exit 1
fi

change=0
cd "$REPO" >/dev/null

for cert in /var/cache/spline-ssl/* ; do

    if read host date ; then

        if [[ -n "$host" && -n "$date" ]]; then
            mkdir -p "SSL/$host/"
            mv "$cert" "SSL/$host/$host-$date.crt"

            git add "SSL/$host/$host-$date.crt"
            git commit --no-verify --quiet \
                --author="SSL Cert Syncer <root@bcfg2.spline.inf.fu-berlin.de>" \
                --message="SSL: Automatic ssl cert sync

Add cert for $host." \
                "SSL/$host/$host-$date.crt"

            ((change++))

        fi

    fi < <(basename "$cert" | sed "s/$FILE_REGEXP/\1 \2/")
done

if [[ $change -gt 0 ]]; then
    echo "Moved $change certificates into repo, you may want to call $(tput bold)renew-config$(tput sgr0) now."
fi