# Cleaning world - umerge.sh

## Zucca

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:

```
#!/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. ;)

----------

## spindle

This should be handy, I usually do this by hand. Thanks Zucca.

----------

## Zucca

This can be useful also:

```
/path/to/unmerge.sh && emerge -va --depclean && revdep-rebuild -- -va
```

  :Wink: 

Basically: remove packages of your choice --> remove the deps of those packages (if no other package uses them) --> check deps after --depclean

----------

## Zucca

I also made merge.sh for installing packages.  :Wink: 

----------

## imake

It's very useful,thanks a lot~

----------

## Zucca

Nice to see people finding this useful. :)

----------

## Zucca

UPDATE: Just made it working with the new emerge command.

----------

## Zucca

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.

```
#!/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"
```

----------

## saboya

Why don't you use emerge -1 and emerge --depclean later? Am I missing something?

----------

## Hu

I would rewrite the script as follows (untested):

```
#!/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

```

----------

## Zucca

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

----------

## Hu

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.

----------

