slitaz-tools view sdt/sdt @ rev 1014

/sdt: tiny edits
author Paul Issott <paul@slitaz.org>
date Sun Feb 12 09:20:08 2017 +0000 (2017-02-12)
parents b62b418ee6e7
children ff7076d04f2e
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 # Example: 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 is online..."
40 wget -q "${url}?sdt=raw" -O ${tmp} && cat ${tmp} && rm ${tmp}
41 else
42 echo "Tracker is unreachable..."
43 fi
44 separator && newline ;;
45 send)
46 # Send stats to online DB
47 if [ -f "${HOME}/.cache/slitaz/sdt.log" ]; then
48 echo "It looks like you already sent this distro to the DB"
49 exit 0
50 fi
51 user="$2"
52 [ "$user" ] || user="anonymous"
53 country=$(get_geoloc)
54 release=$(cat /etc/slitaz-release)
55 kernel=$(uname -r)
56 mode=$(get_mode)
57 cat << EOT
59 $(boldify "Information sent to the SliTaz Distro Tracker")
60 $(separator)
61 User : ${user}
62 Country : ${country}
63 Release : SliTaz ${release}
64 Kernel : ${kernel}
65 Running : ${mode}
66 EOT
67 separator && newline
68 echo "Send this data to SliTaz Distro Tracker ? "
69 echo -n "Press 'c' then ENTER to continue or any other key to quit: "
70 read anser && newline
71 if [ "$anser" != "c" ]; then
72 exit 0
73 fi
74 echo "Sending data to: $url" && newline
75 wget -q --user-agent "SliTaz/SDT" \
76 "${url}?sdt=add&user=${user}&country=${country}&release=${release}&kernel=${kernel}&mode=${mode}" \
77 -O ${tmp} && cat ${tmp} && rm ${tmp}
78 mkdir -p ${HOME}/.cache/slitaz
79 echo "sent" > ${HOME}/.cache/slitaz/sdt.log ;;
80 *)
81 newline
82 echo "$(boldify 'Usage:') $(basename $0) [get-stats|send] [username]"
83 newline ;;
84 esac
85 exit 0