aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/osm/osm.api.changeset.commit
blob: 5182e3bec9e6d18261b15046b2b9063fbf9023da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/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 </dev/tty
if [ -z ${OSM_USER_PASSWD} ]; then
  read -e -p 'Type USER:PASSWD: ' -r OSM_USER_PASSWD </dev/tty
fi

# Create changeset with given information
curl ${OSM_API}/changeset/create \
  --user ${OSM_USER_PASSWD} \
  --upload-file - \
  <<EOF | tail -1 | changeset_id=$(cat)
<osm>
  <changeset>
    <tag k='comment' v='${comment}'/>
    <tag k='created_by' v='bash script'/>
    <tag k='bot' v='yes'/>
  </changeset>
</osm>
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 -Ee "/<(node|way|relation)/ s/>/ changeset=\"${changeset_id}\">/" $1 |\
tee /dev/tty | \
curl -X POST --user ${OSM_USER_PASSWD} -i --upload-file - $OSM_API/changeset/${changeset_id}/upload

# Close Changeset
curl -X PUT --user ${OSM_USER_PASSWD} -i ${OSM_API}/changeset/${changeset_id}/close