Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
script to uninstall entire package tree (eg. Gnome or KDE)
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
agaffney
Retired Dev
Retired Dev


Joined: 28 May 2003
Posts: 104
Location: St. Charles, MO

PostPosted: Sun Jul 13, 2003 8:57 pm    Post subject: script to uninstall entire package tree (eg. Gnome or KDE) Reply with quote

I wrote this Perl script to aid in the uninstallation of multi-package programs such as Gnome or KDE. Please take a look at it, break it, flame it, fix it, whatever. Standard disclaimer applies: If it breaks something (even though it doesn't actually do anything right now), don't come to me.

Code:

#! /usr/bin/perl

my @pkgs1, @pkgs2, @world, @system, $line, $line2, $pkg;

open WORLD, "< /var/cache/edb/world";
foreach $line (<WORLD>) {
  chomp $line;
  push @world, $line;
}
close WORLD;

open SYSTEM, "emerge --nospinner -ep system |";
foreach $line (<SYSTEM>) {
  chomp $line;
  $line =~ /\[.+\] (.+\/.+)-\d.*\s*$/;
  $line2 = $1;
  if($line2 eq "") {
    next;
  }
  push @system, $line2;
}
close SYSTEM;

open QUERY, "emerge --nospinner -ep gnome |";
foreach $line (<QUERY>) {
  if($line !~ /^\[.+\]/) {
    next;
  }
  $line =~ s/^\[.+\] (.+)  /$1/;
  chomp $line;
  push (@pkgs1, $line);
}
close QUERY;

PKG:
foreach $pkg (@pkgs1) {
  open QUERY, "qpkg -q -nc $pkg |";
DEP:
  foreach $line (<QUERY>) {
    $line =~ s/\s+//;
    if(($line =~ /\*$/) || ($line =~ /DEPENDED/)) {
      next DEP;
    }
    chomp $line;
    foreach $line2 (reverse @pkgs1) {
      if($line eq $line2) {
        next DEP;
      }
      if($line2 eq $pkg) {
        next PKG;
      }
    }
    next PKG;
  }
  foreach $line (@world) {
    if($pkg =~ /$line/) {
      next PKG;
    }
  }
  foreach $line (@system) {
    if($pkg =~ /$line/) {
      next PKG;
    }
  }
  foreach my $tmp (@pkgs2) {
    if($tmp eq $pkg) {
      next PKG;
    }
  }
  push @pkgs2, $pkg;
  print "$pkg is safe to unmerge\n";
}
Back to top
View user's profile Send private message
erik_swanson
Retired Dev
Retired Dev


Joined: 02 Feb 2003
Posts: 123
Location: Corvallis, OR USA

PostPosted: Mon Jul 14, 2003 4:44 am    Post subject: Reply with quote

What about just emerge -C bigmetapackage, then emerge depclean?
Back to top
View user's profile Send private message
agaffney
Retired Dev
Retired Dev


Joined: 28 May 2003
Posts: 104
Location: St. Charles, MO

PostPosted: Mon Jul 14, 2003 7:01 am    Post subject: Reply with quote

Because 'emerge depclean' sometimes gives really weird results. This script restricts the search to just packages installed as dependencies of the main package. It then filters out anything in the world file or the system class and anything that has something outside the said package tree depending on it.
Back to top
View user's profile Send private message
Ni[o
Tux's lil' helper
Tux's lil' helper


Joined: 22 Jul 2003
Posts: 138
Location: Viroflay (78 - France)

PostPosted: Fri Sep 12, 2003 8:08 pm    Post subject: Reply with quote

Soory but I'm not a perl user and not really used to such scripts, so how do I use it to unmerge kde for example ?? :oops:
Back to top
View user's profile Send private message
blue.sca
l33t
l33t


Joined: 28 Aug 2003
Posts: 680
Location: Mainz, Germany

PostPosted: Sat Sep 13, 2003 8:23 pm    Post subject: Reply with quote

if it works (and i believe so ;)), really nice, thats the last feature i really missed to portage...

in my case, emerge --depclean give really weird results, because it wants even unemerge files out of world...
Back to top
View user's profile Send private message
agaffney
Retired Dev
Retired Dev


Joined: 28 May 2003
Posts: 104
Location: St. Charles, MO

PostPosted: Sun Sep 28, 2003 4:25 pm    Post subject: Reply with quote

Quote:
Soory but I'm not a perl user and not really used to such scripts, so how do I use it to unmerge kde for example ??

Change the line that says
Code:
open QUERY, "emerge --nospinner -ep gnome |";

to
Code:
open QUERY, "emerge --nospinner -ep kde |";
Back to top
View user's profile Send private message
dangerweasel
n00b
n00b


Joined: 15 Aug 2002
Posts: 47
Location: Outer Rim

PostPosted: Sun Sep 28, 2003 5:41 pm    Post subject: So... Reply with quote

This does not actually do the unmerging for me? I have to take the list of output packages and manually unmerge them? It is nice that it lists the packages I can unmerge, but can it unmerge them for me?
Back to top
View user's profile Send private message
agaffney
Retired Dev
Retired Dev


Joined: 28 May 2003
Posts: 104
Location: St. Charles, MO

PostPosted: Sun Sep 28, 2003 5:59 pm    Post subject: Reply with quote

I decided it would be safest if the script didn't automatically unmerge packages. There is a slight chance it could be wrong. It uses qpkg to check for dependencies, and there are known problems with qpkg.
Back to top
View user's profile Send private message
Lovechild
Advocate
Advocate


Joined: 17 May 2002
Posts: 2858
Location: Århus, Denmark

PostPosted: Sun Sep 28, 2003 9:23 pm    Post subject: Reply with quote

Wouldn't that script mark most of the base system like glibc, gcc and other vital packages as removable since you use -ep ?

Note I don't know perl, but should you have some sort of vital list that must never be removed..
Back to top
View user's profile Send private message
agaffney
Retired Dev
Retired Dev


Joined: 28 May 2003
Posts: 104
Location: St. Charles, MO

PostPosted: Sun Sep 28, 2003 9:55 pm    Post subject: Reply with quote

The scrips makes a list of all packages in /var/cache/edb/world and all packages returned by 'emerge -ep system'. It checks against these lists and runs 'qpkg -q -nc pkgname-ver' to see if anything depends on it besides other packages that were installed by Gnome.
Back to top
View user's profile Send private message
dangerweasel
n00b
n00b


Joined: 15 Aug 2002
Posts: 47
Location: Outer Rim

PostPosted: Mon Sep 29, 2003 7:05 pm    Post subject: Reply with quote

I discovered the same aofter pouring over the long list of ebuilds I could remove. I retract the question. :oops: I unmberged everything in gnome-base and gnome-extras using kportage and xterm. Thanks, though. Great script, BTW. Very helpful.
Back to top
View user's profile Send private message
agaffney
Retired Dev
Retired Dev


Joined: 28 May 2003
Posts: 104
Location: St. Charles, MO

PostPosted: Mon Sep 29, 2003 7:23 pm    Post subject: Reply with quote

I plan on writing another version that will optionally unmerge the packages for you and remove the associated files from /usr/portage/distfiles if you so choose. I think I will write my own dependency checking code instead of relying on qpkg.
Back to top
View user's profile Send private message
SyS_RaGE
n00b
n00b


Joined: 02 Jun 2003
Posts: 14

PostPosted: Fri Oct 10, 2003 1:27 pm    Post subject: Reply with quote

Well, the script is a great idea, and it helped a little. But it is in no way safe. It marked quite a few packages as safe to unmerge that weren't at all. I think I caught most of them.. or at least I hope I did. Just thought I'd post and warn people not to put too much trust in the list though. I would love it if somebody could figure out a way to do this in a manner that's a little more safe. Thanks anyway though. Still saved me time.
Back to top
View user's profile Send private message
Chewi
Developer
Developer


Joined: 01 Sep 2003
Posts: 875
Location: Edinburgh, Scotland

PostPosted: Sun Dec 07, 2003 12:59 am    Post subject: Reply with quote

Great idea but it didn't work for me! I do know a bit of Perl but not all that well so I'll leave you to figure this one out!

Code:
Nested quantifiers in regex; marked by <-- HERE in m/app-doc/doc++ <-- HERE / at ./unmerge-gnome line 56, <QUERY> line 138.
Back to top
View user's profile Send private message
vdboor
Guru
Guru


Joined: 03 Dec 2003
Posts: 592
Location: The Netherlands

PostPosted: Wed Dec 10, 2003 3:38 pm    Post subject: Reply with quote

locutusofborg wrote:
Quote:
Soory but I'm not a perl user and not really used to such scripts, so how do I use it to unmerge kde for example ??

Change the line that says
Code:
open QUERY, "emerge --nospinner -ep gnome |";

to
Code:
open QUERY, "emerge --nospinner -ep kde |";


since you're writing a script in Perl, why not using @ARGV to read the command line arguments?

I love this script, it's what I was looking for, but I'll play a little with it too when I have some time.
_________________
The best way to accelerate a windows server is by 9.81M/S²
Linux user #311670 and Yet Another Perl Programmer

[ screenies | Coding on KMess ]
Back to top
View user's profile Send private message
eeknay
Guru
Guru


Joined: 07 Jul 2003
Posts: 402
Location: EndOfTheRainbow

PostPosted: Wed Mar 31, 2004 10:36 am    Post subject: Reply with quote

hi, i'm not familiar with running scripts, how do i use this.

this is what i would do:
1.copy&paste the stuff into a new file like "deinstall"
2. do a "chmod a+x deinstall
3 ./deinstall

something else i have to do??

eeknay
_________________
Linda: "The holiday season is time of celebration for most but it is also the time to remember the tragic suffering of the less fortunate."
Morbo: "Earthlings do not yet know the meaning of suffering."
Back to top
View user's profile Send private message
vdboor
Guru
Guru


Joined: 03 Dec 2003
Posts: 592
Location: The Netherlands

PostPosted: Sun Apr 04, 2004 10:33 am    Post subject: Reply with quote

eeknay wrote:
hi, i'm not familiar with running scripts, how do i use this.

this is what i would do:
1.copy&paste the stuff into a new file like "deinstall"
2. do a "chmod a+x deinstall
3 ./deinstall

something else i have to do??

eeknay


Why wouldn't you try it? :P Your approach it is correct btw. ;)

chmod a+x is the step required to make a script executable for all users. When you run a script in unix/linux, the system looks at the first line to start the interpreter for the script (#! /usr/bin/perl )
_________________
The best way to accelerate a windows server is by 9.81M/S²
Linux user #311670 and Yet Another Perl Programmer

[ screenies | Coding on KMess ]
Back to top
View user's profile Send private message
teedog
Apprentice
Apprentice


Joined: 09 Mar 2004
Posts: 211

PostPosted: Sat May 22, 2004 5:52 am    Post subject: Reply with quote

Great script. Just what I was looking for. I wish these features were built into Portage though. The number of user-made scripts I need to use to keep my system sane is growing everyday.
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