slitaz-tools rev 1017
sdt/sdt: simplify...
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Tue Mar 14 02:36:18 2017 +0200 (2017-03-14) |
parents | 62187a6485ae |
children | c187e3d49df6 |
files | sdt/sdt |
line diff
1.1 --- a/sdt/sdt Tue Mar 14 01:22:17 2017 +0200 1.2 +++ b/sdt/sdt Tue Mar 14 02:36:18 2017 +0200 1.3 @@ -8,17 +8,13 @@ 1.4 1.5 version="0.1" 1.6 url="http://scn.slitaz.org/" 1.7 -tmp="/tmp/$(basename $0).msg" 1.8 date="$(date +%Y%m%d)" 1.9 +mark="$HOME/.cache/slitaz/sdt.log" 1.10 1.11 get_geoloc() { 1.12 - # freegeoip.net/{format}/{ip_or_hostname} 1.13 - # Example: wget freegeoip.net/csv/${ip} -O /tmp/geoloc 1.14 - wget -q "${url}?sdt=geoloc" -O ${tmp} 1.15 - ip=$(cat ${tmp}) && rm ${tmp} 1.16 - wget -q freegeoip.net/csv/${ip} -O /tmp/geoloc 1.17 - country=$(cat /tmp/geoloc | cut -d ',' -f 3 ) 1.18 - echo "$country" && rm -f /tmp/geoloc 1.19 + # freegeoip.net/<format>/[<ip_or_hostname>] 1.20 + # Example: wget freegeoip.net/csv/$ip -O /tmp/geoloc 1.21 + wget -q http://freegeoip.net/csv/ -O- | cut -d, -f3 1.22 } 1.23 1.24 get_mode() { 1.25 @@ -32,54 +28,54 @@ 1.26 case "$1" in 1.27 get-stats) 1.28 # Get some info from the DB 1.29 - newline 1.30 - boldify "SDT Stats" 1.31 - separator 1.32 - if wget -q -T 5 --spider ${url}; then 1.33 + title "SDT Stats" 1.34 + if wget -q -T 5 --spider $url; then 1.35 echo "Tracker is online..." 1.36 - wget -q "${url}?sdt=raw" -O ${tmp} && cat ${tmp} && rm ${tmp} 1.37 + wget -q "$url?sdt=raw" -O- 1.38 else 1.39 echo "Tracker is unreachable..." 1.40 fi 1.41 - separator && newline ;; 1.42 + footer 1.43 + ;; 1.44 send) 1.45 # Send stats to online DB 1.46 - if [ -f "${HOME}/.cache/slitaz/sdt.log" ]; then 1.47 + if [ -f "$mark" ]; then 1.48 echo "It looks like you already sent this distro to the DB" 1.49 exit 0 1.50 fi 1.51 user="$2" 1.52 - [ "$user" ] || user="anonymous" 1.53 + [ -n "$user" ] || user="anonymous" 1.54 country=$(get_geoloc) 1.55 release=$(cat /etc/slitaz-release) 1.56 kernel=$(uname -r) 1.57 mode=$(get_mode) 1.58 - cat << EOT 1.59 + cat <<EOT 1.60 1.61 -$(boldify "Information sent to the SliTaz Distro Tracker") 1.62 +$(boldify "Information that will be sent to the SliTaz Distro Tracker") 1.63 $(separator) 1.64 -User : ${user} 1.65 -Country : ${country} 1.66 -Release : SliTaz ${release} 1.67 -Kernel : ${kernel} 1.68 -Running : ${mode} 1.69 +User : $user 1.70 +Country : $country 1.71 +Release : SliTaz $release 1.72 +Kernel : $kernel 1.73 +Running : $mode 1.74 EOT 1.75 - separator && newline 1.76 - echo "Send this data to SliTaz Distro Tracker ? " 1.77 + footer 1.78 + echo "Send this data to SliTaz Distro Tracker?" 1.79 echo -n "Press 'c' then ENTER to continue or any other key to quit: " 1.80 - read anser && newline 1.81 - if [ "$anser" != "c" ]; then 1.82 - exit 0 1.83 - fi 1.84 - echo "Sending data to: $url" && newline 1.85 + read answer; newline 1.86 + [ "$answer" == 'c' ] || exit 0 1.87 + 1.88 + echo "Sending data to $url"; newline 1.89 wget -q --user-agent "SliTaz/SDT" \ 1.90 -"${url}?sdt=add&user=${user}&country=${country}&release=${release}&kernel=${kernel}&mode=${mode}" \ 1.91 - -O ${tmp} && cat ${tmp} && rm ${tmp} 1.92 - mkdir -p ${HOME}/.cache/slitaz 1.93 - echo "sent" > ${HOME}/.cache/slitaz/sdt.log ;; 1.94 +"$url?sdt=add&user=$user&country=$country&release=$release&kernel=$kernel&mode=$mode" \ 1.95 + -O- 1.96 + mkdir -p $(dirname $mark) 1.97 + echo "sent" > $mark 1.98 + ;; 1.99 *) 1.100 newline 1.101 echo "$(boldify 'Usage:') $(basename $0) [get-stats|send] [username]" 1.102 - newline ;; 1.103 + newline 1.104 + ;; 1.105 esac 1.106 exit 0