]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
jail-upgrade: introducing function check_for_upgrade
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Tue, 14 Nov 2006 00:02:10 +0000 (00:02 +0000)
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Tue, 14 Nov 2006 00:02:10 +0000 (00:02 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@27 04377dda-e619-0410-9926-eae83683ac58

src/jail-upgrade

index c879bfabf1dccf8f5e96091fb49aed871c1e36bd..a5803d0a0619e157377edda5223d850f04c65bc2 100755 (executable)
@@ -24,18 +24,25 @@ function swaret_jail_upgrade {
 
   if [ ! -d "$PATCHES_DIR" ]; then
     for file in `find $PATCHES_DIR -name *tgz`; do
+
       pack=`package_name $file`
       for installed in `ls $1/var/log/packages/$pack* 2> /dev/null`; do
         if [[ $pack == `package_name $installed.tgz` ]]; then
           if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
+
             ROOT=$1 upgradepkg $file
-           UPGRADED="$UPGRADED $pack"
+                 upgraded $pack
+
           fi
         fi
       done
+
     done
   fi
 
+  # clear the upgraded package list
+  unset UPGRADED
+
 }
 
 function simplaret_jail_upgrade {
@@ -51,15 +58,19 @@ function simplaret_jail_upgrade {
 
   if [ -d "$PATCHES_DIR/$ARCH/$VERSION" ]; then
     for file in `find $PATCHES_DIR/$ARCH/$VERSION -name *tgz`; do
+
       pack=`package_name $file`
       for installed in `ls $1/var/log/packages/$pack* 2> /dev/null`; do
         if [[ "$pack" == "`package_name $installed.tgz`" ]]; then
           if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
+
             ROOT=$1 upgradepkg $file
-           UPGRADED="$UPGRADED $pack"
+                 upgraded $pack
+
           fi
         fi
       done
+
     done
   else
     echo error: cant upgrade for arch $ARCH and version $VERSION on $1: no such patch dir $PATCHES_DIR/$ARCH/$VERSION
@@ -69,12 +80,77 @@ function simplaret_jail_upgrade {
      [ "$CONSIDER_ALL_PACKAGES_AS_PATCHES" == "1" ]; then
      # TODO: search all packages in the repositories
      #       apply a patch if:
+     #       - the package is installed
      #       - it hasnt already applied
      #       - has a different version from the current installed
      #       - has a different build number from the current installed
+     if [ -d "$STORAGE/$ARCH/$VERSION" ]; then
+       for file in `find $STORAGE/$ARCH/$VERSION -name *tgz`; do
+
+          pack=`package_name $file`
+          for installed in `ls $1/var/log/packages/$pack* 2> /dev/null`; do
+            if [[ "$pack" == "`package_name $installed.tgz`" ]]; then
+              if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
+
+                # the package is installed
+                if ! echo $UPGRADED | grep -q $pack; then
+                  # the package isnt already applied
+                  if [ "`package_version $file`" != "`package_version $installed.tgz`" ] ||
+                     [ "`package_build $file`" != "`package_build $installed.tgz`" ]; then
+                    # the stored package has a different version or build number
+                    # from the installed one; then we upgrade it
+                    ROOT=$1 upgradepkg $file
+                    upgraded $pack
+                  fi
+                fi
+
+              fi
+            fi
+          done
+
+       done
+     fi
      true
   fi
 
+  # clear the upgraded package list
+  unset UPGRADED
+
+}
+
+function check_for_upgrade {
+
+  # check if package $1 is installed in the $2 root environment
+  # and should be upgraded
+  local pack found file
+
+  found="0"
+  file="$1"
+  pack="`package_name $file`"
+
+  if [ -d "$2/var/log/packages/" ] && [ ! -z "$file" ]; then
+    for installed in `ls $2/var/log/packages/$pack* 2> /dev/null`; do
+      if [[ "$pack" == "`package_name $installed.tgz`" ]]; then
+        if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
+          found="1"
+        fi
+      fi
+    done
+  fi
+
+  # if the package is installed, return true, otherwise false
+  if [ "$found" == "0" ]; then
+    return 1
+  elif [ "$found" == "1" ]; then
+    return 0
+  fi
+
+}
+
+function upgraded {
+
+  UPGRADED="$UPGRADED $1 "
+
 }
 
 if [ -f "$COMMON" ]; then