Tuesday, December 23, 2008

Scripts...

I use some scripts in my rc.lua file which I guess I need to post in order for some of the widgets to work. These are not my original work, I got them from various sources on the inturwub. I cant remember where so I cant give the credit where it is due.

The first one tells you the current or last emerged package.

#!/bin/bash
#emerge-current.sh
tac /var/log/emerge.log |\
grep 'Compiling' |\
head |\
sed -e 's/.*(//' |\
sed -e 's/::.*)//' |\
head -n 1 |\
cut -d \) -f 1

The next one tells the progress in percentage.

#!/bin/bash
# This script will report the progress of the last emerge command run.
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}'

The next one tells us the status of the current package being emerged.

#!/bin/bash

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

And the final one will show us when the last-sync was. (This one requires the Date::Manip perl module)

#!/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";

I also use a little script to show my current ip.

#!/bin/bash
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

And finally I use a script to download a image of the world with the current state of darkness and use it as my desktop. You will have to edit this one to suit your resolution. I have this set as a cron job which executes once a hour to get me the latest desktop picture.

#!/bin/bash
#
# Save this script to somewhere like "/home/(user)", "chmod a+x" it,
# edit it to change the correct IMAGEFILE for your screen size,
# then run "crontab -e" and add a line like this:
#
# 0 * * * * DISPLAY:0 /home/(user)/xplanetdisplay.sh

MIRROR=http://taint.org/xplanet/
IMAGEFILE=day_clouds_2048x1024.png

###########################################################################

[ -f $HOME/.exports ] && . $HOME/.exports
PATH=$PATH:/usr/local/bin:/usr/X11/bin
export DISPLAY PATH HOME LANG XAUTHORITY SESSION_MANAGER

tmpdir=$HOME/.xplanetroot
[ -d $tmpdir ] || mkdir $tmpdir
cd $tmpdir

if wget -qN $MIRROR/$IMAGEFILE ; then
feh --bg-scale $IMAGEFILE
fi

No comments: