aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/osm/osm.api.changeset.commit
blob: 8fe812517582f92aac30f85c8d4d3db384a78da3 (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
57
58
59
60
61
62
63
64
#!/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 - \
    --silent \
    <<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
}

# Return http code after uploading a file
uploade_file_to_changeset() {
  curl $OSM_API/changeset/${changeset_id}/upload \
    --user ${OSM_USER_PASSWD} -i \
    --upload-file - \
    --silent -o /dev/null -w "%{http_code}" 
}

# 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 |\
uploade_file_to_changeset | if [[ $(cat) != '200' ]]; then exit 1; fi

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