summaryrefslogtreecommitdiff
path: root/pkgfoster
blob: 4552b39ee5deeff4fddc1a6d52eebf986786e7e1 (plain)
    1 #!/bin/bash
    2 #
    3 # pkgfoster 2005-11-27
    4 # Jukka Heino <jukka@karsikkopuu.net>
    5 #
    6 # pkgfoster is a simple script you can use to clean up orphaned packages (i.e. 
    7 # packages which no other package depends on). It uses prt-cache by default, so 
    8 # remember to build the cache with "prt-get cache". You can also use normal 
    9 # prt-get by modifying the PRT_GET variable. List of packages to keep 
   10 # are stored in ~/.keepers. Packages from core are never considered for 
   11 # deletion.
   12 #
   13 
   14 PRT_GET=prt-cache
   15 
   16 function PKGRM
   17 {
   18 	if [ $UID -ne 0 ]; then
   19 		SUDO="`which sudo 2>/dev/null`"
   20 		if [ -z "$SUDO" ]; then
   21 			su -c "pkgrm $1"
   22 		else
   23 			sudo pkgrm $1
   24 		fi
   25 	else
   26 		pkgrm $1
   27 	fi
   28 }
   29 
   30 BASE=$(ls $(awk '/^[[:space:]]*prtdir.*\/core/ {print $2}' /etc/prt-get.conf))
   31 touch ~/.keepers
   32 
   33 echo "Checking packages for orphans..."
   34 
   35 while true ; do
   36 
   37 	RECHECK=0
   38 
   39 	for PACKAGE in $($PRT_GET listinst) ; do
   40 
   41 		if [ -z "$(grep ^$PACKAGE$ ~/.keepers)"                   ] && \
   42 	           [ -z "$(echo "$BASE" | tr ' ' '\n' | grep ^$PACKAGE$)" ] && \
   43 	           [ -z "$($PRT_GET dependent $PACKAGE)"                  ] ; then
   44 
   45 			echo
   46 			$PRT_GET info $PACKAGE
   47 			echo
   48 
   49 			echo -n "Uninstall $PACKAGE? (y/N) "
   50 			read ANSWER
   51 
   52 			if [ "$ANSWER" == "y" ] ; then
   53 				PKGRM $PACKAGE
   54 				RECHECK=1
   55 			else
   56 				echo $PACKAGE >> ~/.keepers
   57 			fi
   58 
   59 		fi
   60 
   61 	done
   62 
   63 	if [ "$RECHECK" == "0" ] ; then
   64 		exit 0
   65 	fi
   66 
   67 	echo
   68 	echo "Re-checking packages for new orphans..."
   69 
   70 done

Generated by cgit