bin/rollup: New program to consolidate the archive of old certificates.
[ca] / bin / rollup
diff --git a/bin/rollup b/bin/rollup
new file mode 100755 (executable)
index 0000000..4955761
--- /dev/null
@@ -0,0 +1,40 @@
+#! /bin/sh -e
+
+thisyear=$(date +%Y)
+last=nil
+
+flush () {
+  case $last in nil) return ;; esac
+  (cd tmp/rollup/all && tar cfz - .) >tmp/rollup/$year-all.tgz
+  mv tmp/rollup/$year-all.tgz archive/
+  rm -f archive/$last-??-??T??:??:??Z.tgz
+  rm -rf tmp/rollup/all
+}
+
+rm -rf tmp/rollup; mkdir -p tmp/rollup
+for i in archive/????-??-??T??:??:??Z.tgz; do
+  base=${i##*/} year=${base%%-*}
+  case $year in
+    $thisyear) break ;;
+    $last) ;;
+    *) flush; mkdir tmp/rollup/all; last=$year ;;
+  esac
+  mkdir tmp/rollup/cur
+  (cd tmp/rollup/cur && tar xfz -) <$i
+  mv tmp/rollup/cur/cert.* tmp/rollup/all/
+  for j in tmp/rollup/cur/*; do
+    base=${j##*/}
+    case $base in
+      cert.*)
+       mv tmp/rollup/cur/$base tmp/rollup/all/
+       ;;
+      *)
+       cat tmp/rollup/cur/$base >>tmp/rollup/all/$base;
+       rm tmp/rollup/cur/$base
+       ;;
+    esac
+  done
+  rmdir tmp/rollup/cur
+done
+flush
+rmdir tmp/rollup