[PC-BSD Commits] r7436 - pcbsd/current/pc-metapkgmanager
svn at pcbsd.org
svn at pcbsd.org
Wed Aug 25 09:22:10 PDT 2010
Author: kris
Date: 2010-08-25 09:22:10 -0700 (Wed, 25 Aug 2010)
New Revision: 7436
Modified:
pcbsd/current/pc-metapkgmanager/pc-metapkgmanager.sh
Log:
Added functionality to add / status commands for pc-metapkgmanager
Modified: pcbsd/current/pc-metapkgmanager/pc-metapkgmanager.sh
===================================================================
--- pcbsd/current/pc-metapkgmanager/pc-metapkgmanager.sh 2010-08-25 12:41:02 UTC (rev 7435)
+++ pcbsd/current/pc-metapkgmanager/pc-metapkgmanager.sh 2010-08-25 16:22:10 UTC (rev 7436)
@@ -27,7 +27,6 @@
# Define some universals
MPDIR="/usr/local/share/pcbsd/base-ports"
-
display_usage() {
cat <<EOF
usage: `basename $0` [options]
@@ -45,7 +44,89 @@
exit 0
}
+add_metapkgs() {
+}
+
+# Delete specified meta-pkg, and packages which it installed that are not used elsewhere
+del_metapkgs() {
+ if [ -z "$1" ] ; then exit_err "No meta-pkg specified!" ; fi
+ if [ ! -e "${MPDIR}/${1}/pkg-list" ] ; then exit_err "No such meta-pkg: $1" ; fi
+ _dpkg=$1
+
+ # Build a list of installed meta-pkgs
+ for i in `find ${MPDIR}/* -type d`
+ do
+ if [ ! -e "${i}/pkg-list" ] ; then continue ; fi
+ if [ "${i}" = "${MPDIR}/$_dpkg" ] ; then continue ; fi
+ found=0
+ _iList=""
+ while read pkg
+ do
+ pkg_info $pkg >/dev/null 2>/dev/null
+ if [ "$?" != "0" ] ; then continue; fi
+ _iList="${_iList}${pkg}:"
+ done < ${i}/pkg-list
+ if [ "$found" = "0" ] ; then kPkgs="${kPkgs}${_iList}" ; fi
+ done
+
+ # kPkgs is our list of packages which are required by other installed meta-pkgs
+ export kPkgs
+
+ # Lets remove the pkgs from this meta-pkg
+ while read rmPkg
+ do
+ # Make sure this pkg is installed
+ pkg_info $rmPkg >/dev/null 2>/dev/null
+ if [ "$?" != "0" ] ; then continue ; fi
+
+ # confirm this package isn't required by any others
+ pkg_info -R ${rmPkg} | grep "Required by:" >/dev/null 2>/dev/null
+ if [ "$?" = "0" ] ; then continue; fi
+
+ # Check that this isnt an apart of another meta-pkg installed list
+ echo "$kPkgs" | grep "${rmPkg}:" >/dev/null 2>/dev/null
+ if [ "$?" = "0" ] ; then continue; fi
+
+ echo "Removing ${rmPkg}"
+ pkg_delete ${rmPkg} >/dev/null 2>/dev/null
+
+ done < ${MPDIR}/${_dpkg}/pkg-list
+
+ # Now check what packages we have and prune those whom aren't needed
+ while
+ z="1"
+ do
+ FOUND=""
+ for j in `pkg_info -I -a | cut -d ' ' -f 1`
+ do
+ echo "$kPkgs" | grep "${j}:" >/dev/null 2>/dev/null
+ if [ "$?" != "0" ] ; then
+ check_remove_port "${j}"
+ if [ "$?" = "0" ] ; then
+ FOUND="1"
+ break
+ fi
+ fi
+ done
+
+ # All done pruning ports
+ if [ -z "$FOUND" ] ; then break ; fi
+ done
+
+}
+
+# Check if the specified pkg doesn't have anything which requires it, and remove it if so
+check_remove_pkg() {
+ pkg_info -R "${1}" | grep "Required" >/dev/null 2>/dev/null
+ if [ "$?" != "0" ] ; then
+ echo "Removing unused pkg: ${1}"
+ pkg_delete ${1}
+ return 0
+ fi
+ return 1
+}
+
# Function to list available metapkgs
list_metapkgs() {
if [ ! -d "${MPDIR}" ] ; then exit_err "No available meta-pkg dir" ; fi
@@ -74,12 +155,46 @@
exit 1
}
+# Check on a meta-pkg, see if its installed, partially installed, or not.
+stat_metapkg() {
+ if [ -z "$1" ] ; then exit_err "No meta-pkg specified!" ; fi
+ if [ ! -e "${MPDIR}/${1}/pkg-list" ] ; then exit_err "No such meta-pkg: $1" ; fi
+ _mpkg=$1
+
+ found=1
+ nfound=0
+
+ # Now query pkg_info to confirm each pkg is installed
+ while read pkg
+ do
+ pkg_info $pkg >/dev/null 2>/dev/null
+ if [ "$?" != "0" ] ; then
+ nfound=1
+ else
+ found=0
+ fi
+
+ done < ${MPDIR}/${_mpkg}/pkg-list
+
+ if [ "$found" = "0" -a "$nfound" = "0" ] ; then
+ echo "The meta-pkg $_mpkg is installed"
+ fi
+ if [ "$found" = "0" -a "$nfound" = "1" ] ; then
+ echo "The meta-pkg $_mpkg is partially installed"
+ fi
+ if [ "$found" = "1" ] ; then
+ echo "The meta-pkg $_mpkg is not installed"
+ fi
+
+ exit 0
+}
+
# Figure out which mode we are running in
case ${1} in
list) list_metapkgs ;;
add) add_metapkgs "$2" ;;
del) del_metapkgs "$2" ;;
- status) stat_metapkgs "$2" ;;
+ status) stat_metapkg "$2" ;;
*) display_usage ;;
esac
More information about the Commits
mailing list