#!/bin/bash # # pkgfoster 2005-11-27 # Jukka Heino # # pkgfoster is a simple script you can use to clean up orphaned packages (i.e. # packages which no other package depends on). It uses prt-cache by default, so # remember to build the cache with "prt-get cache". You can also use normal # prt-get by modifying the PRT_GET variable. List of packages to keep # are stored in ~/.keepers. Packages from core are never considered for # deletion. # PRT_GET=prt-cache function PKGRM { if [ $UID -ne 0 ]; then SUDO="`which sudo 2>/dev/null`" if [ -z "$SUDO" ]; then su -c "pkgrm $1" else sudo pkgrm $1 fi else pkgrm $1 fi } BASE=$(ls $(awk '/^[[:space:]]*prtdir.*\/core/ {print $2}' /etc/prt-get.conf)) touch ~/.keepers echo "Checking packages for orphans..." while true ; do RECHECK=0 for PACKAGE in $($PRT_GET listinst) ; do if [ -z "$(grep ^$PACKAGE$ ~/.keepers)" ] && \ [ -z "$(echo "$BASE" | tr ' ' '\n' | grep ^$PACKAGE$)" ] && \ [ -z "$($PRT_GET dependent $PACKAGE)" ] ; then echo $PRT_GET info $PACKAGE echo echo -n "Uninstall $PACKAGE? (y/N) " read ANSWER if [ "$ANSWER" == "y" ] ; then PKGRM $PACKAGE RECHECK=1 else echo $PACKAGE >> ~/.keepers fi fi done if [ "$RECHECK" == "0" ] ; then exit 0 fi echo echo "Re-checking packages for new orphans..." done