123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #!/bin/sh
- set -e
- set -x
- set -u
- usage() {
- echo "Usage: $0 <year> <month>" >&2
- echo " $0 last (does last month)" >&2
- exit 1
- }
- if [ -z "${1:-}" ]; then
- usage
- fi
- if [ "$1" = "last" ]; then
- year=`date --date="last month" +'%Y'`
- month=`date --date="last month" +'%m'`
- elif [ -z "${2:-}" ]; then
- usage
- else
- year="$1"
- month="$2"
- fi
- if [ "$year" -lt 2000 ] || [ "$year" -gt 2020 ] ||
- [ "$month" -lt 1 ] || [ "$month" -gt 12 ] ||
- [ "`echo -n $month | wc -c`" != 2 ]; then
- usage
- fi
- this_year=`date --utc +'%Y'`
- this_month=`date --utc +'%m'`
- if [ "`date -d $this_year-$this_month-01 +%s`" -le "`date -d $year-$month-01 +%s`" ]; then
- echo "Date in the future or current month?" >&2
- exit 1
- fi
- for file in \
- "extra-infos-$year-$month.tar.bz2" \
- "server-descriptors-$year-$month.tar.bz2" \
- "consensuses-$year-$month.tar.bz2" \
- "statuses-$year-$month.tar.bz2" \
- ; do
- if [ -e "$file" ]; then
- echo "$file already exists" >&2
- exit 1
- fi
- done
- for dir in \
- "extra-infos-$year-$month" \
- "server-descriptors-$year-$month" \
- "consensus/$year/$month" \
- "status/$year/$month" \
- ; do
- if ! [ -d "$dir" ]; then
- echo "$dir not found" >&2
- exit 1
- fi
- done
- for dir in \
- "consensuses-$year-$month" \
- "statuses-$year-$month" \
- ; do
- if [ -e "$dir" ]; then
- echo "$dir already exists" >&2
- exit 1
- fi
- done
- for kind in consensus status; do
- mv "$kind"/$year/$month "$kind"es-$year-$month
- find "$kind"es-$year-$month -type f -name '*.bz2' -print0 | xargs -0 bunzip2 -v
- tar cjvf "$kind"es-$year-$month.tar.bz2 "$kind"es-$year-$month
- rm -rf "$kind"es-$year-$month
- done
- for kind in extra-infos server-descriptors; do
- tar cjvf "$kind"-$year-$month.tar.bz2 "$kind"-$year-$month
- rm -rf "$kind"-$year-$month
- done
- [ -d Archive ] || mkdir Archive
- for kind in consensus status; do
- t="$kind"es-$year-$month.tar.bz2
- ! [ -e Archive/"$t" ] && mv "$t" Archive/"$t"
- done
- for kind in extra-infos server-descriptors; do
- t="$kind"-$year-$month.tar.bz2
- ! [ -e Archive/"$t" ] && mv "$t" Archive/"$t"
- done
|