]> git.somenet.org - somenet/munin.git/blob - cron/cron_portage.sh
hostapd stats script
[somenet/munin.git] / cron / cron_portage.sh
1 #!/bin/sh
2
3 if [ ! -e "/tmp/munin_portage/timestamp.chk" -o -n "`diff -N -q /tmp/munin_portage/timestamp.chk /usr/portage/metadata/timestamp.chk`" ]; then
4 mkdir -p /tmp/munin_portage/
5
6 if [ -e "/tmp/munin_portage/running.lock" ]; then
7   echo 'another instance is still running. rm "/tmp/munin_portage/running.lock"'>&2
8   exit 0;
9 else
10   echo "running since: `date`" > /tmp/munin_portage/running.lock
11 fi
12
13 if [ -e "/tmp/munin_portage/ebuilds.txt" ]; then
14   mv /tmp/munin_portage/ebuilds.txt /var/lib/munin_portage_ebuilds.txt
15 fi
16 if [ -e "/tmp/munin_portage/packages.txt" ]; then
17   mv /tmp/munin_portage/packages.txt /var/lib/munin_portage_packages.txt
18 fi
19
20 find /usr/portage/ -mindepth 3 -maxdepth 3 -iname '*.ebuild' | grep -v "/usr/portage/distfiles" | grep -v "/usr/portage/metadata" | grep -v "/usr/portage/profiles" | sort > /tmp/munin_portage/ebuilds.txt
21 find /usr/portage/ -mindepth 2 -maxdepth 2 -type d | grep -v "/usr/portage/profiles/" | grep -v "/usr/portage/metadata/" | grep -v "/usr/portage/distfiles/" | grep -v "/usr/portage/eclass/" | sort > /tmp/munin_portage/packages.txt
22
23 if [ ! -e "/var/lib/munin_portage_ebuilds.txt" ]; then
24   cp /tmp/munin_portage/ebuilds.txt /var/lib/munin_portage_ebuilds.txt
25 fi
26 if [ ! -e "/var/lib/munin_portage_packages.txt" ]; then
27   cp /tmp/munin_portage/packages.txt /var/lib/munin_portage_packages.txt
28 fi
29
30 echo "packages.value `cat /tmp/munin_portage/packages.txt | wc -l`" > /tmp/munin_portage/packages.stat
31 echo "ebuilds.value `cat /tmp/munin_portage/ebuilds.txt | wc -l`" > /tmp/munin_portage/ebuilds.stat
32 echo "ebadded.value `diff -u0 /var/lib/munin_portage_ebuilds.txt /tmp/munin_portage/ebuilds.txt | grep -v @@ | grep '+/' | wc -l`" > /tmp/munin_portage/ebuilds_added.stat
33 echo "ebremoved.value `diff -u0 /var/lib/munin_portage_ebuilds.txt /tmp/munin_portage/ebuilds.txt | grep -v @@ | grep -e '-/' | wc -l`" > /tmp/munin_portage/ebuilds_removed.stat
34 echo "pkgadded.value `diff -u0 /var/lib/munin_portage_packages.txt /tmp/munin_portage/packages.txt | grep -v @@ | grep '+/' | wc -l`" > /tmp/munin_portage/packages_added.stat
35 echo "pkgremoved.value `diff -u0 /var/lib/munin_portage_packages.txt /tmp/munin_portage/packages.txt | grep -v @@ | grep -e '-/' | wc -l`" > /tmp/munin_portage/packages_removed.stat
36
37 emerge -qpuDN --package-moves=n --with-bdeps=y --color n @world | sed 's/^\[[^]]*\] //' > /tmp/munin_portage/updates.txt
38 echo "updates.extinfo `cat /tmp/munin_portage/updates.txt | awk '{ printf "%s ", $0 }'`" > /tmp/munin_portage/updates.list
39 echo "updates.value `cat /tmp/munin_portage/updates.txt | wc -l`" > /tmp/munin_portage/updates.stat
40
41 cp /usr/portage/metadata/timestamp.chk /tmp/munin_portage/timestamp.chk
42 rm /tmp/munin_portage/running.lock
43 fi
44