| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # This file is meant to be SOURCED |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | function track(){ |
| 18 | # Tracks events by sending HTTP GET requests with query strings to a web server |
| 19 | # - First argument: event name |
| 20 | # - Rest of arguments (if they exist): tuples of operation-value-comment-tags |
| 21 | # - operation: particular operation in an event (if it is not provided, the operation will be named after the event) |
| 22 | # - value: particular value for an operation |
| 23 | # - comment |
| 24 | # - none will be passed when empty |
| 25 | # - will be parsed to replace spaces by underscores |
| 26 | # - tags |
| 27 | # - none will be passed when empty |
| 28 | # - will be parsed to replace spaces by ~ |
| 29 | |
| 30 | if [ $# -lt 1 ]; then |
| 31 | echo "Unexpected error in track function. At least 1 arg is expected: event" |
| 32 | return 1 |
| 33 | fi |
| 34 | |
| 35 | osm_track_event_name=$1 |
| 36 | |
| 37 | ctime=`date +%s` |
| 38 | |
| 39 | query_string="" |
| 40 | query_string="${query_string}&installation_id=${OSM_TRACK_INSTALLATION_ID}" |
| 41 | query_string="${query_string}&local_ts=${ctime}" |
| 42 | query_string="${query_string}&event=${osm_track_event_name}" |
| 43 | |
| 44 | shift 1 |
| 45 | if [ $# -eq 0 ]; then |
| 46 | operation="${osm_track_event_name}" |
| 47 | value="" |
| 48 | comment="" |
| 49 | tags="" |
| 50 | final_query_string="${query_string}" |
| 51 | final_query_string="${final_query_string}&operation=${operation}" |
| 52 | final_query_string="${final_query_string}&value=${value}" |
| 53 | final_query_string="${final_query_string}&comment=${comment}" |
| 54 | final_query_string="${final_query_string}&tags=${tags}" |
| 55 | url="https://osm.etsi.org/InstallLog.php?${final_query_string}" |
| 56 | echo "Track $osm_track_event_name $operation: ${url}" |
| garciadeblas | e572aab | 2022-01-14 11:19:16 +0100 | [diff] [blame] | 57 | LANG=C wget -q -O /dev/null "$url" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 58 | else |
| 59 | while (( "$#" > 0 )); do |
| 60 | operation="${1:-${osm_track_event_name}}" |
| 61 | shift 1 |
| 62 | value="${1:-}" |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 63 | value="${value// /_}" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 64 | shift 1 |
| 65 | comment="${1:-}" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 66 | comment="${comment// /_}" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 67 | shift 1 |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 68 | tags="${1:-}" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 69 | tags="${tags//,/\~}" |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 70 | shift 1 |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 71 | [ "$value" == "none" ] && value="" |
| 72 | [ "$comment" == "none" ] && comment="" |
| 73 | [ "$tags" == "none" ] && tags="" |
| 74 | final_query_string="${query_string}" |
| 75 | final_query_string="${final_query_string}&operation=${operation}" |
| 76 | final_query_string="${final_query_string}&value=${value}" |
| 77 | final_query_string="${final_query_string}&comment=${comment}" |
| 78 | final_query_string="${final_query_string}&tags=${tags}" |
| 79 | url="https://osm.etsi.org/InstallLog.php?${final_query_string}" |
| 80 | echo "Track $osm_track_event_name $operation: ${url}" |
| garciadeblas | e572aab | 2022-01-14 11:19:16 +0100 | [diff] [blame] | 81 | LANG=C wget -q -O /dev/null "$url" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 82 | done |
| 83 | fi |
| 84 | return 0 |
| 85 | } |
| 86 | |
| 87 | |