summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2022-03-31 08:26:12 +0200
committerLinus Nordberg <linus@nordberg.se>2022-03-31 08:26:12 +0200
commit88e691cb29c6c1e3618c5ee7faf645b349517672 (patch)
tree588e7dc14a4d72f2f64bc8deccbbb0c5425edb02
make executable
-rw-r--r--scripts/savepads.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/savepads.sh b/scripts/savepads.sh
new file mode 100644
index 0000000..18a55bc
--- /dev/null
+++ b/scripts/savepads.sh
@@ -0,0 +1,45 @@
+#! /usr/bin/env bash
+
+#
+# A simple script that downloads sigsum's ms and db pads periodcally.
+# Downloaded pads that are older than $age_days are silently removed.
+#
+# It is assumed that both pads contain the pattern $match. You may want
+# to keep an eye on the resulting log file. It should always be empty.
+#
+# Crontab at the 16th minute every three hours:
+#
+# 16 */3 * * * /some/path/sigsum-savepads >>/some/log/file 2>&1
+#
+
+set -eu
+trap EXIT
+
+prefix="https://pad.sigsum.org/p"
+suffix="export/txt"
+age_days=30
+
+dir="$1"; shift
+pads="sigsum-ms sigsum-db"
+match="This pad describes"
+
+function main() {
+ for pad in $pads; do
+ src=$prefix/$pad/$suffix
+ dst=$dir/$(date "+%y%m%d-%H%M%S")_$pad
+ curl "$src" > "$dst" 2>/dev/null ||
+ die_with_error "must fetch $pad"
+
+ grep "$match" "$dst" ||
+ die_with_error "expected \"$match\" to be in $src"
+
+ find "$dir" -type f -mtime +$age_days -regextype posix-extended -regex "^.*[0-9]{6}-[0-9]{6}_$pad$" -delete
+ done
+}
+
+function die_with_error(){
+ echo "$(date \"+%y-%m-%d %H:%M:%S %Z\") [FATA]" "$@" >&2
+ exit 1
+}
+
+main