#!/bin/bash # count_zero 2006 # distributed under the GPLv2 # Bash Script to unmerge all packages that contain a given keyword 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!