blob: 615286a65ed6ff071d4cf8f1437e8207a4f3ff9f [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}"
garciadeblase572aab2022-01-14 11:19:16 +010057 LANG=C wget -q -O /dev/null "$url"
garciadeblas0bc87522021-10-20 22:16:17 +020058 else
59 while (( "$#" > 0 )); do
60 operation="${1:-${osm_track_event_name}}"
61 shift 1
62 value="${1:-}"
garciadeblas4d89c372021-11-25 11:57:18 +010063 value="${value// /_}"
garciadeblas0bc87522021-10-20 22:16:17 +020064 shift 1
65 comment="${1:-}"
garciadeblas0bc87522021-10-20 22:16:17 +020066 comment="${comment// /_}"
garciadeblas0bc87522021-10-20 22:16:17 +020067 shift 1
garciadeblas4d89c372021-11-25 11:57:18 +010068 tags="${1:-}"
garciadeblas0bc87522021-10-20 22:16:17 +020069 tags="${tags//,/\~}"
garciadeblas4d89c372021-11-25 11:57:18 +010070 shift 1
garciadeblas0bc87522021-10-20 22:16:17 +020071 [ "$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}"
garciadeblase572aab2022-01-14 11:19:16 +010081 LANG=C wget -q -O /dev/null "$url"
garciadeblas0bc87522021-10-20 22:16:17 +020082 done
83 fi
84 return 0
85}
86
87