#!/usr/bin/env bash set -euxo pipefail usage () { echo "Recursively imports all gpx tracks in a directory into an SQLite database." echo "" echo "Usage: $(basename $0) directory target-database" } gpx_directory="$1" target_database="$2" # basic argument verification case "$@" in -h|--help) usage && exit 0;; esac [ -z "$gpx_directory" ] && usage && exit 1 [ -z "$target_database" ] && usage && exit 1 tmp="$(mktmp -d diogenes.XXXXX -p /tmp)/$(basename $target_database)" # recursive scan and import while IFS= read -d '' -r file; do spatialite_xml_load -d "$tmp" -x "$file" done < <(find "$gpx_directory" -name '*.gpx' -print0) mv $tmp $target_database # TODO: Create virtual joined table