View previous topic :: View next topic |
Author |
Message |
koprimer n00b
Joined: 29 Feb 2004 Posts: 64
|
Posted: Fri Oct 27, 2006 5:30 pm Post subject: Emerge Progress Script (using bash + dialog) |
|
|
I know there are a lot of scripts out there to display the progress of emerge. Mine uses bash scripting and dialogs. Just ^C to exit out of the status. You can also bypass the dialog and have it just print out the progress once. It's probably not as good as some I've seen, but it's a start. You can also get the code here. enjoy!
estatus:
Code: | #!/bin/bash
#/***************************************************************************
#* Copyright (C) 2005 by coprime *
#* coprime@rootshell.be *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU General Public License as published by *
#* the Free Software Foundation; either version 2 of the License, or *
#* (at your option) any later version. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU General Public License for more details. *
#* *
#* You should have received a copy of the GNU General Public License *
#* along with this program; if not, write to the *
#* Free Software Foundation, Inc., *
#* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
#****************************************************************************/
trap "exit" SIGINT SIGTERM
#stty intr '^['
TMPPORT="/var/tmp/portage"
EMERGELOG="/var/log/emerge.log"
printusage() {
echo -e "usage: $0 [<option>]\n\tEmerge Status v1.0 - by coprime\n\n" \
"\tOption:\t\tDescription:\n\t-p\t\tPrints out emerge status\n" \
"\t-h\t\tPrints out this help"
}
getdialog() {
DIALOG=`which dialog 2>/dev/null`
#other dialogs are too much of a pain
#XDIALOG=`which xdialog 2>/dev/null`
#KDIALOG=`which kdialog 2>/dev/null`
#GDIALOG=`which gdialog 2>/dev/null`
# use other dialogs if possible
#[ -n "$DISPLAY" ] && {
# if [ -n "$XDIALOG" ]; then
# DIALOG=$XDIALOG
# elif [ -n "$KDIALOG" ]; then
# DIALOG=$KDIALOG
# elif [ -n "$GDIALOG" ]; then
# DIALOG=$GDIALOG
# fi
#}
}
getper() {
NAME=`tail -n 2 $EMERGELOG | grep Compiling | sed "s/\(.*\)Compiling\/Merging \(.*\)::.*/\2/" | sed "s/(\([a-zA-Z].*\)\/\(.*\)/\1\/\2/" 2>/dev/null`
CUR=`echo $NAME | sed "s/\(.*\)\/\(.*\)/\2/" 2>/dev/null`
TOT=`find $TMPPORT/$CUR -iname "*.c*" | wc -l 2>/dev/null`
PROG=`find $TMPPORT/$CUR -iname "*.o*" | wc -l 2>/dev/null`
((${#TOT} != 0)) && PER=`echo \`bc -l <<< $PROG/$TOT*100\` / 1 | bc 2>/dev/null`
((${#PER} > 100)) && PER="100"
((${#NAME} == 0)) && NAME="nothing" && PER="0"
}
printstatus() {
[ -d $TMPPORT ] && [ -r $TMPPORT ] && {
getper
echo "Current percentage: $PER% ($NAME)"
}
}
dialogstatus() {
getdialog
[ -d $TMPPORT ] && [ -r $TMPPORT ] && {
while true; do
getper
TMP=$NAME
{
LOOP=true
while $LOOP; do
echo $PER
sleep 5
getper
[ $NAME != $TMP ] && LOOP=false
done
echo
} | $DIALOG --backtitle "Gentoo emerge status" --title "Gentoo emerge status" --gauge "Currently emerging $NAME..." 9 50 0 2>/dev/null
done
}
}
#main
getopts "hp" opt $@
case "$opt" in
h) printusage;;
p) printstatus;;
*) dialogstatus;;
esac
|
|
|
Back to top |
|
|
zietbukuel l33t
Joined: 30 Dec 2005 Posts: 607
|
Posted: Sun Oct 29, 2006 4:59 am Post subject: |
|
|
For the latest Portage change:
Code: |
CUR=`echo $NAME | sed "s/\(.*\)\/\(.*\)/\2/" 2>/dev/null` |
With:
And it now works...
Last edited by zietbukuel on Thu Nov 02, 2006 7:31 pm; edited 1 time in total |
|
Back to top |
|
|
nanafunk n00b
Joined: 29 Jun 2005 Posts: 36
|
Posted: Wed Nov 01, 2006 1:05 am Post subject: |
|
|
My two cents....
Code: |
getper() {
NAME=`tail -n 2 $EMERGELOG | grep Compiling | sed "s/\(.*\)Compiling\/Merging \(.*\)::.*/\2/" | sed "s/(\([a-zA-Z].*\)\/\(.*\)/\1\/\2/" 2>/dev/null`
CUR=`echo $NAME | sed "s/\(.*\)\/\(.*\)/\2/" 2>/dev/null`
TOT=`find $TMPPORT/$CUR -iname "*.c*" | wc -l 2>/dev/null`
PROG=`find $TMPPORT/$CUR -iname "*.o*" | wc -l 2>/dev/null`
((${#TOT} != 0)) && PER=`echo \`bc -l <<< $PROG/$TOT*100\` / 1 | bc 2>/dev/null`
((${#PER} > 100)) && PER="100"
((${#NAME} == 0)) && NAME="nothing" && PER="0"
}
|
All those 2>/dev/null's can be gotten rid of
Code: |
blah(){
command
command
} 2>/dev/null
|
sed can "tail" and it can also "grep", you can also do it in one sed command.
saves the pipeline, also variables should be quoted
Code: |
NAME=$(sed -n '$!N;$!D;/Compiling/s/.*(\([^:]*\).*/\1/p' "$EMERGELOG")
|
echo $VAR | sed , is usually redundant, as bash can do this for you
using "Parameter Expansion" (section on it in bash manual, also some online resources, if you'd like to read about it) quicker than using sed.
Also `` is the old style for command substitution, it's been depreceated in favour of $() , which can be nested easier, i think it looks nicer too.
[ is /usr/bin/[ , you could instead use [[ the bash builtin (faster than [), it can do everything [ can do, and it has some extra features.
If you'd like to read about it .... http://wooledge.org/mywiki/BashFaq#faq31
That wiki is very cool also, good resource for bash scripting.
also #bash @ irc.freenode.org
Nice script, thanks alot. |
|
Back to top |
|
|
koprimer n00b
Joined: 29 Feb 2004 Posts: 64
|
Posted: Thu Nov 02, 2006 5:21 pm Post subject: |
|
|
zietbukuel, thanks for the reply. I'm sure your fix will help a lot of others who have latest portage. I'll make sure to include the fix for the next stable release.
nanafunk, thanks a lot for the suggestions, I'll make sure to make the appropriate changes when I can. As you can tell, there's still a lot I need to learn when it comes to bash. The wiki link is great, it'll make a fine addition to my list of useful links |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|