#!/usr/bin/env bash

set -x

# Allow the webserver to access the files
chmod -R o+r .

# Strip location metadata
find . -iname '*.heic' -exec exiftool -gps:all= -xmp:geotag= {} \;
find . -iname 'FLOPPY.*' -exec exiftool -gps:all= -xmp:geotag= {} \;


# Convert HEIC to JPEG
find . -iname '*.heic' | sed -r 's#\./([^/]+)/(IMG_[0-9]+)\.HEIC#convert "\1/\2.HEIC" "\1/FLOPPY.JPG"#' | bash -x -

# Remove HEIC originals
find . -iname '*.heic' -delete
find . -iname '*.heic_original' -delete
find . -iname '*.heic_original' -delete

# Sync to the website
rsync -a --info=progress2 --delete ./ zlomek.irth.pl:/srv/http/mavica
