#! /bin/sh

# given a path, traverse that file system tree and extract all
# .xz files and re-compress them to .gz; some tooling, in particular
# graphdb, only supports gz and not xz

set -eu

if [ ! $# -eq 1 ]; then
    echo "usage: $0 DIRECTORY" 1>&2
    exit 1
fi

directory="$1"
files=$(find "$directory" -name "*.xz")

for file in $files; do
    echo "$file" 1>&2

    # the filename of the extracted (uncompressed) file
    rdf_file=$(echo "$file" | sed 's/\.xz//')

    # uncompress and then compress again
    unxz "$file"
    gzip "$rdf_file"
done
