slitaz-tools view sdt/sdt @ rev 1029

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:26:53 2019 +0100 (2019-02-26)
parents ff7076d04f2e
children
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 date="$(date +%Y%m%d)"
12 mark="$HOME/.cache/slitaz/sdt.log"
14 get_geoloc() {
15 # freegeoip.net/<format>/[<ip_or_hostname>]
16 # Example: wget freegeoip.net/csv/$ip -O /tmp/geoloc
17 wget -q http://freegeoip.net/csv/ -O- | cut -d, -f3
18 }
20 get_mode() {
21 if grep -q "root=/dev/null" /proc/cmdline; then
22 echo "live"
23 else
24 echo "install"
25 fi
26 }
28 case "$1" in
29 get-stats)
30 # Get some info from the DB
31 title "SDT Stats"
32 if wget -q -T 5 --spider $url; then
33 echo "Tracker is online..."
34 wget -q "$url?sdt=raw" -O-
35 else
36 echo "Tracker is unreachable..."
37 fi
38 footer
39 ;;
40 send)
41 # Send stats to online DB
42 if [ -f "$mark" ]; then
43 echo "It looks like you already sent this distro to the DB"
44 exit 0
45 fi
46 user="$2"
47 [ -n "$user" ] || user="anonymous"
48 country=$(get_geoloc)
49 release=$(cat /etc/slitaz-release)
50 kernel=$(uname -r)
51 mode=$(get_mode)
52 cat <<EOT
54 $(boldify "Information that will be sent to the SliTaz Distro Tracker")
55 $(separator)
56 User : $user
57 Country : $country
58 Release : SliTaz $release
59 Kernel : $kernel
60 Running : $mode
61 EOT
62 footer
63 echo "Send this data to SliTaz Distro Tracker?"
64 echo -n "Press 'c' then ENTER to continue or any other key to quit: "
65 read answer; newline
66 [ "$answer" = 'c' ] || exit 0
68 echo "Sending data to $url"; newline
69 wget -q --user-agent "SliTaz/SDT" \
70 "$url?sdt=add&user=$user&country=$country&release=$release&kernel=$kernel&mode=$mode" \
71 -O-
72 mkdir -p $(dirname $mark)
73 echo "sent" > $mark
74 ;;
75 *)
76 newline
77 echo "$(boldify 'Usage:') $(basename $0) [get-stats|send] [username]"
78 newline
79 ;;
80 esac
81 exit 0