View previous topic :: View next topic |
Author |
Message |
Phenax l33t
Joined: 10 Mar 2006 Posts: 972
|
Posted: Wed Aug 02, 2006 3:01 am Post subject: [Script] Mass Unmerge |
|
|
Out of date, and needs work.
Last edited by Phenax on Mon Dec 18, 2006 9:42 pm; edited 6 times in total |
|
Back to top |
|
|
count_zero Guru
Joined: 17 May 2004 Posts: 460 Location: Little Rock, Arkansas, USA
|
Posted: Wed Aug 02, 2006 4:06 am Post subject: |
|
|
Great job! Your script is very useful.
However, it doesn't catch every package installed on a system--only those entered in the world file. Try this little modification to catch every installed package:
(I also changed it so that the keyword can be entered as an argument when calling the script)
Code: | #!/bin/bash
keyword=$1
if [[ $1 = "" ]]
then echo "Please input the keyword to be mass unmerged:"
read keyword
else :
fi
if [[ $keyword = "" ]]; then
echo "You need to enter a keyword next time"
exit
fi
ls -R /var/db/pkg/ | grep $keyword | sed 's/\/var\/db\/pkg\///g' | sed 's/://g' | sed 's/-r[0-9]$//g' | sed 's/\.//g' | sed 's/-[0-9]*$//g' | grep \/ | xargs emerge -pC
echo "These are the packages that I will unmerge. Are you sure you want
to go through with this? [y/n]:"
read var
if [ $var = "y" ]; then
ls -R /var/db/pkg/ | grep $keyword | sed 's/\/var\/db\/pkg\///g' | sed 's/://g' | sed 's/-r[0-9]$//g' | sed 's/\.//g' | sed 's/-[0-9]*$//g' | grep \/ | xargs emerge -C
else
echo "Sorry to hear that, maybe you should revise your keyword"
exit
fi
|
_________________ "We must all hang together, or assuredly we shall all hang separately."
-Ben Franklin |
|
Back to top |
|
|
Phenax l33t
Joined: 10 Mar 2006 Posts: 972
|
Posted: Wed Aug 02, 2006 4:09 am Post subject: |
|
|
Wow, thanks a lot for the revision, I hope you don't mind that I append it to the first post. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Wed Aug 02, 2006 5:43 pm Post subject: |
|
|
tip, you can use an other character than '/' in your sed expression:
eg:
Code: | sed 's/\/var\/db\/pkg\///g' |
to
Code: | sed 's:/var/db/pkg/::g' |
|
|
Back to top |
|
|
avx Advocate
Joined: 21 Jun 2004 Posts: 2152
|
Posted: Fri Aug 04, 2006 10:29 pm Post subject: |
|
|
I don't know, if Bash is capable of using arrays, but if so, you could move the output of
Code: | ls -R /var/db/pkg/ | grep $keyword | sed 's/\/var\/db\/pkg\///g' | sed 's/://g' | sed 's/-r[0-9]$//g' | sed 's/\.//g' | sed 's/-[0-9]*$//g' | grep \/ |
into an array an iterate over that which makes it easy to implement a function from which allows you to select single packets you want to keep.
Anyway, nice idea, actually I'm using something similar(implemented in ruby) with 'quickpkg' to make packages for backups.
cheers,
ph |
|
Back to top |
|
|
ppurka Advocate
Joined: 26 Dec 2004 Posts: 3256
|
Posted: Sat Aug 05, 2006 2:42 pm Post subject: |
|
|
ph030 wrote: | I don't know, if Bash is capable of using arrays, but if so, you could move the output of
Code: | ls -R /var/db/pkg/ | grep $keyword | sed 's/\/var\/db\/pkg\///g' | sed 's/://g' | sed 's/-r[0-9]$//g' | sed 's/\.//g' | sed 's/-[0-9]*$//g' | grep \/ |
into an array an iterate over that which makes it easy to implement a function from which allows you to select single packets you want to keep. | This can be done I think. Just put it in a for loop or pipe it to a while loop: Code: | for package in `ls -R /var/db... <blah blah>`; do <something something>; done |
@Phenax Thats a wonderful idea! Thanks. |
|
Back to top |
|
|
count_zero Guru
Joined: 17 May 2004 Posts: 460 Location: Little Rock, Arkansas, USA
|
Posted: Sat Aug 05, 2006 6:23 pm Post subject: |
|
|
ph030 wrote: |
into an array an iterate over that which makes it easy to implement a function from which allows you to select single packets you want to keep.
|
In another script I wrote, "addkeywords" (https://forums.gentoo.org/viewtopic-t-464213-highlight-.html) which allows you to choose a package to add to the package.keywords file, had an option where it gave a list of packages that were numbered, and you could choose which package you meant. You could probably do something very similar, just ask for each package number you want unmerged separated by a comma. It would probably take only a little tweaking to get it right. _________________ "We must all hang together, or assuredly we shall all hang separately."
-Ben Franklin |
|
Back to top |
|
|
count_zero Guru
Joined: 17 May 2004 Posts: 460 Location: Little Rock, Arkansas, USA
|
Posted: Sun Aug 06, 2006 4:53 am Post subject: |
|
|
Okay, I worked on it a little, and came up with this:
Code: | #!/bin/bash
mkdir -p /tmp/massunmerge
packages=/tmp/massunmerge/packages
keyword=$1
list=/tmp/massunmerge/list
list2=/tmp/massunmerge/list2
rm -f $packages $list $list2
if [[ $1 = "" ]]
then echo "Please input the keyword to be mass unmerged:"
read keyword
else :
fi
if [[ $keyword = "" ]]
then
echo "You need to enter a keyword next time"
exit
else :
fi
ls -R /var/db/pkg/ | grep $keyword | sed 's/\/var\/db\/pkg\///g' | sed 's/://g' | sed 's/-r[0-9]$//g' | sed 's/\.//g' | sed 's/-[0-9]*$//g' | grep \/ | xargs emerge -pC | sed '/^>/d' > $packages
list=$packages
input=1
until [[ -z $input ]]
do
cat $list | sed '/./,/^$/!d' | sed 's/[0-9]*)\ //' > $list
number=1
cat $list | while read each
do
if [ -z `echo $each | grep /` ]
then echo $each >> $list2
else echo $each | sed "s/.*/$number) &/" >> $list2
number=$(( number + 1 ))
fi
done
cat $list2
echo -n "Enter the numbers of the packages, separated by a comma,
that you want to remove from this list. Else, hit enter to continue: "
read input
input=`echo $input | sed 's/\,/ /g' | sed 's/\ \ / /g' | sed 's/^\ //'`
for each in `echo $input`
do
cat $list2 | sed "/^$each)/,/^$/ s/.*//" > $list
cat $list > $list2
done
rm -rf $list2
done
cat $list | grep / > $packages
echo -n "These are the packages that I will unmerge. Are you sure you want
to go through with this? [y/n]: "
read var
if [ $var = "y" ]
then
cat $packages | xargs emerge -C
else
echo "Sorry to hear that, maybe you should revise your keyword"
exit
fi
echo Done! |
It provides a numbered list of the packages to be unmerged, and allows you to choose packages to remove from the list. It makes the code a lot more complicated, however. I have to admit that I'm not the most elegant of coders, but then I have no formal training.
You can also download the script here: http://countzero.amidal.com/files/ _________________ "We must all hang together, or assuredly we shall all hang separately."
-Ben Franklin |
|
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
|
|