update-function for lin and autocorrection of the checksums for the verify-plugins

Christian Riggenbach criggenbach at magahugu.net
Sat Jan 3 23:34:52 CET 2009


Hi everybody

A new try: After about a year, I submit my update-patches again. I hope,
this time more people have time to check them.

The patches ('module-update.plugin', 'lin.patch', and
'download-generic.plugin.patch') extend the lin-programm with an
update-funktion. This is made with an additional getopts-switch in the
lin-program itself, a BUILD_POST_INSTALL-plugin and by preserving the
timestamp of the dowloaded file for suggest the UPDATED-date.

With this patch, a user can update a module simply by:

# lin -uw VERSION MODULE

The patches 'verify-{md5,sha1}.plugin.patch' extend the
verifying-plugins so that they can correct the checksums themself, if
the module is in the zlocal-section.


my greetings and a happy new year

Christian Riggenbach


-------------- next part --------------
--- var/lib/lunar/plugins/download-generic.plugin	2007-03-18 22:05:01.000000000 +0100
+++ /var/lib/lunar/plugins/download-generic.plugin	2008-12-21 14:28:08.000000000 +0100
@@ -50,7 +50,7 @@
     WGET_OPTS+=" --no-check-certificate"
   fi
 
-  WGET_OPTS+=" --tries=${NUM_RETRY:-5}"
+  WGET_OPTS+=" --tries=${NUM_RETRY:-5} --preserve-permissions"
 
   [ -n "$http_proxy" ] && export http_proxy=$http_proxy
   [ -n  "$ftp_proxy" ] && export  ftp_proxy=$ftp_proxy
@@ -61,7 +61,7 @@
     # looks like it worked
     if testpack $TMP_FILE ; then
       if [ "$TMP_FILE" != "$3/$2" ]; then
-        install -m644 $TMP_FILE "$3/$2"
+        install -p -m644 $TMP_FILE "$3/$2"
         rm $TMP_FILE
       fi
       verbose_msg "download of \"$2\" successful"
-------------- next part --------------
--- sbin/lin	2008-04-02 00:05:01.000000000 +0200
+++ /sbin/lin	2008-04-27 22:02:19.000000000 +0200
@@ -53,6 +53,9 @@
 -v  |  --verbose                Increases the level of message output
 -w  |  --want version           Try to install a different version that is
                                 not in moonbase
+-u  |  --update                 Try to update a module with the version
+                                given by --want, so only use together
+                                with --want.
 EOF
   exit  1
 }
@@ -207,7 +210,7 @@
 
 . /etc/lunar/config
 
-GETOPT_ARGS=$(getopt -q -n lin -o "cdf:hprRsvV:w:" -l "compile,debug,deps,from:,help,opts:,probe,reconfigure,resurrect,silent,verbose,Version:,want:" -- "$@")
+GETOPT_ARGS=$(getopt -q -n lin -o "cdf:hprRsvV:w:u" -l "compile,debug,deps,from:,help,opts:,probe,reconfigure,resurrect,silent,verbose,Version:,want:,update" -- "$@")
 
 # the following trap makes sure all threads exit in case something weird
 # happens:
@@ -238,6 +241,7 @@
       -s|--silent      ) export SILENT="$1" ;                       shift   ;;
       -v|--verbose     ) export VERBOSE="on" ;                      shift   ;;
       -w|--want        ) export WANT_VERSION=$2 ;                   shift 2 ;;
+      -u|--update      ) export UPDATE_MODULE="on" ;                shift   ;;
       --) shift ; break ;;
       *) help ; break ;;
     esac
-------------- next part --------------
#!/bin/bash
#############################################################
#                                                           #
# module-update.plugin - plugin that performs an update of  #
#                        a module as a post install step    #
#                                                           #
#############################################################
#                                                           #
# Copyright 2008 by Christian Riggenbach under GPLv2        #
#                                                           #
#############################################################


# Same as in lvu but with the messages mostly as debug_msg and with return values; nasty hack...
edit_module_update()
{
  if [ "$ZLOCAL_OVERRIDES" != "on" ]; then
    message "${PROBLEM_COLOR}Cannot edit modules when ZLOCAL_OVERRIDES == off${DEFAULT_COLOR}"
    message "${PROBLEM_COLOR}Do this: \`lunar set ZLOCAL_OVERRIDES on\`${DEFAULT_COLOR}"
    return 1
  else
    if SECTION=$(find_section $1) ; then
      if echo $SECTION | grep -q ^zlocal; then
        debug_msg "Module \"$1\" is already in section \"zlocal\""
        debug_msg "unedit it first or edit the working copy"
        return 0
      else
        cp -a $MOONBASE/$SECTION/$1 $MOONBASE/zlocal/
        # clean out SCM directories
        find $MOONBASE/zlocal/$1 -type d -name CVS -o -name .svn | xargs rm -rf
        debug_msg "Copied \"$1\" from \"$SECTION\""
        debug_msg "Edit your module in \"$MOONBASE/zlocal/$1\""
        return 0
      fi
    else
      message "${PROBLEM_COLOR}Can't find module \"$1\"${DEFAULT_COLOR}"
      return 1
    fi
  fi
}

plugin_module_update () {

# check if --want and --update is given
  if [ "$UPDATE_MODULE" == "on" -a -n "$WANT_VERSION" ] ; then

    message "
${MESSAGE_COLOR}The module has compiled correctly and could be updated to version ${VERSION_COLOR}$WANT_VERSION${DEFAULT_COLOR}"

    # a few hints to guide new users of this function
    message "
${MESSAGE_COLOR}An update to version ${VERSION_COLOR}$WANT_VERSION${DEFAULT_COLOR}${MESSAGE_COLOR} is performed by the following steps:
 * copy the module to zlocal (as 'lvu edit' does)
 * edit the DETAILS file (update with new VERSION and UPDATE)
 * correct the sha1/md5 sum
 * recheck the DETAILS file
 * submit the module with '${BOLD}lvu submit ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR}'
The first three steps are done automaticaly, the following two are to be done by the user.${DEFAULT_COLOR}"

    # query the user to update
    if query "Do you want to update the module to version ${VERSION_COLOR}$WANT_VERSION${QUERY_COLOR} ? " n ; then

      # 'lvu edit' the module, see the function above
      if edit_module_update $MODULE ; then

        # make sure to get the right VERSION
        WANT_VERSION_BUFFER="$WANT_VERSION"
        SOURCE_BUFFER="$SOURCE"
        unset WANT_VERSION

        # get all the variables of the module again, espicialy the VERSION string
        run_details $MODULE

        message "${MESSAGE_COLOR}Update the module ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} from version ${VERSION_COLOR}$VERSION${DEFAULT_COLOR}${MESSAGE_COLOR} to ${VERSION_COLOR}$WANT_VERSION_BUFFER${DEFAULT_COLOR}${MESSAGE_COLOR}${DEFAULT_COLOR}"
        #echo $MODULE $SECTION $VERSION $WANT_VERSION $UPDATED

        # edit the VERSION string
        sedit "s/.*VERSION=.*/         VERSION=$WANT_VERSION_BUFFER/" "$MOONBASE/$SECTION/$MODULE/DETAILS"

        # produce the default value of UPDATED
        #WANT_UPDATED_DEFAULT="`date +%Y%m%d`"
        WANT_UPDATED_DEFAULT="`stat -c%y "$SOURCE_CACHE/$SOURCE_BUFFER" | awk '{print $1}' | awk -F - '{print $1$2$3}'`"

        message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR}: ${QUERY_COLOR}Please enter the UPDATED value. This should be as YYYYMMDD. [$WANT_UPDATED_DEFAULT]${DEFAULT_COLOR}"

        # read the UPDATED value. timeout with standart delay
        read -e -t $PROMPT_DELAY WANT_UPDATED

        # check if WANT_UPDATED is "", then fill in the default value
        if [ -z "$WANT_UPDATED" ] ; then
          WANT_UPDATED="$WANT_UPDATED_DEFAULT"
        fi

        # check if a platform-specific DETAILS-file is used
        if [ -e "$MOONBASE/$SECTION/$MODULE/DETAILS.$PLATFORM" ]; then
          DETAILS_FILE="$MOONBASE/$SECTION/$MODULE/DETAILS.$PLATFORM"
        else
          DETAILS_FILE="$MOONBASE/$SECTION/$MODULE/DETAILS"
        fi

        # edit the UPDATED string. no validation, so that strings like `date +xyz` are accepted.
        sedit "s/.*UPDATED=.*/         UPDATED=$WANT_UPDATED/" "$DETAILS_FILE"

        # check if there are more than one SOURCE
        if [ -n "$SOURCE1" -o -n "$SOURCE2" ] ; then
          message "${PROBLEM_COLOR}It's not possible to update automaticaly the sha1 sum of modules with multiple files!${DEFAULT_COLOR}"
        else
          # the magic of verifying the sources
          TMP_SHA1=$(sha1sum $SOURCE_CACHE/$SOURCE_BUFFER | cut -d " " -f 1-1)
          sedit "s/.*SOURCE_VFY=.*/      SOURCE_VFY=sha1:${TMP_SHA1}/" "$MOONBASE/$SECTION/$MODULE/DETAILS"
        fi

        message "${MESSAGE_COLOR}Please recheck the changes in ${FILE_COLOR}$MOONBASE/zlocal/$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR}
Module ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} successfully updated!${DEFAULT_COLOR}"

      fi

    fi

  fi

}

plugin_register BUILD_POST_INSTALL plugin_module_update

-------------- next part --------------
--- var/lib/lunar/plugins/verify-md5.plugin	2006-10-22 21:05:01.000000000 +0200
+++ /var/lib/lunar/plugins/verify-md5.plugin	2009-01-03 23:19:31.000000000 +0100
@@ -6,6 +6,7 @@
 #############################################################
 #                                                           #
 # Copyright 2005 by Auke Kok under GPLv2                    #
+#           2008 by Christian Riggenbach under GPLv2        #
 #                                                           #
 #############################################################
 
@@ -19,14 +20,43 @@
   TMP_MD5=$(md5sum $SOURCE_CACHE/$1 | cut -d " " -f 1-1)
   if [ "${2:4}" != "$TMP_MD5" ] ; then
     message "${PROBLEM_COLOR}! md5sum check failed for ${DEFAULT_COLOR}${FILE_COLOR}$1${DEFAULT_COLOR}"
-    verbose_msg "offending md5sum: $TMP_MD5"
-    verbose_msg "should be md5sum: ${2:4}"
-    return 1
+
+    # check if the SECTION of the module is "zlocal", so we can continue with updating the md5 sum
+    if [ $SECTION == "zlocal" ] ; then
+      message "${MESSAGE_COLOR}It's appearing that you compile a module from zlocal!${DEFAULT_COLOR}"
+      message "${MESSAGE_COLOR}When you have forgotten to change the md5-sum, please use this: ${DEFAULT_COLOR}md5:${TMP_MD5}"
+
+    # check if there are more than one SOURCE
+    if [ -n "$SOURCE1" -o -n "$SOURCE2" ] ; then
+      message "${PROBLEM_COLOR}It's not possible to update automaticaly the md5 sum of modules with multiple files!${DEFAULT_COLOR}"
+      return 1
+    else
+      # check if a platform-specific DETAILS-file is used
+      if [ -e "$MOONBASE/$SECTION/$MODULE/DETAILS.$PLATFORM" ]; then
+        DETAILS_FILE="$MOONBASE/$SECTION/$MODULE/DETAILS.$PLATFORM"
+      else
+        DETAILS_FILE="$MOONBASE/$SECTION/$MODULE/DETAILS"
+      fi
+      if query "Do you want to correct the md5 sum in the DETAILS file ? " n ; then
+        if query "Do you want to force the checksum to sha1 ?" y ; then
+          sedit "s/.*SOURCE_VFY=md5:.*/      SOURCE_VFY=sha1:`sha1sum $SOURCE_CACHE/$1 | cut -d " " -f 1-1`/" "$DETAILS_FILE"
+        return 2
+        else
+          sedit "s/.*SOURCE_VFY=md5:.*/      SOURCE_VFY=md5:${TMP_MD5}/" "$DETAILS_FILE"
+            return 2
+        fi
+      else
+        verbose_msg "offending md5sum: $TMP_MD5"
+        verbose_msg "should be md5sum: ${2:4}"
+        return 1
+      fi
+    fi
+    fi
   else
     # always return 'continue' plugin value
     return 2
-  fi  
+  fi
 }
 
-
 plugin_register SOURCE_VERIFY plugin_source_verify_md5
+
-------------- next part --------------
--- var/lib/lunar/plugins/verify-sha1.plugin	2006-10-22 21:05:01.000000000 +0200
+++ /var/lib/lunar/plugins/verify-sha1.plugin	2009-01-03 23:19:16.000000000 +0100
@@ -6,6 +6,7 @@
 #############################################################
 #                                                           #
 # Copyright 2005 by Auke Kok under GPLv2                    #
+#           2007 by Christian Riggenbach under GPLv2        #
 #                                                           #
 #############################################################
 
@@ -19,14 +20,39 @@
   TMP_MD5=$(sha1sum $SOURCE_CACHE/$1 | cut -d " " -f 1-1)
   if [ "${2:5}" != "$TMP_MD5" ] ; then
     message "${PROBLEM_COLOR}! sha1sum check failed for ${DEFAULT_COLOR}${FILE_COLOR}$1${DEFAULT_COLOR}"
-    verbose_msg "offending sha1sum: $TMP_MD5"
-    verbose_msg "should be sha1sum: ${2:5}"
-    return 1
+
+      # check if the SECTION of the module is "zlocal", so we can continue with updating the sha1 sum
+      if [ $SECTION == "zlocal" ] ; then
+        message "${MESSAGE_COLOR}It's appearing that you compile a module from zlocal!${DEFAULT_COLOR}"
+        message "${MESSAGE_COLOR}When you have forgotten to change the SHA1-sum, please use this: ${DEFAULT_COLOR}sha1:${TMP_MD5}${MESSAGE_COLOR} for the file ${DEFAULT_COLOR}$1"
+
+        # check if there are more than one SOURCE
+        if [ -n "$SOURCE1" -o -n "$SOURCE2" ] ; then
+          message "${PROBLEM_COLOR}It's not possible to update automaticaly the sha1 sum of modules with multiple files!${DEFAULT_COLOR}"
+          return 1
+        else
+          # check if a platform-specific DETAILS-file is used
+          if [ -e "$MOONBASE/$SECTION/$MODULE/DETAILS.$PLATFORM" ]; then
+            DETAILS_FILE="$MOONBASE/$SECTION/$MODULE/DETAILS.$PLATFORM"
+          else
+            DETAILS_FILE="$MOONBASE/$SECTION/$MODULE/DETAILS"
+          fi
+          if query "Do you want to correct the sha1 sum in the DETAILS file ? " n ; then
+            sedit "s/.*SOURCE_VFY=sha1:.*/      SOURCE_VFY=sha1:${TMP_MD5}/" "$DETAILS_FILE"
+            return 2
+          else
+            verbose_msg "offending sha1sum: $TMP_MD5"
+            verbose_msg "should be sha1sum: ${2:5}"
+            return 1
+          fi
+        fi
+
+      fi
   else
     # always return 'continue' plugin value
     return 2
-  fi  
+  fi
 }
 
-
 plugin_register SOURCE_VERIFY plugin_source_verify_sha1
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
URL: <http://foo-projects.org/pipermail/lunar/attachments/20090103/d6fda3f5/attachment.bin>


More information about the Lunar mailing list