From 6fae25b305d714b3ab7608fa003f1af9bf024545 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 14 Feb 2023 13:33:23 +0800 Subject: Rename tools into bin --- bin/osm/osm.api.changeset.commit | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 bin/osm/osm.api.changeset.commit (limited to 'bin/osm/osm.api.changeset.commit') diff --git a/bin/osm/osm.api.changeset.commit b/bin/osm/osm.api.changeset.commit new file mode 100755 index 0000000..6b67833 --- /dev/null +++ b/bin/osm/osm.api.changeset.commit @@ -0,0 +1,80 @@ +#!/bin/bash + +set -e +shopt -s lastpipe + +OSM_SERVER=https://api.openstreetmap.org +OSM_TEST_SERVER=https://master.apis.dev.openstreetmap.org +if [[ $@ =~ '--serious' ]]; then + SERVER=$OSM_SERVER +else + SERVER=$OSM_TEST_SERVER +fi + +OSM_API=${SERVER}/api/0.6 +FILE=${@//--serious/} + +# Prompt for comment and User:Password +if [[ ! -t 0 ]]; then + comment=$(cat) +else + read -e -p 'Type comment: ' -r comment " $SOURCE)}" + + curl ${OSM_API}/changeset/create \ + --user ${OSM_USER_PASSWD} \ + --upload-file - \ + --silent \ + < + + ${SOURCE_TAG} + + + + + +EOF +} + +# Return http code after uploading a file +uploade_file_to_changeset() { + curl -X POST $OSM_API/changeset/${changeset_id}/upload \ + --user ${OSM_USER_PASSWD} -i \ + --upload-file - \ + --silent -o /dev/null -w "%{http_code}" +} + +close_changeset() { + curl -X PUT ${OSM_API}/changeset/${changeset_id}/close \ + --user ${OSM_USER_PASSWD} -i \ + --silent -o /dev/null -w "%{http_code}" +} + +# Create changeset with given information +changeset_id=$(create_changeset) + +# Print created changeset id +echo "Changeset created, check ${SERVER}/changeset/${changeset_id}" >/dev/tty +echo ${changeset_id} + +# Upload OSC file to Changeset +sed -Ee "/<(node|way|relation)/ s/>/ changeset=\"${changeset_id}\">/" $FILE |\ +uploade_file_to_changeset | if [[ $(cat) == '200' ]]; then + echo Upload file $FILE to changeset ${changeset_id} >/dev/tty +else + exit 1 +fi + +# Close Changeset +close_changeset | if [[ $(cat) == '200' ]]; then + echo Changeset ${changeset_id} closed >/dev/tty +else + exit 1 +fi -- cgit v1.2.3-70-g09d2