#!/bin/sh

if [ "$#" -eq 0 ]
then
  echo "Must supply path for inverted files"
  exit 1
fi

target="$1"

target=${target%/}

find "$target" -name "*.inv.gz" -delete

for fl in *.e2x.gz
do
  base=${fl%.e2x.gz}
  echo "$base"
  seconds_start=$(date "+%s")
  gunzip -c "$fl" |
  rchive -invert |
  gzip -1 > "$target/$base.inv.gz"
  seconds_end=$(date "+%s")
  seconds=$((seconds_end - seconds_start))
  echo "$seconds seconds"
  sleep 1
done
