

That still won't help me with software that's already installed.sumin k'adra wrote:in the next version of portage (2.0.50) you should be able to select which licenses you find acceptable in make.conf. Try searching the forums for the thread on it.
-sk
Where did you get this information ? 2.0.50 has many new features, but not that one.sumin k'adra wrote:in the next version of portage (2.0.50) you should be able to select which licenses you find acceptable in make.conf. Try searching the forums for the thread on it.
Code: Select all
#!/bin/bash
# Program to find licenses of installed packages
# Space separated list of acceptable licenses. See /usr/portage/licenses
oklicenses="GPL-1 GPL-2 as-is"
pkgdir=/var/db/pkg
filelist=`mktemp`
for i in `find $pkgdir -name LICENSE`; do
license=`cat "$i"`
echo -n "$license " >> $filelist
echo $i | cut -f5-6 -d/ >> $filelist
done
sort $filelist >> ${filelist}.sorted
for i in $oklicenses; do
grep $i ${filelist}.sorted >> ${filelist}.good
done
diff -u ${filelist}.sorted ${filelist}.good | grep -v '^--' | grep '^-' | cut -f2- -d/ >> ${filelist}.bad
# Remove the p at your own peril! Check it with the p first just in case you missed something
for i in `cat ${filelist}.bad`; do
emerge -pC =${i}
done
# Comment this line if you want to keep the lists (/tmp/tmpXXXX)
rm -f ${filelist}*
Code: Select all
oklicenses="GPL-1 GPL-2 as-is Apache-1.1 Artistic BSD BZIP2 DIVX EDB LGPL-2.1 FDL-1.1 FLEX FTL Info-ZIP MIT X11 MOTIF MPL-1.1 OPL OpenSoftware PSF-2.2 PYTHON Sudo W3C ZLIB fontconfig fmod freedist povlegal-3.5 public-domain wxWinLL-3"
Code: Select all
#!/bin/bash
# Program to find and remove packages with unwanted licenses
# Space separated list of acceptable licenses. See /usr/portage/licenses
oklicenses="GPL-1 GPL-2 as-is BSD"
pkgdir=/var/db/pkg
filelist=`mktemp`
emergeopts="-pC"
for i in `find $pkgdir -name LICENSE`; do
license=`cat "$i"`
echo -n "$license " >> $filelist
echo $i | cut -f5-6 -d/ >> $filelist
done
sort $filelist >> ${filelist}.sorted
for i in $oklicenses; do
grep $i ${filelist}.sorted >> ${filelist}.good
done
cat ${filelist}.good | sort -u >> ${filelist}.tmp && mv ${filelist}.{tmp,good}
diff -u ${filelist}.sorted ${filelist}.good | grep -v '^--' | grep '^-' | cut -c2- >> ${filelist}.bad
for i in `cat ${filelist}.bad | cut -f2- -d/` ; do
emergefiles=${emergefiles:-""}"=${i} "
done
read -n1 -p "Do you want to see the list of bad packages? (y/n) " reply
echo
if [[ $reply = 'y' ]]; then
less ${filelist}.bad
fi
echo "Pretend unmerge of packages:"
emerge $emergeopts $emergefiles
read -n1 -p "Continue with real unmerge? Saying yes will permanently remove packages (y/n) " reply2
if [[ $reply2 != 'y' ]]; then
echo && exit 0
fi
emergeopts="-C"
emerge $emergeopts $emergefiles
# Comment this line if you want to keep the lists (/tmp/tmpXXXX)
rm -f ${filelist}*
Code: Select all
#!/bin/bash
# Program to find and remove packages with unwanted licenses
# Space separated list of acceptable licenses. See /usr/portage/licenses
#OSI Compatible (+ as-is & public-domain)
#I couldn't find some of the OSI licenses in /usr/portage/licenses
#http://www.opensource.org/licenses/
oklicenses="as-is public-domain Academic Apache-1.1 Apple Artistic Artistic-2 BSD GPL-1 GPL-2 LGPL-2 LGPL-2.1 PLAN9 IBM MIT MPL-1.0 MPL-1.1 nethack OpenSoftware PHP PYTHON PSF-2.1.1 PSF-2.2 QPL QPL-1.0 Sleepycat SISSL-1.1 SPL ncsa-1.3 W3C wxWinLL-3 ZLIB"
#We should probably do OSI compatible + whatever Gentoo needs
#My system's
#Hopefully I'll narrow this down, since most of these licenses only cover one or two pacakges
#oklicenses="GPL-1 GPL-2 as-is Apache-1.1 Artistic BSD BZIP2 DIVX EDB LGPL-2.1 FDL-1.1 FLEX FTL Info-ZIP MIT X11 MOTIF MPL-1.1 OPL OpenSoftware PSF-2.2 PYTHON W3C ZLIB fontconfig fmod freedist povlegal-3.5 public-domain wxWinLL-3 CRACKLIB DB"
pkgdir=/var/db/pkg
filelist=`mktemp`
emergeopts="-C"
for i in `find $pkgdir -name LICENSE`; do
license=`cat "$i"`
echo -n "$license " >> $filelist
echo $i | cut -f5-6 -d/ >> $filelist
done
sort $filelist >> ${filelist}.sorted
for i in $oklicenses; do
grep $i ${filelist}.sorted >> ${filelist}.good
done
cat ${filelist}.good | sort -u >> ${filelist}.tmp && mv ${filelist}.{tmp,good}
diff -u ${filelist}.sorted ${filelist}.good | grep -v '^--' | grep '^-' | cut -c2- >> ${filelist}.bad
for i in `cat ${filelist}.bad | cut -f2- -d/` ; do
emergefiles=${emergefiles:-""}"=${i} "
done
badpackages=`wc -l ${filelist}.bad | cut -f1 -d\ `
if [ $badpackages = '0' ]; then
echo "No packages found outside of license parameters"; exit 2;
else
echo "Found ${badpackages} packages outside of license parameters";
fi
read -n1 -p "Do you want to see the list of bad packages? (y/n) " reply
echo
if [[ $reply = 'y' ]]; then
less ${filelist}.bad
fi
echo "Pretend unmerge of packages:"
emerge -p $emergeopts $emergefiles
read -n1 -p "Continue with real unmerge? Saying yes will permanently remove packages (y/n) " reply2
if [[ $reply2 != 'y' ]]; then
echo; exit 1
fi
emerge $emergeopts $emergefiles
cp ${filelist}.bad /var/log/unmerged.license
# Comment this line if you want to keep the lists (/tmp/tmpXXXX)
rm -f ${filelist}*
exit 0
Code: Select all
#!/bin/bash
# $Id: licenses2kill.sh,v 1.6 2004/01/30 19:57:06 tom Exp $
# Program to find and remove packages with unwanted licenses
# Copyright (c) Tom Knight (tomk@forums.gentoo.org)
# Harold Martin (cocoadev@earthlink.net)
# This program is distributed under the terms of GPL version 2.
# Space separated list of acceptable licenses. See /usr/portage/licenses
#OSI Compatible (+ as-is & public-domain)
#I couldn't find some of the OSI licenses in /usr/portage/licenses
#http://www.opensource.org/licenses/
oklicenses="as-is public-domain Academic Apache-1.1 Apple Artistic Artistic-2 BSD GPL-1 GPL-2 LGPL-2 LGPL-2.1 PLAN9 IBM MIT MPL-1.0 MPL-1.1 nethack OpenSoftware PHP PYTHON PSF-2.1.1 PSF-2.2 QPL QPL-1.0 Sleepycat SISSL-1.1 SPL ncsa-1.3 W3C wxWinLL-3 ZLIB"
#We should probably do OSI compatible + whatever Gentoo needs
#My system's
#Hopefully I'll narrow this down, since most of these licenses only cover one or two pacakges
#oklicenses="GPL-1 GPL-2 as-is Apache-1.1 Artistic BSD BZIP2 DIVX EDB LGPL-2.1 FDL-1.1 FLEX FTL Info-ZIP MIT X11 MOTIF MPL-1.1 OPL OpenSoftware PSF-2.2 PYTHON W3C ZLIB fontconfig fmod freedist povlegal-3.5 public-domain wxWinLL-3 CRACKLIB DB"
cleanup ()
{
rm -f ${filelist}*
}
pkgdir=/var/db/pkg
filelist=`mktemp`
emergeopts="-C"
logfile=/var/log/unmerged.license
echo "Searching licenses"
for i in `find $pkgdir -name LICENSE`; do
license=`cat "$i"`
echo -n "$license " >> $filelist
echo $i | cut -f5-6 -d/ >> $filelist
done
sort $filelist >> ${filelist}.sorted
for i in $oklicenses; do
grep $i ${filelist}.sorted >> ${filelist}.good
done
cat ${filelist}.good | sort -u >> ${filelist}.tmp && mv ${filelist}.{tmp,good}
diff -u ${filelist}.sorted ${filelist}.good | grep -v '^--' | grep '^-' | cut -c2- >> ${filelist}.bad
badpackages=`wc -l ${filelist}.bad | awk '{print $1}'`
if [[ $badpackages = '0' ]]; then
echo "No packages found outside of license parameters"; cleanup; exit 2;
else
echo "Found ${badpackages} packages outside of license parameters";
fi
read -n1 -p "Do you want to see the list of bad packages? (y/n) " reply
echo
if [[ $reply = 'y' ]]; then
while :; do
nl -s ") " ${filelist}.bad
read -p "Enter the number of a package you wish to keep, or d to continue " keep_package_no
if [[ ${keep_package_no} != 'd' ]]; then
if (( ${keep_package_no} > 0 )) && (( ${keep_package_no} <= ${badpackages} )); then
keep_package=`head -n ${keep_package_no} ${filelist}.bad | tail -n1 | cut -f2- -d/`
keep_license=`head -n ${keep_package_no} ${filelist}.bad | tail -n1 | cut -f1 -d\ `
echo "Keeping ${keep_package} package"
badleft=`wc -l ${filelist}.bad | awk '{print $1}'`
declare -i headn
declare -i tailn
headn=${keep_package_no}-1
tailn=${badleft}-${keep_package_no}
head -n ${headn} ${filelist}.bad > ${filelist}.tmp && \
tail -n ${tailn} ${filelist}.bad >> ${filelist}.tmp && \
mv ${filelist}.{tmp,bad}
# Maybe this should add the license to oklicenses for future use?
read -n1 -p "Keep all packages with ${keep_license} license? " keep_all
echo
if [[ $keep_all = 'y' ]]; then
echo "Keeping all ${keep_license} packages"
grep -v ^${keep_license} ${filelist}.bad > ${filelist}.tmp && \
mv ${filelist}.{tmp,bad}
fi
else
echo "Number out of range"
fi
else
break
fi
done
fi
for i in `cat ${filelist}.bad | cut -f2- -d/` ; do
emergefiles=${emergefiles:-""}"=${i} "
done
read -n1 -p "Continue with unmerge? Saying yes will permanently remove packages (y/n) " reply2
if [[ $reply2 != 'y' ]]; then
echo; cleanup; exit 1
fi
emerge $emergeopts $emergefiles
echo "Packages removed by licenses2kill" >> $logfile
echo `date +%c` >> $logfile
echo >> $logfile
cat ${filelist}.bad >> $logfile
echo >> $logfile
cleanup
exit 0

Code: Select all
# Blank for no logging, otherwise it will output to the file you specify
licenselog=""
packagelog=""Code: Select all
# separate the licenses from the packages that they associate with, and then save the variable for later use
badlicenses=`cat "${filelist}.bad" | cut -f1 -d\ | sort -u | tee ${filelist}.liccrop | wc -l`
echo "There are $badlicenses licenses outside of parameters"
read -n1 -p "Do you want to view the list of licenses that are being rejected? (y/n)" licrep
echo
if [[ $licrep = 'y' ]];
then
if [[ $licenselog != "" ]]
then
nl -s ") " ${filelist}.liccrop | tee $licenselog
else
nl -s ") " ${filelist}.liccrop
fi
fiCode: Select all
if [[ $packagelog != "" ]]
then
nl -s ") " ${filelist}.bad | tee $packagelog
else
nl -s ") " ${filelist}.bad
fiCode: Select all
# Check to see if the user is root or in the portage group before you try to unmerge things.
if [[ `/usr/bin/whoami` = 'root' || `groups | grep -c "portage"` -ge 1 ]]
then