From cac94f6008506fdb9b2b49e9dc9718995b4447bd Mon Sep 17 00:00:00 2001
From: Manuel Canales Esparcia <manuel@linuxfromscratch.org>
Date: Mon, 21 Aug 2006 21:09:16 +0000
Subject: [PATCH] Added installed version to packages database

---
 BLFS/libs/func_packages | 34 ++++++++++++++++++++++++++--------
 BLFS/update_book.sh     |  2 ++
 blfs                    |  4 ++--
 3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/BLFS/libs/func_packages b/BLFS/libs/func_packages
index 39db618..6cec2d5 100644
--- a/BLFS/libs/func_packages
+++ b/BLFS/libs/func_packages
@@ -37,6 +37,15 @@ get_pkg_ver() {         # Find package version for a given package ID
 
 }
 
+#-----------------------#
+get_installed_ver() {   # Find installed package version for a given package ID
+#-----------------------#
+  local pkg_id=$1
+
+  find $TRACKING_DIR -name "${pkg_id}-[[:digit:]]*" | sed "s/.*${pkg_id}-//"
+
+}
+
 #-----------------------#
 generate_packages()  {  # Master packages file
 #-----------------------#
@@ -49,7 +58,8 @@ generate_packages()  {  # Master packages file
   for file in `find $BLFS_XML -name "*.xml"` ; do
     pkg_id=$(grep "sect1 id" $file | sed -e 's/<sect1 id="//;s/".*//')
     pkg_ver=$(get_pkg_ver $pkg_id)
-    [[ ! -z "$pkg_id" ]] && echo -e "$pkg_id\t$file\t$pkg_ver" >> packages.tmp
+    installed_ver=$(get_installed_ver $pkg_id)
+    [[ ! -z "$pkg_id" ]] && echo -e "$pkg_id\t$file\t$pkg_ver\t$installed_ver" >> packages.tmp
   done
 
   # IDs clean-up (unuseful pages or commented-out packages, could be more)
@@ -65,19 +75,27 @@ generate_packages()  {  # Master packages file
   GNOME_VER=$(get_pkg_ver gnome)
   GNOME_MINOR_VER=$(get_pkg_ver gnome-minor)
   KDE_VER=$(get_pkg_ver kde)
+  KDE_INST_VER=$(get_installed_ver kde)
   KDE_KOFFICE_VER=$(get_pkg_ver koffice)
   XORG7_VER=$(get_pkg_ver xorg7)
 
+  # Meta-packages installed version
+  ALSA_INST_VER=$(get_installed_ver alsa)
+  GNOME_INST_VER=$(get_installed_ver gnome)
+  KDE_INST_VER=$(get_installed_ver kde)
+  KDE_KOFFICE_INST_VER=$(get_installed_ver koffice)
+  XORG7_INST_VER=$(get_installed_ver xorg7)
+
   # Add header with meta-packages pseudo Id
 {
   cat << EOF
-alsa	$BLFS_XML	$ALSA_VER
-gnome-core	$BLFS_XML	$GNOME_VER$GNOME_MINOR_VER
-gnome-full	$BLFS_XML	$GNOME_VER$GNOME_MINOR_VER
-kde-core	$BLFS_XML	$KDE_VER
-kde-full	$BLFS_XML	$KDE_VER
-kde-koffice	$BLFS_XML	$KDE_KOFFICE_VER
-xorg7	$BLFS_XML	$XORG7_VER
+alsa	$BLFS_XML	$ALSA_VER	$ALSA_INST_VER
+gnome-core	$BLFS_XML	$GNOME_VER$GNOME_MINOR_VER	$GNOME_INST_VER
+gnome-full	$BLFS_XML	$GNOME_VER$GNOME_MINOR_VER	$GNOME_INST_VER
+kde-core	$BLFS_XML	$KDE_VER	$KDE_INST_VER
+kde-full	$BLFS_XML	$KDE_VER	$KDE_INST_VER
+kde-koffice	$BLFS_XML	$KDE_KOFFICE_VER	$KDE_KOFFICE_INST
+xorg7	$BLFS_XML	$XORG7_VER	$XORG7_INST_VER
 EOF
 } >> packages.tmp
 
diff --git a/BLFS/update_book.sh b/BLFS/update_book.sh
index 2812cb4..0a4a5ea 100755
--- a/BLFS/update_book.sh
+++ b/BLFS/update_book.sh
@@ -14,6 +14,8 @@ TREE=$3      # SVN tree for the BLFS book version
 [[ -z $DOC_MODE ]] && DOC_MODE=update
 [[ -z $TREE ]] && TREE=trunk/BOOK
 
+TRACKING_DIR=tracking-dir
+
 #---------------------
 # packages module
 source libs/func_packages
diff --git a/blfs b/blfs
index cb5030b..0ecfa11 100755
--- a/blfs
+++ b/blfs
@@ -124,9 +124,9 @@ rm -rf menu/.svn
 rm -rf menu/lxdialog/.svn
 
 
-# Set some harcoded values to the proper values
+# Set some harcoded envars to their proper values
 sed -i 's,blfs-xml,'$BLFS_XML',' update_book.sh libs/book.xsl
-sed -i 's,tracking-dir,'$TRACKING_DIR',' gen_config.sh
+sed -i 's,tracking-dir,'$TRACKING_DIR',' update_book.sh gen_config.sh
 
 # Fetch book sources and create packages and GNOME/KDE dependencies files
 if [[ -d $BLFS_XML ]] ; then