posts:conky:*.sh|*.pl: add emerge scripts for conky.
[blog.git] / posts / conky / emerge-status.sh
1 #!/bin/bash
2 #
3 # emerge-status.sh by Hellf[i]re
4 #
5 # This script will report the current status of portage.
6 #
7 # Usage:
8 # .conkyrc:     ${execi [time] /path/to/script/emerge-current.sh}
9 #
10 # Usage Example
11 #               ${execi 30 /home/youruser/scripts/emerge-current.sh}
12 #
13 # Known Bugs:
14 #  1) If there are two emerges running at once, when the first one finishes 
15 #     running, the script will report the current status as "Completed".
16 #  2) If there is a emerge running and you run a search, the script will
17 #     report the current status as "Completed", until the running emerge
18 #     moves to the next package, or itself completes.
19 #  The reasons for this are twofold - one, it's a feature ;) and two, there
20 #  would be far too much parsing required to find out the current status of
21 #  every command which is run in parallel.
22
23 STATUS=`tail -n 15 /var/log/emerge.log |\
24 grep -iE "Compiling|Cleaning|AUTOCLEAN|completed|search|terminating|rsync" |\
25 cut -d ' ' -f "2-" |\
26 grep -Ev 'Finished\.|Cleaning up\.\.\.' |\
27 tail -n 1`
28
29 #echo "$STATUS"
30
31 if [ "`echo "$STATUS" | grep -i compiling`" != "" ]; then echo Compiling
32 elif [ "`echo "$STATUS" | grep -i cleaning`" != "" ]; then echo Cleaning
33 elif [ "`echo "$STATUS" | grep -i autoclean`" != "" ]; then echo Autoclean
34 elif [ "`echo "$STATUS" | grep -i sync`" != "" ]; then echo Syncing
35 elif [ "`echo "$STATUS" | grep -i search`" != "" ]; then echo Searching
36 elif [ "`echo "$STATUS" | grep -i completed`" != "" ]; then echo Completed
37 elif [ "`echo "$STATUS" | grep -i terminating`" != "" ]; then echo Completed
38 else echo Script Error!
39 fi