#!/bin/bash # www.xeron.cc # Distributed under terms of the GPL v2 # # Well I knew I had to. My own portage query tool in bash. Way faster than # equery and qpkg, well, for the things I've implemented anyway. Ohh yes, pure # bash speed. This requires realpath, grep, find, and column. I think most # people will already have the latter three. Realpath is a small dep, and # somewhat useful anyway. # # Some color code and sed stuff taken from qpkg. Infact, comment out the below # variables if you don't want color. I don't feel like parsing for it. NO="\x1b[0;0m" BR="\x1b[0;01m" CY="\x1b[36;01m" YL="\x1b[33;01m" BL="\x1b[34;01m" BD="\x1b[1m" UL="\x1b[4m" testargs() { if [ -z "$*" ]; then echo -e "Not enough arguments!\n" $0 -h exit 1 fi } efile() { testargs "$@" for FULL_PATH in `realpath -s "$@"|sed "s:\[:\\\\\[:; s:*:\\\\\*:"`; do if [ -d "$FULL_PATH" ]; then grep "^dir $FULL_PATH$" /var/db/pkg/*/*/CONTENTS|sed "s:/var/db/pkg/::; s,/CONTENTS:,|," else grep "^... $FULL_PATH " /var/db/pkg/*/*/CONTENTS -o|sed "s:/var/db/pkg/::; s,/CONTENTS:,|,; s/\ $//" fi done | column -t -s\||sed "s,\(.*-.*/\)\(.*\)\(...\ /.*$\),${BD}\1${CY}\2${NO}\3,;" } econtent() { testargs "$@" for PACKAGE in `find /var/db/pkg/* -maxdepth 1 -mindepth 1 2>/dev/null|sed s:^/var/db/pkg/::|grep -- "$*"`; do echo -e "$PACKAGE *\n${BL}CONTENTS:${NO}"|sed "s:\(.*-.*/\)\(.*\):${BD}\1${CY}\2:;" cat /var/db/pkg/$PACKAGE/CONTENTS| \ sed "s:\(^obj \)\(.*\)\( .*\)\{2\}$:${BR}\2${NO}:; s:\(^sym \)\(.*\)\(\ ->\ \)\(.*\)\( .*\)$:${CY}\2${NO}\3\4:; s:\(^dir \)\(.*\)$:${YL}\2${NO}:" echo done } esearch() { testargs "$@" PACKAGES=`find /var/db/pkg/* -maxdepth 1 -mindepth 1 2>/dev/null|sed s:^/var/db/pkg/::|grep -- "$*"|sed "s:\(.*-.*/\)\(.*\):${BD}\1${CY}\2${NO}:"` if [ -z "$PACKAGES" ]; then echo "No packages found!" exit 1 else echo -e "$PACKAGES\nTotal packages: `echo "$PACKAGES" | wc -l`" fi } etc-clean() { # I don't think this can be indented without breaking something... WHITELIST="/etc/mtab /etc/csh.env /etc/dhcpc /etc/hosts /etc/yp.conf /etc/pango/pango.modules /etc/rsync/rsyncd.conf /etc/fstab /etc/shadow /etc/shadow- /etc/gshadow /etc/gshadow- /etc/group /etc/group- /etc/passwd /etc/passwd- /etc/portage /etc/portage/profile /etc/portage/sets /etc/ioctl.save /etc/conf.d/.keep /etc/modules.d/.keep /etc/modules.autoload.d/.keep /etc/profile.env /etc/.pwd.lock /etc/localtime /etc/ld.so.conf /etc/ld.so.cache /etc/resolv.conf /etc/modules.conf /etc/modprobe.conf /etc/make.profile /etc/opt/.keep /etc/opt /etc/make.conf /etc/modules.devfs /etc/devfs.d /etc/gtk-2.0 /etc/gtk-2.0/gtk.immodules /etc/gtk-2.0/gdk-pixbuf.loaders /etc/sgml /etc/samba/private /etc/xml /etc/env.d/.keep /etc/env.d/01hostname /etc/env.d/03opengl /etc/env.d/05binutils /etc/env.d/05gcc /etc/env.d/20java /etc/env.d/90games /etc/env.d/binutils/config-i686-pc-linux-gnu /etc/env.d/gcc/config `grep -rh "^... /etc" /var/db/pkg/*/*/CONTENTS| \ sed "s:\(^obj \)\(.*\)\( .*\)\{2\}$:\2:; s:\(^sym \)\(.*\)\(\ ->\ \)\(.*\)\( .*\)$:\2:; s:\(^dir \)\(.*\)$:\2:"| \ sort -u` " IFS=$'\n' for x in `find /etc \( -name gconf.xml.defaults -o -name runlevels \) -prune -o -print`; do for w in $WHITELIST; do if [ "$w" = "$x" ]; then exists=1 break else unset exists fi done if [ -z "$exists" ]; then echo "$x" fi done } help() { echo -e "Usage: `basename $0` [-f ${UL}FILE${NO}|-l ${UL}PACKAGE${NO}|-s ${UL}PACKAGE${NO}|-e|-h]" echo -e " -f check what package owns a file(s)" echo -e " -l list package contents. A \".\" will list all." echo -e " -s search installed packages and display count. A \".\" will list all." echo -e " -e list files in /etc that aren't in portage" echo -e " -h display this help and exit" exit 0 } case $1 in -f) shift; IFS=$'\n'; efile "$@";; -l) shift; IFS=$'\n'; econtent "$@";; -s) shift; IFS=$'\n'; esearch "$@";; -e) etc-clean;; -h|*) help ;; esac