blob: 627c680d9b955b960aa45c1acf1f7cd411abdfcf [file] [log] [blame]
garciadeblas0bc87522021-10-20 22:16:17 +02001#!/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
17function 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}"
57 wget -q -O /dev/null $url
58 else
59 while (( "$#" > 0 )); do
60 operation="${1:-${osm_track_event_name}}"
61 shift 1
62 value="${1:-}"
63 shift 1
64 comment="${1:-}"
65 shift 1
66 comment="${comment// /_}"
67 tags="${1:-}"
68 shift 1
69 tags="${tags//,/\~}"
70 [ "$value" == "none" ] && value=""
71 [ "$comment" == "none" ] && comment=""
72 [ "$tags" == "none" ] && tags=""
73 final_query_string="${query_string}"
74 final_query_string="${final_query_string}&operation=${operation}"
75 final_query_string="${final_query_string}&value=${value}"
76 final_query_string="${final_query_string}&comment=${comment}"
77 final_query_string="${final_query_string}&tags=${tags}"
78 url="https://osm.etsi.org/InstallLog.php?${final_query_string}"
79 echo "Track $osm_track_event_name $operation: ${url}"
80 wget -q -O /dev/null $url
81 done
82 fi
83 return 0
84}
85
86