bin/rollup: Fix offset-by-one year bug.
[ca] / bin / rollup
1 #! /bin/sh -e
2
3 thisyear=$(date +%Y)
4 last=nil
5
6 flush () {
7 case $last in nil) return ;; esac
8 (cd tmp/rollup/all && tar cfz - .) >tmp/rollup/$last-all.tgz
9 mv tmp/rollup/$last-all.tgz archive/
10 rm -f archive/$last-??-??T??:??:??Z.tgz
11 rm -rf tmp/rollup/all
12 }
13
14 rm -rf tmp/rollup; mkdir -p tmp/rollup
15 for 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
38 done
39 flush
40 rmdir tmp/rollup