slitaz-tools view sdt/sdt @ rev 1011

Add sdt SliTaz Distro Tracker
author Christophe Lincoln <pankso@slitaz.org>
date Sat Feb 11 23:41:23 2017 +0100 (2017-02-11)
parents
children b62b418ee6e7
line source
1 #!/bin/sh
2 #
3 # SDT - SliTaz Distro Tracker Cmdline client
4 #
5 # (C) SliTaz GNU/Linux 2017 - BSD License
6 #
7 . /lib/libtaz.sh
9 version="0.1"
10 url="http://scn.slitaz.org/"
11 tmp="/tmp/$(basename $0).msg"
12 date="$(date +%Y%m%d)"
14 get_geoloc() {
15 # freegeoip.net/{format}/{ip_or_hostname}
16 # Exemple: wget freegeoip.net/csv/${ip} -O /tmp/geoloc
17 wget -q "${url}?sdt=geoloc" -O ${tmp}
18 ip=$(cat ${tmp}) && rm ${tmp}
19 wget -q freegeoip.net/csv/${ip} -O /tmp/geoloc
20 country=$(cat /tmp/geoloc | cut -d ',' -f 3 )
21 echo "$country" && rm -f /tmp/geoloc
22 }
24 get_mode() {
25 if grep -q "root=/dev/null" /proc/cmdline; then
26 echo "live"
27 else
28 echo "install"
29 fi
30 }
32 case "$1" in
33 get-stats)
34 # Get some info from the DB
35 newline
36 boldify "SDT Stats"
37 separator
38 if wget -q -T 5 --spider ${url}; then
39 echo "Tracker in online..."
40 wget -q "${url}?sdt=raw" -O ${tmp} && cat ${tmp} && rm ${tmp}
41 else
42 echo "Tracker in unreachable..."
43 fi
44 separator && newline ;;
45 send)
46 # Send stats to online DB
47 user="$2"
48 [ "$user" ] || user="anonymous"
49 country=$(get_geoloc)
50 release=$(cat /etc/slitaz-release)
51 kernel=$(uname -r)
52 mode=$(get_mode)
53 cat << EOT
55 $(boldify "Informations sent to SliTaz Distro Tracker")
56 $(separator)
57 User : ${user}
58 Country : ${country}
59 Release : SliTaz ${release}
60 Kernel : ${kernel}
61 Running : ${mode}
62 EOT
63 separator && newline
64 echo "Send these data to SliTaz Distro Tracker ? "
65 echo -n "Press 'c' then ENTER to continue or any other key to quit: "
66 read anser && newline
67 if [ "$anser" != "c" ]; then
68 exit 0
69 fi
70 echo "Sending data to: $url" && newline
71 wget -q --user-agent "SliTaz/SDT" \
72 "${url}?sdt=add&user=${user}&country=${country}&release=${release}&kernel=${kernel}&mode=${mode}" \
73 -O ${tmp} && cat ${tmp} && rm ${tmp}
74 ;;
75 *)
76 newline
77 echo "$(boldify 'Usage:') $(basename $0) [get-stats|send] [username]"
78 newline ;;
79 esac
80 exit 0