aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/osm/osm.api.changeset.commit
blob: 20ec2f0d5f9dd0abd6cc139873dfc1b8c9004239 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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 </dev/tty
fi
if [ -z ${OSM_USER_PASSWD} ]; then
  read -e -p 'Type USER:PASSWD: ' -r OSM_USER_PASSWD </dev/tty
fi

create_changeset() {
  curl ${OSM_API}/changeset/create \
    --user ${OSM_USER_PASSWD} \
    --upload-file - \
    <<EOF | tail -1
<osm>
  <changeset>
    <tag k='comment' v='${comment}'/>
    <tag k='created_by' v='bash script'/>
    <tag k='bot' v='yes'/>
  </changeset>
</osm>
EOF
}

# Create changeset with given information
changeset_id=$(create_changeset)

# Print created changeset id
echo >/dev/tty
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 |\
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