3 # $FreeBSD: ports/sysutils/bsdstats/files/300.statistics,v 1.31 2006/10/03 01:33:11 scrappy Exp $
4 # $DragonFly: src/etc/periodic/monthly/300.statistics,v 1.1 2006/10/04 21:39:23 dillon Exp $
6 # If there is a global system configuration file, suck it in.
8 if [ -r /etc
/defaults
/periodic.conf
]
10 .
/etc
/defaults
/periodic.conf
12 periodic_conf
=/etc
/periodic.conf
14 .
/etc
/rc.conf
# For systems without periodic.conf, use rc.conf
15 if [ -r /etc
/rc.conf.
local ]
19 periodic_conf
=/etc
/rc.conf.
local
26 checkin_server
=${monthly_statistics_checkin_server:-"bsdstats.org"}
27 bsdstats_log
=${monthly_statistics_logfile:-"/var/log/bsdstats"}
28 id_token_file
='/var/db/bsdstats'
30 PATH
=/sbin
:/bin
:/usr
/sbin
:/usr
/bin
:/usr
/local
/sbin
:/usr
/local
/bin
44 echo ${1+$@} |
sed -e '
61 url
="http://$checkin_server/scripts/$1"
64 /usr
/bin
/fetch
-q -o - "$url"
67 /usr
/bin
/ftp -V -o - "$url"
73 if [ `dig bsdstats.org txt | grep TXT | grep UP | wc -l` = 0 ]
75 echo "DNS not reachable, Network Down?"
82 for line
in `/usr/sbin/pciconf -l | /usr/bin/grep -v none`
84 DRIVER
=`echo $line | awk -F\@ '{print $1}'`
85 DEV
=`echo $line | awk '{print $4}' | cut -c8-15`
86 CLASS
=`echo $line | awk '{print $2}' | cut -c9-14`
87 query_string
=$query_string`echo \&dev[]=$DRIVER:$DEV:$CLASS`
99 do_fetch report_devices.php?token
=$TOKEN\
&key
=$KEY$query_string |
{
110 echo "[`date`] System Devices reported"
112 echo "[`date`] System Devices not reported, exiting"
117 echo "[`date`] Error with fetch to server"
126 if [ -f $id_token_file ]
128 if [ `cat /var/db/bsdstats | wc -l` -lt 3 ]
134 if [ ! -f $id_token_file -o ! -s $id_token_file ] ;
136 IDTOKEN
=$
(uri_escape $
( openssl rand
-base64 32 ) )
138 idf
=$
( mktemp
"$id_token_file.XXXXXX" ) && \
139 chown root
:wheel
$idf && \
142 do_fetch getid.php?key
=$IDTOKEN |
{
160 echo "VERSION=$version"
163 mv $idf $id_token_file
164 if [ ! -s $id_token_file ] ;
166 echo "Nothing returned from $checkin_server"
171 KEY
=$
( uri_escape
$KEY )
172 TOKEN
=$
( uri_escape
$TOKEN )
177 do_fetch enable_token.php?key
=$TOKEN\
&token
=$KEY |
{
188 echo "[`date`] System enabled"
190 echo "[`date`] System not enabled, exiting"
195 echo "[`date`] Error with fetch to server"
204 do_fetch disable_token.php?key
=$TOKEN\
&token
=$KEY |
{
215 echo "[`date`] System disabled"
217 echo "[`date`] System not disabled, exiting"
222 echo "[`date`] Error with fetch to server"
231 do_fetch report_system.php?token
=$TOKEN\
&key
=$KEY\
&rel
=$REL\
&arch
=$ARCH\
&opsys
=$OS |
{
242 echo "[`date`] System reported"
244 echo "[`date`] System report failed, exiting"
249 echo "[`date`] Error with fetch to server"
258 do_fetch report_cpu.php?token
=$TOKEN\
&key
=$KEY\
&cpus
=$count\
&vendor
=$VEN\
&cpu_type
=$DEV |
{
269 echo "[`date`] System CPU reported"
271 echo "[`date`] System CPU report failed, exiting"
276 echo "[`date`] Error with fetch to server"
283 case "$monthly_statistics_enable" in
287 REL
=`/usr/bin/uname -r`
288 ARCH
=`/usr/bin/uname -m`
289 OS
=`/usr/bin/uname -s`
294 echo "Posting monthly OS statistics to $checkin_server"
295 case "$monthly_statistics_report_devices" in
298 echo "Posting monthly device statistics to $checkin_server"
299 line
=$
( sysctl
-n hw.model
)
300 VEN
=$
( echo $line | cut
-d ' ' -f 1 )
301 DEV
=$
( uri_escape $
( echo $line | cut
-d ' ' -f 2- ) )
302 count
=$
( sysctl
-n hw.ncpu
)
304 echo "Posting monthly CPU statistics to $checkin_server"
307 echo "Posting monthly device/CPU statistics disabled"
308 echo " set monthly_statistics_report_devices=\"YES\" in $periodic_conf"
314 echo "Posting monthly OS statistics disabled"
315 echo " set monthly_statistics_enable=\"YES\" in $periodic_conf"