Pre-2.0 release, MFC some driver fixes related to interrupt management.
[dragonfly.git] / etc / periodic / monthly / 300.statistics
blob20e983b38675397e6cdd90e365eba6fdc1e189a9
1 #!/bin/sh -
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 ]
9 then
10 . /etc/defaults/periodic.conf
11 source_periodic_confs
12 periodic_conf=/etc/periodic.conf
13 else
14 . /etc/rc.conf # For systems without periodic.conf, use rc.conf
15 if [ -r /etc/rc.conf.local ]
16 then
17 . /etc/rc.conf.local
19 periodic_conf=/etc/rc.conf.local
22 oldmask=$(umask)
23 umask 066
25 version="4.7"
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
31 export PATH
33 unset HTTP_USER_AGENT
35 IFS="
38 random () {
39 jot -r 1 0 900
42 # RFC 2396
43 uri_escape () {
44 echo ${1+$@} | sed -e '
45 s/%/%25/g
46 s/;/%3b/g
47 s,/,%2f,g
48 s/?/%3f/g
49 s/:/%3a/g
50 s/@/%40/g
51 s/&/%26/g
52 s/=/%3d/g
53 s/+/%2b/g
54 s/\$/%24/g
55 s/,/%2c/g
56 s/ /%20/g
60 do_fetch () {
61 url="http://$checkin_server/scripts/$1"
62 case $(uname) in
63 FreeBSD )
64 /usr/bin/fetch -q -o - "$url"
66 * )
67 /usr/bin/ftp -V -o - "$url"
69 esac
72 check_dns () {
73 if [ `dig bsdstats.org txt | grep TXT | grep UP | wc -l` = 0 ]
74 then
75 echo "DNS not reachable, Network Down?"
76 exit
79 send_devices () {
80 case $(uname) in
81 FreeBSD )
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`
88 done
90 report_devices
92 * )
93 # Not supported
95 esac
98 report_devices () {
99 do_fetch report_devices.php?token=$TOKEN\&key=$KEY$query_string | {
100 local IFS
101 IFS='=
104 while read var val
106 case $var in
107 STATUS)
108 if [ $val = "OK" ]
109 then
110 echo "[`date`] System Devices reported"
111 else
112 echo "[`date`] System Devices not reported, exiting"
113 exit
117 echo "[`date`] Error with fetch to server"
118 exit
120 esac
121 done
122 } >> $bsdstats_log
125 get_id_token () {
126 if [ -f $id_token_file ]
127 then
128 if [ `cat /var/db/bsdstats | wc -l` -lt 3 ]
129 then
130 rm $id_token_file
134 if [ ! -f $id_token_file -o ! -s $id_token_file ] ;
135 then
136 IDTOKEN=$(uri_escape $( openssl rand -base64 32 ) )
138 idf=$( mktemp "$id_token_file.XXXXXX" ) && \
139 chown root:wheel $idf && \
140 chmod 600 $idf
142 do_fetch getid.php?key=$IDTOKEN | {
143 local IFS
144 IFS='=
147 while read var val
149 case $var in
150 KEY)
151 echo "KEY=$val"
153 TOKEN)
154 echo "TOKEN=$val"
158 esac
159 done
160 echo "VERSION=$version"
161 } > $idf && \
163 mv $idf $id_token_file
164 if [ ! -s $id_token_file ] ;
165 then
166 echo "Nothing returned from $checkin_server"
167 exit 1
170 . $id_token_file
171 KEY=$( uri_escape $KEY )
172 TOKEN=$( uri_escape $TOKEN )
176 enable_token () {
177 do_fetch enable_token.php?key=$TOKEN\&token=$KEY | {
178 local IFS
179 IFS='=
182 while read var val
184 case $var in
185 STATUS)
186 if [ $val = "OK" ]
187 then
188 echo "[`date`] System enabled"
189 else
190 echo "[`date`] System not enabled, exiting"
191 exit
195 echo "[`date`] Error with fetch to server"
196 exit
198 esac
199 done
200 } >> $bsdstats_log
203 disable_token () {
204 do_fetch disable_token.php?key=$TOKEN\&token=$KEY | {
205 local IFS
206 IFS='=
209 while read var val
211 case $var in
212 STATUS)
213 if [ $val = "OK" ]
214 then
215 echo "[`date`] System disabled"
216 else
217 echo "[`date`] System not disabled, exiting"
218 exit
222 echo "[`date`] Error with fetch to server"
223 exit
225 esac
226 done
227 } >> $bsdstats_log
230 report_system () {
231 do_fetch report_system.php?token=$TOKEN\&key=$KEY\&rel=$REL\&arch=$ARCH\&opsys=$OS | {
232 local IFS
233 IFS='=
236 while read var val
238 case $var in
239 STATUS)
240 if [ $val = "OK" ]
241 then
242 echo "[`date`] System reported"
243 else
244 echo "[`date`] System report failed, exiting"
245 exit
249 echo "[`date`] Error with fetch to server"
250 exit
252 esac
253 done
254 } >> $bsdstats_log
257 report_cpu () {
258 do_fetch report_cpu.php?token=$TOKEN\&key=$KEY\&cpus=$count\&vendor=$VEN\&cpu_type=$DEV | {
259 local IFS
260 IFS='=
263 while read var val
265 case $var in
266 STATUS)
267 if [ $val = "OK" ]
268 then
269 echo "[`date`] System CPU reported"
270 else
271 echo "[`date`] System CPU report failed, exiting"
272 exit
276 echo "[`date`] Error with fetch to server"
277 exit
279 esac
280 done
281 } >> $bsdstats_log
283 case "$monthly_statistics_enable" in
284 [Yy][Ee][Ss])
285 check_dns
286 HN=`/bin/hostname`
287 REL=`/usr/bin/uname -r`
288 ARCH=`/usr/bin/uname -m`
289 OS=`/usr/bin/uname -s`
290 get_id_token
291 sleep `random`
292 enable_token
293 report_system
294 echo "Posting monthly OS statistics to $checkin_server"
295 case "$monthly_statistics_report_devices" in
296 [Yy][Ee][Ss])
297 send_devices
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 )
303 report_cpu
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"
310 esac
311 disable_token
314 echo "Posting monthly OS statistics disabled"
315 echo " set monthly_statistics_enable=\"YES\" in $periodic_conf"
317 esac
319 umask $oldmask
320 exit $rc