#!/bin/sh

basedir="$PWD"

mkdir -p $basedir/tmp

for i in $(ls shp/[K-X]*.shp.zip | sort); do
	if [ -f $basedir/abort ]; then
		echo "Abort at $i"
		exit 1
	fi
	echo "Importing $i..." | tee $basedir/import
	cd $basedir/tmp/
	rm $basedir/tmp/*

	unzip $basedir/$i
	
	for f in $basedir/tmp/*; do
		DST=$(echo "$f" | cut -d '_' -f 2 | sed -e 's|^|tiet_2013_08_|g')
		mv $f $DST
	done

	PGCLIENTENCODING="UTF-8" ~/bin/ogr2ogr \
			-f "PostgreSQL" \
			-a_srs "EPSG:3067" \
			PG:"FIXME" \
			-append *_v.shp
done
