diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2023-02-14 13:33:23 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2023-02-14 13:33:23 +0800 |
commit | 6fae25b305d714b3ab7608fa003f1af9bf024545 (patch) | |
tree | 05507b2c0505659d2fd847ecce988dacab63a236 /bin/osm/osm.api.changeset.commit | |
parent | 41ad31a2dee9ff912f222652f022b4c55cddcbf7 (diff) |
Rename tools into bin
Diffstat (limited to 'bin/osm/osm.api.changeset.commit')
-rwxr-xr-x | bin/osm/osm.api.changeset.commit | 80 |
1 files changed, 80 insertions, 0 deletions
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 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | shopt -s lastpipe | ||
5 | |||
6 | OSM_SERVER=https://api.openstreetmap.org | ||
7 | OSM_TEST_SERVER=https://master.apis.dev.openstreetmap.org | ||
8 | if [[ $@ =~ '--serious' ]]; then | ||
9 | SERVER=$OSM_SERVER | ||
10 | else | ||
11 | SERVER=$OSM_TEST_SERVER | ||
12 | fi | ||
13 | |||
14 | OSM_API=${SERVER}/api/0.6 | ||
15 | FILE=${@//--serious/} | ||
16 | |||
17 | # Prompt for comment and User:Password | ||
18 | if [[ ! -t 0 ]]; then | ||
19 | comment=$(cat) | ||
20 | else | ||
21 | read -e -p 'Type comment: ' -r comment </dev/tty | ||
22 | fi | ||
23 | if [ -z ${OSM_USER_PASSWD} ]; then | ||
24 | read -e -p 'Type USER:PASSWD: ' -r OSM_USER_PASSWD </dev/tty | ||
25 | fi | ||
26 | |||
27 | create_changeset() { | ||
28 | SOURCE_TAG="${SOURCE:+$(printf "<tag k='source' v='%s'/>" $SOURCE)}" | ||
29 | |||
30 | curl ${OSM_API}/changeset/create \ | ||
31 | --user ${OSM_USER_PASSWD} \ | ||
32 | --upload-file - \ | ||
33 | --silent \ | ||
34 | <<EOF | tail -1 | ||
35 | <osm> | ||
36 | <changeset> | ||
37 | ${SOURCE_TAG} | ||
38 | <tag k='comment' v='${comment}'/> | ||
39 | <tag k='created_by' v='bash script'/> | ||
40 | <tag k='bot' v='yes'/> | ||
41 | </changeset> | ||
42 | </osm> | ||
43 | EOF | ||
44 | } | ||
45 | |||
46 | # Return http code after uploading a file | ||
47 | uploade_file_to_changeset() { | ||
48 | curl -X POST $OSM_API/changeset/${changeset_id}/upload \ | ||
49 | --user ${OSM_USER_PASSWD} -i \ | ||
50 | --upload-file - \ | ||
51 | --silent -o /dev/null -w "%{http_code}" | ||
52 | } | ||
53 | |||
54 | close_changeset() { | ||
55 | curl -X PUT ${OSM_API}/changeset/${changeset_id}/close \ | ||
56 | --user ${OSM_USER_PASSWD} -i \ | ||
57 | --silent -o /dev/null -w "%{http_code}" | ||
58 | } | ||
59 | |||
60 | # Create changeset with given information | ||
61 | changeset_id=$(create_changeset) | ||
62 | |||
63 | # Print created changeset id | ||
64 | echo "Changeset created, check ${SERVER}/changeset/${changeset_id}" >/dev/tty | ||
65 | echo ${changeset_id} | ||
66 | |||
67 | # Upload OSC file to Changeset | ||
68 | sed -Ee "/<(node|way|relation)/ s/>/ changeset=\"${changeset_id}\">/" $FILE |\ | ||
69 | uploade_file_to_changeset | if [[ $(cat) == '200' ]]; then | ||
70 | echo Upload file $FILE to changeset ${changeset_id} >/dev/tty | ||
71 | else | ||
72 | exit 1 | ||
73 | fi | ||
74 | |||
75 | # Close Changeset | ||
76 | close_changeset | if [[ $(cat) == '200' ]]; then | ||
77 | echo Changeset ${changeset_id} closed >/dev/tty | ||
78 | else | ||
79 | exit 1 | ||
80 | fi | ||