Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
re-emerge programs with selected USE-flag with 'sure'
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
MaJor_PerMutation
n00b
n00b


Joined: 23 Jul 2003
Posts: 61

PostPosted: Fri Dec 05, 2003 11:13 pm    Post subject: re-emerge programs with selected USE-flag with 'sure' Reply with quote

Be warned:
This is my very first script at all and my very first usage of programs like 'sed' (and overall regular expressions), so you know, what this means...
I take NO responsibility for anything the script does or does not do!
(but: on my system it runs flawless)

What is it?
It's called "sure", the
"_s_elected _u_se-flag _r_e-_e_merger"
and that's what it does.
You selected a USE-flag, can look-up infos, fetch sources and emerge programs accordings to this USE-flag.

I wrote it for this situation
(let's take this as example):
I added USE="crypt" to my 'make.conf' and now wanted to know
which ebuild make use of the "crypt"-flag and how do I re-emerge them instead of one-by-one.

How do I use it?
When you just enter 'sure' without anything else it shows a little help.
'sure's standard behaviour is to to just display infos according to the USE-flag you select. At the moment, there's only support for one flag.

So, a
Code:
sure crypt

gives you info like this:

Code:
net-mail/sylpheed
Description: "A lightweight email client and newsreader"
Version to re-emerge: 0.9.4
Size: 655474


and this, for every installed program on your system, which supports USE="crypt".


Options:
There are two options, "-f" and "-x", which can be combined to "-fx".
Examples:

"-f" (fetch-only)
Code:
sure -f crypt

Gathers the infos and shows them,
calls 'emerge', fetches all files,
and exits.

"-x": (execute)
Code:
sure -x crypt

Gather and show info,
call 'emerge' to do a "normal" emerge.
Normal means: fetching and building alternate.

-"fx": (fetch first, then execute)
Code:
sure -fx crypt

Gather and show info,
call 'emerge' to fetch all sources,
call emerge to build all programs,
and then exit.

Note:
'emerge' is only called for fetching/building and not for gathering the infos.
So, compared to a python 'emerge -s/S' or so,
it is very fast, at least at my system.

Limitations/ToDo:
(or: things which might be added, cleand up etc.
in the following version if there's interest/use for):
1: filter the programs which have already been installed with the selected USE-flag
2: break the one-flag-limit and according to this...
3: ...add support for logics like 'sure crypt AND/OR/NOT ssl'
4: fetch in background when first build has started
5: more options
6: Size in B,KB,MB instead of Bytes only
7: a color-output mode
8: learn more about programs (especially) like 'sed' and the regular expression to clean up this spaghetti-code

Bugs:
In rarely cases, the version of a program (in 'sure's list) is not
correctly displayed. It does not affect any other things.
As soon as I know how to correctly 'sed' this, I'll correct it.


And here it is, have fun and feel free to comment :-D:

just seen:
There are some long lines which get wrapped around... :(
will try to cut them, until then you have to manually correct them.
Sorry!

Code:

#!/bin/sh
#
# SURE - the _S_elected _U_seflag _R_e-_E_merger
# Version 002
#
# It take _NO_ responsibility for anything this script does or does not do!
#
# send anything you like (bugs. enhancement requests, ideas,  etc.)
# according to this script to "mjp.m@t-online.de"
#

# paranoid cleaning
rm -rf /tmp/sure002/ &> /dev/null
mkdir /tmp/sure002/ &> /dev/null

# truth-reset
FETCH=0
EXE=0

# help if we have no option and no use-flag
if [[ $# -eq 0 ]]
then
   echo ""
   echo "Usage: `basename $0` [OPTIONS] USE-FLAG"
   echo ""
   echo "Valid options are:"
   echo "-f    fetch all files only"
   echo "-x    execute normal (alternating fetch and build)"
   echo "-fx   fetch all files, then build all"
   echo ""
   exit 1
fi

# grab the options
while getopts ":fx" option
do
   case $option in
       f     ) FETCH=1;;
       x     ) EXE=1;;
       *     ) echo "!!! Error: $1 is an invalid option."; exit 1;;
   esac
done
shift $(($OPTIND - 1))

if [[ -z "$1" ]]
then
   echo "!!! Error: You did not enter a USE-flag."
   rm -rf /tmp/sure002/
   exit 1
fi

# grep the USE
grep -l -w -e "$1" /var/db/pkg/*/*/IUSE > /tmp/sure002/allt.sur

# break if file is zero length
if [[ ! -s "/tmp/sure002/allt.sur" ]]
then
   echo "No match could be found for your USE-flag: $1"
   rm -rf /tmp/sure002/
   exit 1
fi

# sed to base path in portage
# are there any ebuild-versions which don't start with [0-9]???
sed -e s/.*pkg/\\/usr\\/portage/ -e s/-[0-9].*/\\// /tmp/sure002/allt.sur > /tmp/sure002/bpatht1.sur

# sed to digest
sed -e s/.*pkg\\/[a-z0-9]*-[a-z0-9]*\\//files\\/digest-/ -e s/\\/IUSE// /tmp/sure002/allt.sur  > /tmp/sure002/dgestt1.sur

# sed to ebuild
sed -e s/.*pkg\\/[a-z0-9]*-[a-z0-9]*\\/// -e s/\\/IUSE/.ebuild/ /tmp/sure002/allt.sur > /tmp/sure002/ebuildt1.sur

# sed to catecory/program format
sed -e s/.*pkg\\/// -e s/-[0-9].*// /tmp/sure002/allt.sur > /tmp/sure002/emerge.sur

# sed to version
# long line needed to handle 'foo-(number)bar-version' packages
# FIX ME! rarely cases are not correctly displayed
# but does not conflict with emerge, since this is only for displaying
sed -e s/.*pkg\\/[a-z0-9]*-[a-z0-9]*\\/.*[a-z]-/"Version installed: "/ -e s/\\/IUSE// /tmp/sure002/allt.sur > /tmp/sure002/versiont0.sur

# cat-count the lines
cat -n /tmp/sure002/bpatht1.sur > /tmp/sure002/bpatht0.sur
cat -n /tmp/sure002/dgestt1.sur > /tmp/sure002/dgestt0.sur
cat -n /tmp/sure002/ebuildt1.sur > /tmp/sure002/ebuildt0.sur

# join numbered lines to build full paths to digest- and ebuild-files
join /tmp/sure002/bpatht0.sur /tmp/sure002/dgestt0.sur | sed -e s/[0-9]*\ // -e s/\ // > /tmp/sure002/digest.sur
join /tmp/sure002/bpatht0.sur /tmp/sure002/ebuildt0.sur | sed -e s/[0-9]*\ // -e s/\ // > /tmp/sure002/ebuild.sur

# cat|grep|sed the description of digest-files
rm -f /tmp/sure002/dscribt0.sur &> /dev/null
cat /tmp/sure002/ebuild.sur |
while read line
do
   grep -e DESCRIPTION $line | sed -e s/[A-Z]*=/Description":"\ / >> /tmp/sure002/dscribt0.sur
done

# cat|sed the size
rm -f /tmp/sure002/sizet0.sur &> /dev/null
cat /tmp/sure002/digest.sur |
while read line
do
   sed -e s/.*\ /Size":"\ / $line >> /tmp/sure002/sizet0.sur
done

# cat-count the lines for final output
cat -n /tmp/sure002/versiont0.sur > /tmp/sure002/version.sur
cat -n /tmp/sure002/emerge.sur > /tmp/sure002/catpro.sur
cat -n /tmp/sure002/dscribt0.sur > /tmp/sure002/describe.sur
cat -n /tmp/sure002/sizet0.sur > /tmp/sure002/size.sur

# joining final output
join /tmp/sure002/catpro.sur /tmp/sure002/describe.sur > /tmp/sure002/outputt1.sur
join /tmp/sure002/outputt1.sur /tmp/sure002/version.sur > /tmp/sure002/outputt0.sur
join /tmp/sure002/outputt0.sur /tmp/sure002/size.sur > /tmp/sure002/output.sur

# sed final output and show
sed -e s/[0-9]*\ /\\n/ -e s/\ /\\n/ -e s/\ "Version"/\\n"Version"/ -e s/\ "Size"/\\n"Size"/ /tmp/sure002/output.sur
echo""

# fetch, emerge, both or nothing?
if [[ $FETCH -eq 1 ]]
then
   cat /tmp/sure002/emerge.sur | xargs emerge -pv
   cat /tmp/sure002/emerge.sur | xargs emerge -f
fi

if [[ $EXE -eq 1 ]]
then
   cat /tmp/sure002/emerge.sur | xargs emerge -pv
   cat /tmp/sure002/emerge.sur | xargs emerge --oneshot
fi


# even more paranoid cleaning
rm -rf /tmp/sure002/ &> /dev/null

exit 0
Back to top
View user's profile Send private message
BarryJ
n00b
n00b


Joined: 13 Apr 2003
Posts: 72
Location: Wisconsin, USA

PostPosted: Mon Dec 15, 2003 10:59 pm    Post subject: Reply with quote

Cool script! It works for me and helped me with the very problem I was having. Thanks man!
Back to top
View user's profile Send private message
ares
Apprentice
Apprentice


Joined: 13 Oct 2003
Posts: 280
Location: Savigliano (CN)

PostPosted: Fri Dec 26, 2003 12:03 am    Post subject: Reply with quote

Very Good... :D
_________________
My portage and homepage
Back to top
View user's profile Send private message
Krigare
Tux's lil' helper
Tux's lil' helper


Joined: 12 Nov 2003
Posts: 92
Location: ::1

PostPosted: Sat Dec 27, 2003 5:25 am    Post subject: Reply with quote

good work
_________________
Together we are strong.
Back to top
View user's profile Send private message
MighMoS
Guru
Guru


Joined: 24 Apr 2003
Posts: 416
Location: @ ~

PostPosted: Sat Dec 27, 2003 6:40 am    Post subject: Reply with quote

For me, it seems to mix up the descriptions. :?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
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