#!/bin/bash

# Find all .xz files in the current directory
for xzfile in ./*/*.xz; do

    # Skip if no .xz files found
    [ -e "$xzfile" ] || continue

    # Skip if the .xz file is less than 64 bytes in size
    if [ "$(stat -c%s "$xzfile")" -lt 64 ]; then
        continue
    fi

    # Try to determine the original file extension (.zip or .dem)
    origfile_zip="${xzfile%.dem.xz}.zip"
    origfile_dem="${xzfile%.xz}"

    # If the uncompressed .zip file exists, delete it
    if [ -e "$origfile_zip" ]; then
        echo "Deleting duplicate uncompressed file: $origfile_zip"
        rm -f -- "$origfile_zip"
    fi

    # If the uncompressed .dem file exists, delete it
    if [ -e "$origfile_dem" ]; then
        echo "Deleting duplicate uncompressed file: $origfile_dem"
        rm -f -- "$origfile_dem"
    fi
done
