Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Cleaning world - umerge.sh
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
Zucca
l33t
l33t


Joined: 14 Jun 2007
Posts: 921
Location: KUUSANKOSKI, Finland

PostPosted: Mon Jan 05, 2009 2:27 pm    Post subject: Cleaning world - umerge.sh Reply with quote

Many times when I search for a certain kind of program I usually emerge many candidates. Finally when I have decided what program to use I forget to unmerge all the other programs that I installed for testing. I want to keep my system clean - only keeping the apps I really need. This is why I did a simple bash script that reads trough the world file and then gives you a list of packages to get rid of. It always uses --ask for emerge, so you can safely test it first.

Here's the source:
Code:
#!/bin/bash
# umerge.sh - unmerge packages easily
# v0.0.2b

UMERGELIST=`mktemp -t "unmerge_list_XXXXX"`

dialog --title 'Dialog unmerger' --single-quoted --checklist 'Select packages to unmerge' 0 0 0 `while read LINE; do echo -n "$LINE | off "; done < /var/lib/portage/world | sort` 2> "$UMERGELIST"
clear

sed -i "s/'//g" $UMERGELIST

emerge -vaC `cat $UMERGELIST`

rm $UMERGELIST


After you have unmerged packages, you can run 'emerge -va --depclean' to remove all the useless depencies that were needed by the packages you just unmerged.

At least this works on my PC. ;)
_________________
..: Zucca :..
This space is not for rent.


Last edited by Zucca on Sat May 16, 2009 10:36 am; edited 3 times in total
Back to top
View user's profile Send private message
spindle
Apprentice
Apprentice


Joined: 01 Dec 2003
Posts: 240

PostPosted: Mon Jan 05, 2009 3:57 pm    Post subject: Reply with quote

This should be handy, I usually do this by hand. Thanks Zucca.
Back to top
View user's profile Send private message
Zucca
l33t
l33t


Joined: 14 Jun 2007
Posts: 921
Location: KUUSANKOSKI, Finland

PostPosted: Mon Jan 05, 2009 4:29 pm    Post subject: Reply with quote

This can be useful also:
Code:
/path/to/unmerge.sh && emerge -va --depclean && revdep-rebuild -- -va
;)
Basically: remove packages of your choice --> remove the deps of those packages (if no other package uses them) --> check deps after --depclean
_________________
..: Zucca :..
This space is not for rent.
Back to top
View user's profile Send private message
Zucca
l33t
l33t


Joined: 14 Jun 2007
Posts: 921
Location: KUUSANKOSKI, Finland

PostPosted: Tue Jan 06, 2009 10:02 pm    Post subject: Reply with quote

I also made merge.sh for installing packages. ;)
_________________
..: Zucca :..
This space is not for rent.
Back to top
View user's profile Send private message
imake
n00b
n00b


Joined: 08 Jan 2009
Posts: 7

PostPosted: Tue Jan 13, 2009 5:21 pm    Post subject: Re: Cleaning world - umerge.sh Reply with quote

It's very useful,thanks a lot~
Back to top
View user's profile Send private message
Zucca
l33t
l33t


Joined: 14 Jun 2007
Posts: 921
Location: KUUSANKOSKI, Finland

PostPosted: Tue Jan 13, 2009 6:11 pm    Post subject: Reply with quote

Nice to see people finding this useful. :)
_________________
..: Zucca :..
This space is not for rent.
Back to top
View user's profile Send private message
Zucca
l33t
l33t


Joined: 14 Jun 2007
Posts: 921
Location: KUUSANKOSKI, Finland

PostPosted: Sat May 16, 2009 10:37 am    Post subject: Reply with quote

UPDATE: Just made it working with the new emerge command.
_________________
..: Zucca :..
This space is not for rent.
Back to top
View user's profile Send private message
Zucca
l33t
l33t


Joined: 14 Jun 2007
Posts: 921
Location: KUUSANKOSKI, Finland

PostPosted: Wed Dec 14, 2016 2:46 pm    Post subject: Reply with quote

Once again I had a need for this script.
I modified it to fit this decade and tested. Seems to work.
Any feedback is welcome.
I might develop a feature that let's user to read description and other information of a package... But for now it just removes packages user has selected.
Code:
#!/bin/bash
# umerge.sh - unmerge packages easily
# v0.1.0a

umlist="$(mktemp --suffix=".lst" "umerge_list_XXXXX")"

dialog --title 'Dialog unmerger' --single-quoted --no-items --checklist 'Select packages to unmerge' 0 0 0 --file <(awk '{sub(/:/,"-"); print $0 " off"}' /var/lib/portage/world | sort) 2> "$umlist" || exit 1
clear

sed -i "s/'//g" $umlist

emerge -vac $(cat $umlist)

rm "$umlist"
Back to top
View user's profile Send private message
saboya
Guru
Guru


Joined: 28 Nov 2006
Posts: 324
Location: Brazil

PostPosted: Thu Dec 15, 2016 2:29 am    Post subject: Reply with quote

Why don't you use emerge -1 and emerge --depclean later? Am I missing something?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 11312

PostPosted: Thu Dec 15, 2016 3:19 am    Post subject: Reply with quote

I would rewrite the script as follows (untested):
Code:
#!/bin/bash
# unchanged
umlist="$(mktemp --suffix=".lst" "umerge_list_XXXXX")"

# preserve exit code
dialog --title 'Dialog unmerger' --single-quoted --no-items --checklist 'Select packages to unmerge' 0 0 0 --file <(awk '{sub(/:/,"-"); print $0 " off"}' /var/lib/portage/world | sort) 2> "$umlist" || exit $?
clear

# Avoid UUOC; avoid in-place sed; unlink $umlist sooner
xargs -a <( sed -e "s/'//g" < "$umlist" ; rm "$umlist") emerge -vac
Back to top
View user's profile Send private message
Zucca
l33t
l33t


Joined: 14 Jun 2007
Posts: 921
Location: KUUSANKOSKI, Finland

PostPosted: Thu Dec 15, 2016 10:54 am    Post subject: Reply with quote

Thanks Hu.
I planned to use xrags, but I had earlier experience that interactive (--ask) programs can't take input when run from xargs. I could just remember incorrectly. But I'll try your version as I get back to my PC.

saboya wrote:
Why don't you use emerge -1 and emerge --depclean later? Am I missing something?
I'm not that perfect. ;)
Also with that method I'd forget to add packages I want to stay in the system to the world file. :P
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 11312

PostPosted: Fri Dec 16, 2016 2:46 am    Post subject: Reply with quote

When xargs gets the argument list from stdin, the child processes run with stdin redirected to /dev/null to prevent them trying to consume input meant for xargs. However, if xargs is run with --arg-file (short name -a), then child processes get access to stdin as normal because xargs reads from the named file, not from stdin.
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