From: W. Trevor King Date: Thu, 6 Dec 2012 17:39:58 +0000 (-0500) Subject: posts:conky:*.sh|*.pl: add emerge scripts for conky. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2a5f1fc65c58babe531a83927763ca5589fb2f81;p=blog.git posts:conky:*.sh|*.pl: add emerge scripts for conky. Scripts are from http://conky.sourceforge.net/screenshots.html: http://conky.sourceforge.net/emerge-current.sh http://conky.sourceforge.net/emerge-progress.sh http://conky.sourceforge.net/emerge-status.sh http://conky.sourceforge.net/lastsync.pl --- diff --git a/posts/conky/emerge-current.sh b/posts/conky/emerge-current.sh new file mode 100755 index 0000000..47067e5 --- /dev/null +++ b/posts/conky/emerge-current.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# emerge-current.sh by Hellf[i]re +# +# This script is designed to read the name of the last package compiled. +# +# As this script does read the entirety of emerge.log, it will be rather +# heavy on the CPU. It shouldn't be enough to be noticable on newer (2.0Ghz+) +# processors, but it still should not be run more often than every 30 seconds. +# +# Usage: +# .conkyrc: ${execi [time] /path/to/script/emerge-current.sh} +# +# Usage Example +# ${execi 30 /home/youruser/scripts/emerge-current.sh} + +tac /var/log/emerge.log |\ +grep 'Compiling' |\ +head |\ +sed -e 's/.*(//' |\ +sed -e 's/::.*)//' |\ +head -n 1 |\ +cut -d \) -f 1 + + + diff --git a/posts/conky/emerge-progress.sh b/posts/conky/emerge-progress.sh new file mode 100755 index 0000000..1f28f73 --- /dev/null +++ b/posts/conky/emerge-progress.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# source: Jeremy_Z @ forums.gentoo.org http://forums.gentoo.org/viewtopic-t-351806-postdays-0-postorder-asc-start-550.html +# +# This script will report the progress of the last emerge command run. It +# reports the TOTAL percentage complete - not the percentage of the current +# package. For example, if there are 110 packages currently being emerged, and +# it is on the 55th package, it will report 50. +# +# Usage: +# .conkyrc: ${execibar [time] /path/to/script/emerge-progress.sh} +# +# Usage Example +# ${execibar 30 /home/youruser/scripts/emerge-progress.sh} + +tail -n 50 /var/log/emerge.log |\ +tac |\ +grep -v "Starting retry" |\ +grep -iE '([0-9]* of [0-9]*)' -o -m 1 |\ +sed -e 's/\(.*\) of \(.*\)/\1 \2/' |\ +awk '{print 100.0*$1/$2}' diff --git a/posts/conky/emerge-status.sh b/posts/conky/emerge-status.sh new file mode 100755 index 0000000..a1241ef --- /dev/null +++ b/posts/conky/emerge-status.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# emerge-status.sh by Hellf[i]re +# +# This script will report the current status of portage. +# +# Usage: +# .conkyrc: ${execi [time] /path/to/script/emerge-current.sh} +# +# Usage Example +# ${execi 30 /home/youruser/scripts/emerge-current.sh} +# +# Known Bugs: +# 1) If there are two emerges running at once, when the first one finishes +# running, the script will report the current status as "Completed". +# 2) If there is a emerge running and you run a search, the script will +# report the current status as "Completed", until the running emerge +# moves to the next package, or itself completes. +# The reasons for this are twofold - one, it's a feature ;) and two, there +# would be far too much parsing required to find out the current status of +# every command which is run in parallel. + +STATUS=`tail -n 15 /var/log/emerge.log |\ +grep -iE "Compiling|Cleaning|AUTOCLEAN|completed|search|terminating|rsync" |\ +cut -d ' ' -f "2-" |\ +grep -Ev 'Finished\.|Cleaning up\.\.\.' |\ +tail -n 1` + +#echo "$STATUS" + +if [ "`echo "$STATUS" | grep -i compiling`" != "" ]; then echo Compiling +elif [ "`echo "$STATUS" | grep -i cleaning`" != "" ]; then echo Cleaning +elif [ "`echo "$STATUS" | grep -i autoclean`" != "" ]; then echo Autoclean +elif [ "`echo "$STATUS" | grep -i sync`" != "" ]; then echo Syncing +elif [ "`echo "$STATUS" | grep -i search`" != "" ]; then echo Searching +elif [ "`echo "$STATUS" | grep -i completed`" != "" ]; then echo Completed +elif [ "`echo "$STATUS" | grep -i terminating`" != "" ]; then echo Completed +else echo Script Error! +fi diff --git a/posts/conky/lastsync.pl b/posts/conky/lastsync.pl new file mode 100755 index 0000000..37bef03 --- /dev/null +++ b/posts/conky/lastsync.pl @@ -0,0 +1,7 @@ +#!/usr/bin/perl +use Date::Manip; + +$date = `grep "Sync completed" /var/log/emerge.log | tail -n1 | cut -c-10`; +$date = &DateCalc("Jan 1, 1970 00:00:00 GMT",$date); +$date = UnixDate("$date","%A %H:%M"); +print "$date";