bin/rollup: New program to consolidate the archive of old certificates.
[ca] / bin / rollup
CommitLineData
81f38a42
MW
1#! /bin/sh -e
2
3thisyear=$(date +%Y)
4last=nil
5
6flush () {
7 case $last in nil) return ;; esac
8 (cd tmp/rollup/all && tar cfz - .) >tmp/rollup/$year-all.tgz
9 mv tmp/rollup/$year-all.tgz archive/
10 rm -f archive/$last-??-??T??:??:??Z.tgz
11 rm -rf tmp/rollup/all
12}
13
14rm -rf tmp/rollup; mkdir -p tmp/rollup
15for i in archive/????-??-??T??:??:??Z.tgz; do
16 base=${i##*/} year=${base%%-*}
17 case $year in
18 $thisyear) break ;;
19 $last) ;;
20 *) flush; mkdir tmp/rollup/all; last=$year ;;
21 esac
22 mkdir tmp/rollup/cur
23 (cd tmp/rollup/cur && tar xfz -) <$i
24 mv tmp/rollup/cur/cert.* tmp/rollup/all/
25 for j in tmp/rollup/cur/*; do
26 base=${j##*/}
27 case $base in
28 cert.*)
29 mv tmp/rollup/cur/$base tmp/rollup/all/
30 ;;
31 *)
32 cat tmp/rollup/cur/$base >>tmp/rollup/all/$base;
33 rm tmp/rollup/cur/$base
34 ;;
35 esac
36 done
37 rmdir tmp/rollup/cur
38done
39flush
40rmdir tmp/rollup