Search:  
Gentoo Wiki

TIP_USE_helper_scripts


Please format this article according to the guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article


Script to display inline descriptions of USE flags from emerge -uv output

When updating a gentoo system, knowing what is each USE flag for is important. USE flags affect how each package is built, whether it includes support for optional features, and so on.

For that reason, it's recommended to pay attention to each flag. It'd probably make you constantly grepping /usr/portage/profiles/use.* to know what is the meaning of each flag.

You can use the following script to parse emerge -uv output and display the description of each affected flag, so that you can setup your /etc/portage/package.use/ file accordingly.

 #!/bin/sh -f
 # Copyright 2007 Jose San Leandro Armendariz
 # Distributed under the terms of the GNU General Public License
 
 # functions
 usage () {
   cat << USAGE

 emerge [..] | $0

 Displays the emerge output describing each USE flag.

 USAGE
   exit 1;
 }

 while read line;
 do
   if [ "x${line}" != "x" ]; then
     valid=`echo ${line} | grep " USE="`
     if [ "x${valid}" != "x" ]; then
       pkg=`echo ${line} | tr -s " " "\n" | egrep -v "^$" | grep "/"`
       allUses=`echo ${line} | awk -F"\"" '{print $2;}' | tr " " "\n" | grep -v "(" | grep -v "%"`
       echo ${pkg} USE=\"${allUses}\"
       if [ "x${allUses}" != "x" ]; then
         for use in ${allUses}; do
           use=`echo ${use} | tr -d "-"`
           for file in "/usr/portage/profiles/use.desc" "/usr/portage/profiles/use.local.desc"; do
               descriptions=`egrep "^${use} -" ${file} | egrep "^${pkg} -" | grep -v ":"`
               if [ "x${descriptions}" == "x" ]; then
                   descriptions=`egrep "^${use} -" ${file} | head -n 1`
               fi
               if [ "x${descriptions}" != "x" ]; then
                   break;
               fi
           done
           if [ "x${descriptions}" != "x" ]; then
             echo "${descriptions}" | sed "s|${pkg}||g" | sed "s_ -_:_" | \
             awk -F"-" '{printf("  %s\n", $0);}'
           fi
         done
       fi
     fi
   fi
 done

For example,

>emerge -upv | ./emerge-use-summary.sh
sys-apps/portage-2.1.2.7 USE="-build -doc -epydoc"
  build: !!internal use only!! DO NOT SET THIS FLAG YOURSELF!, used for creating build images and the first half of bootstrapping [make stage1]
  doc: Adds extra documentation (API, Javadoc, etc)
sys-apps/debianutils-2.17.5 USE="-static"
  static: !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically
sys-apps/man-1.6e-r3 USE="nls"
  nls: Adds Native Language Support (using gettext - GNU locale utilities)
sys-fs/e2fsprogs-1.39-r2 USE="nls -static"
  nls: Adds Native Language Support (using gettext - GNU locale utilities)
  static: !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically
app-editors/vim-core-7.0.235 USE="bash-completion nls -acl -livecd"
  nls: Adds Native Language Support (using gettext - GNU locale utilities)
  acl: Adds support for Access Control Lists
  livecd: !!internal use only!! DO NOT SET THIS FLAG YOURSELF!, used during livecd building.

Script to display inline descriptions of USE flags from emerge -uv output

Updating your Gentoo box would possibly introduce new USE flags on packages you already installed (and whose previous USE flags were already defined in its /etc/portage/package.use/ file).

If you like to maintain such USE flags sorted alphabetically, you can use the following script to do it automatically.

#!/bin/sh -f
# Copyright 2007 Jose San Leandro Armendariz
# Distributed under the terms of the GNU General Public License

# functions
usage () {
  cat << USAGE

$0 file

Reorders the USE flags defined in given file (i.e. /etc/portage/package.use/[file])

Parameters:
    file - the /etc/portage/package.use file to process.
USAGE
  exit 1;
}

checkInput() {

  if [ "x${file}" == "x" ]; then
    file=$@;
  fi;
  [ "x${file}" == "x" ] && usage
  if [ ! -f ${file} ]; then
    echo "${file} does not exist or cannot be read."
    exit 1
  fi
  package=`awk -F" " '{printf("%s", $1);}' ${file}`
  if [ "x${package}" == "x" ]; then
    echo "category/package not found in ${file}. Check syntax."
    exit 1
  fi
}

checkInput $@

cat ${file} | tr " " "\n" | grep -v ${package} | sort | \
awk -v pkg="${package}" 'BEGIN{printf("%s", pkg);}{printf(" %s", $0);}END{printf("\n");}'

For example,

>./sort-use.sh /etc/portage/package.use/mplayer
media-video/mplayer 3dnow 3dnowext X aac aalib alsa amr arts bl cdparanoia cpudetection dga directfb doc dts dv dvb dvd dvdnav dvdread enca encode esd fbcon gif gtk iconv ipv6 jpeg libcaca live lzo mad md5sum mmx mmxext openal opengl oss png radio real rtc samba sdl srt sse sse2 svga tga theora truetype unicode v4l v4l2 vorbis win32codecs x264 xanim xv xvid xvmc
Retrieved from "http://www.gentoo-wiki.info/TIP_USE_helper_scripts"

Last modified: Wed, 26 Dec 2007 15:28:00 +0000 Hits: 3,691