Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Script] Mass Unmerge
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Phenax
l33t
l33t


Joined: 10 Mar 2006
Posts: 972

PostPosted: Wed Aug 02, 2006 3:01 am    Post subject: [Script] Mass Unmerge Reply with quote

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
View user's profile Send private message
count_zero
Guru
Guru


Joined: 17 May 2004
Posts: 458
Location: Little Rock, Arkansas, USA

PostPosted: Wed Aug 02, 2006 4:06 am    Post subject: Reply with quote

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
View user's profile Send private message
Phenax
l33t
l33t


Joined: 10 Mar 2006
Posts: 972

PostPosted: Wed Aug 02, 2006 4:09 am    Post subject: Reply with quote

Wow, thanks a lot for the revision, I hope you don't mind that I append it to the first post.
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Wed Aug 02, 2006 5:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2070

PostPosted: Fri Aug 04, 2006 10:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3181

PostPosted: Sat Aug 05, 2006 2:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
count_zero
Guru
Guru


Joined: 17 May 2004
Posts: 458
Location: Little Rock, Arkansas, USA

PostPosted: Sat Aug 05, 2006 6:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
count_zero
Guru
Guru


Joined: 17 May 2004
Posts: 458
Location: Little Rock, Arkansas, USA

PostPosted: Sun Aug 06, 2006 4:53 am    Post subject: Reply with quote

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. :D
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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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