#!/bin/sh
set -e
shopt -s lastpipe
OSM_SERVER=https://api.openstreetmap.org
# Test server, use it for debug
#OSM_SERVER=https://master.apis.dev.openstreetmap.org
OSM_API=${OSM_SERVER}/api/0.6
# Prompt for comment and User:Password
read -e -p 'Type comment: ' -r comment
"
# Create changeset with given information
curl ${OSM_API}/changeset/create \
--user ${OSM_USER_PASSWD} \
--upload-file - \
<
EOF
# Print created changeset id
echo >/dev/tty
echo "changeset created, check ${OSM_SERVER}/changeset/${changeset_id}" >/dev/tty
echo ${changeset_id}
# Upload OSC file to Changeset
sed -r "/<(node|way|relation)/ s/>/ changeset=\"${changeset_id}\">/" <$1 |\
tee /dev/tty | \
curl -X POST -u ${OSM_USER_PASSWD} -i -T - $OSM_API/changeset/${changeset_id}/upload
# Close Changeset
curl -X PUT -u ${OSM_USER_PASSWD} -i ${OSM_API}/changeset/${changeset_id}/close