[SM-Commit] GIT changes to master quill by Jaka Kranjc (769c64b60a186be9704f4e15fbafe625637937e7)

Jaka Kranjc scm at mail.sourcemage.org
Mon Jan 15 17:27:25 EST 2007


GIT changes to master quill by Jaka Kranjc <lynxlynxlynx at sourcemage.org>:

 usr/bin/quill                   |  144 ++++++++++++++++++++++++++++------------
 var/lib/quill/ChangeLog         |   10 ++
 var/lib/quill/modules/libcore   |   74 ++++++++++++--------
 var/lib/quill/modules/libupdate |   82 ++++++++++++++++++++++
 4 files changed, 240 insertions(+), 70 deletions(-)

New commits:
commit 769c64b60a186be9704f4e15fbafe625637937e7
Author: Jaka Kranjc <lynxlynxlynx at sourcemage.org>
Commit: Jaka Kranjc <lynxlynxlynx at sourcemage.org>

    committing some unfinished work:
    
    * a lot of update mode improvements, almost ready for general use (currently battling a sed wierdy)
    enabled it for explorers, added libupdate for shared code
    * some misc other improvements

diff --git a/usr/bin/quill b/usr/bin/quill
index cadb330..b7724cc 100755
--- a/usr/bin/quill
+++ b/usr/bin/quill
@@ -11,11 +11,8 @@
 ## @ToDo <80 single else multi
 ## @ToDo Interface to add CONFIGURE options
 ## @ToDo Automated bugcli submissions of spells
-## @ToDo Automatic inclusion into a grimoire when finished
 ## @ToDo Add a better configuration interface(dialog based I hope)
-## @ToDo Make it possible to also update spells using quill
 ## @ToDo Make quill the be-all for spells
-## @ToDo Make quill interface with grimoire to get functions
 ##
 ## Asks the user in simple questions about generating a spell.
 ## @Globals BUILDISON, INSTALLISON, PREBUILDISON, TRIGGERSISON
@@ -93,6 +90,7 @@ quill_rc
 # we should do some quillrc sanity checking someday
 [[ ! -d $QUILL_SPELL_DIR ]] &&
   echo "PEBKAC: bad QUILL_SPELL_DIR ($QUILL_SPELL_DIR)" &&
+  echo "Try running quill -r" &&
   exit 7
 
 PROMPT_DELAY="31557807"
@@ -122,7 +120,7 @@ then
   quill_cpan_core $QUILL_TARGET
 fi
 
-if [[ "$QUILL_UPDATE" == "ion" ]]
+if [[ "$QUILL_UPDATE" == "on" ]]
 then
   while true; do
     SPELL_NAME=$QUILL_TARGET
@@ -138,17 +136,20 @@ then
              "Add a \$SCM version" \
              "Try it out" \
              "Quit" )
-    query_list "What do you want to do?" ANSWER ${actions[0]} "${actions[@]}"
+    query_list "What do you want to do?" ANSWER "${actions[0]}" "${actions[@]}"
 
     [[ $ANSWER == "Quit" ]] && exit 0
 
     #copy spell over and move there
+    codex_get_spell_paths $(codex_find_spell_by_name $SPELL_NAME)
     rm -fr $QUILL_SPELL_DIR/$SPELL_NAME
-    cp -rv $(codex_find_spell_by_name $SPELL_NAME) $QUILL_SPELL_DIR
+    cp -r $SECTION_DIRECTORY/$SPELL_NAME $QUILL_SPELL_DIR
     cd $QUILL_SPELL_DIR/$SPELL_NAME
+    cp DETAILS DETAILS.orig
 
     case "$ANSWER" in
       "${actions[0]}") #"Update the spell to a newer version"
+
         #fetch current versions, ignoring SCM ones
         versions=( $(sed -n 's/\s*\<VERSION=//p' DETAILS |
                    grep -Eiv '\$[(]date *+|cvs|svn|tla|git|scm') )
@@ -165,56 +166,76 @@ then
             sed -i "s/\<VERSION=$version\>/VERSION=$SPELL_VERSION/" DETAILS
 
             #check for multiversion spells
-            if [[ $(grep -c "\<SOURCE=") != 1 ]]
-            then #we have problems
+            if [[ $(grep -cE "\<SOURCE.?=" DETAILS) != 1 ]]
+            then #we have a problem
               message "Oh dear, detected a multiversion spell. Going to cat DETAILS for you "
               message "and then you will tell me which variable I need to set, so I can get "
-              message "to the correct version ($SPELL_VERSION)."
+              message "to the correct version ($version)."
               sleep 3
               cat DETAILS
-              query_string if_var "${QUERY_COLOR}Please enter the appropriate variable. Example: UGU_DEVEL=y${DEFAULT_COLOR}"
+              query_string if_var "${QUERY_COLOR}Please enter the appropriate variable. Example: UGU_DEVEL=y${DEFAULT_COLOR} "
             fi
 
             #check that (usually new) source urls are ok
-            sources_and_urls=$($if_var; . /DETAILS &> /dev/null; get_spell_files_and_urls)
-            sources=$(sed 's/^\(\S*\)\s.*$/\1/' <<< "$sources_and_urls" )
-            source_urls=$(sed 's/^\S*\s*\(.\S*\)\s.*$/\1/' <<< "$sources_and_urls" )
+            get_sources_and_urls
+
             i=
             for su in $source_urls
             do
-              wget -S --spider "$su" 2>&1 | grep -q "ERROR 404"
-              #... if they are not ask for fixed ones
-              if [[ $? != 0 ]]
+              if ! grep -q ftp:// <<< "$su"
+              then
+                # the return value acrobatics make both blocks return the same
+                wget -S --spider "$su" 2>&1 | grep -q "ERROR 404"
+                if [[ $? == 0 ]]
+                then
+                  rc=1
+                else
+                  rc=0
+                fi
+              else
+                wget -S "${su%/*}/" 2>&1 | grep -q "${su##*/}"
+                rc=$?
+              fi
+              #echo
+              #... if they are not ok ask for fixed ones
+              if [[ $rc == 0 ]]
               then
                 message "SOURCE${i}_URL[0] is ok!"
               else
                 message  "SOURCE${i}_URL[0] is broken! Fix it manually."
+                sleep 2
                 quill_edit DETAILS
               fi
-              let i=+1
+              [[ ! $i ]] && i=1
+              let i+=1
             done
 
-            #recheck that (usually new) source urls are ok
-            #FIXME: avoid duplication by moving this in a function
-            sources_and_urls=$($if_var; . /DETAILS &> /dev/null; get_spell_files_and_urls)
-            sources=$(sed 's/^\(\S*\)\s.*$/\1/' <<< "$sources_and_urls" )
-            source_urls=$(sed 's/^\S*\s*\(.\S*\)\s.*$/\1/' <<< "$sources_and_urls" )
+            #reparse the possibly new source urls and company
+            get_sources_and_urls
 
             #download; we are not a grimoire so some hacking is needed
+            echo
             summon -r <<< "$sources_and_urls"
 
+            # ask for SECURITY_PATCHing
+            update_patchlevel SECURITY_PATCH
+
+            #restore patchlevel?
+            update_patchlevel PATCHLEVEL skip remove
+
             #get hashes and save them, removing any previous hash/gpg
             i=
             for source in $sources
             do
-              hash=$(quill_hash_get $source)
-              current_check=$( $if_var; . /DETAILS &> /dev/null; eval echo \$SOURCE${i}_HASH\$SOURCE${i}_GPG\$SOURCE${i}_IGNORE)
+              hash=$(quill_hash_get $SOURCE_CACHE/$source)
+              # use the original DETAILS, as we already changed the VERSION
+              current_check=$(eval ${if_var:-:}; . DETAILS.orig &> /dev/null; eval echo \$SOURCE${i}_HASH\$SOURCE${i}_GPG\$SOURCE${i}_IGNORE)
 
               #skip SOURCE_IGNORE
               if grep -Eq "volatile|signature|unversioned" <<< "$current_check"
               then
                 [[ ! $i ]] && i=1
-                let i=+1
+                let i+=1
                 continue
               fi
 
@@ -225,32 +246,74 @@ then
                 then
                   message "Here is the hash for SOURCE$i anyway, if you need it later: $hash"
                   [[ ! $i ]] && i=1
-                  let i=+1
+                  let i+=1
                   continue
+                #TODO: else sign it and continue
                 fi
               fi
 
               #it is either a SOURCE_HASH or the user wants to replace SOURCE_GPG
-              sed -ir "s/^(\s*)SOURCE${i}_(GPG|HASH)=$current_check$/\1SOURCE${i}_HASH=$hash/" DETAILS
+
+              # SOURCE_GPG usually has unexpanded variables, while we have the expanded
+              if ! grep -q $current_check DETAILS.orig
+              then # looks like it is expanded
+                current_check=$(
+                eval ${if_var:-:}; . DETAILS.orig &> /dev/null;
+                for j in `get_source_nums s`
+                do
+                  j="${j%s}"
+                  SOURCE=$(eval echo \$SOURCE$j)
+                  substitute_with_variables current_check "$SOURCE" {SOURCE$j}
+                done
+                substitute_with_variables current_check "$SPELL_NAME" {SPELL} "$VERSION" {VERSION}
+                echo $current_check
+                )
+              fi
+              if ! grep -q $current_check DETAILS.orig
+              then # maybe the author doesn't like the ugly braces too
+                current_check="$(tr -d "{}" <<< $current_check)"
+              fi
+              if ! grep -q $current_check DETAILS.orig
+              then # give up
+                message "Giving up, you'll have to update SOURCE${i}_(GPG|HASH) yourself."
+                [[ ! $i ]] && i=1
+                let i+=1
+                continue
+              fi
+
+              echo sed -ir "s/^(\s*)SOURCE${i}_(GPG|HASH)=$current_check\s*$/\1SOURCE${i}_HASH=$hash/" DETAILS
+sed -ir "s/^(\s*)SOURCE${i}_(GPG|HASH)=$current_check\s*$/\1SOURCE${i}_HASH=$hash/" DETAILS
+#exit
+# sed -ir s/^(\s*)SOURCE_(GPG|HASH)=gnu.gpg:$SOURCE.sig:UPSTREAM_KEY\s*$/\1SOURCE_HASH=b341b5b172472338ff2bcffe569f3a0796defe1d326eb85ce52daeff5ce1fb0c9304ec10052c604cadea4056f58f50d11c302ba02b979e88e1d9f112e614b7a9/ DETAILS
+# sed: -e expression #1, char 206: invalid reference \1 on `s' command's RHS
+# Do you want to replace SOURCE3_GPG with a hash? [n] y
+# sed -ir s/^(\s*)SOURCE3_(GPG|HASH)=sha512:e7ee7a09880d19dea3d2c0d498631ee9d269738e7acdeba0a346da3b8bd0629628582973de33e6ac0c913e8c691806a50e07d520d6f6d078b76a3e74b9b61fd7\s*$/\1SOURCE3_HASH=e7ee7a09880d19dea3d2c0d498631ee9d269738e7acdeba0a346da3b8bd0629628582973de33e6ac0c913e8c691806a50e07d520d6f6d078b76a3e74b9b61fd7/ DETAILS
+# sed: -e expression #1, char 311: invalid reference \1 on `s' command's RHS
+
               [[ ! $i ]] && i=1
-              let i=+1
+              let i+=1
             done
 
-            #restore patchlevel
-            sed -i "/^[^#]*\<PATCHLEVEL=/d" DETAILS
+            #update HISTORY
+            add_history_entries "DETAILS: updated ${if_var:-spell} to $SPELL_VERSION"
+
           fi
         done
 
-#update HISTORY
-add_history_entries "DETAILS: updated to $SPELL_VERSION"
+        message "Time for review and custom modifications"
+        sleep 1
+        quill_edit
+        echo
 
-#copy the spell back to the grimoire?
-#FIXME: root only, fix the end of quill first
-cp -rv $QUILL_SPELL_DIR/$SPELL_NAME $(codex_find_spell_by_name $SPELL_NAME|dirname)
+        message "Copying the spell back ..."
+        quill_final_put_in_grimoire $GRIMOIRE $SECTION no
 
-message "Done with updating the spell!"
+        rm DETAILS.orig
+        echo
+        message "Done with updating the spell!"
+        echo
 
-        echo ++"$ANSWER"++ ;;
+      ;;
       "${actions[1]}") #"Manage patches"
 #update patchlevel?
 #update HISTORY
@@ -266,11 +329,8 @@ message "Done with updating the spell!"
 #copy the spell back to the grimoire?
         echo ++"$ANSWER"++ ;;
       "${actions[4]}") #"Try it out"
-#check if there is anything to try out
-  #if not just continue
-#copy the spell back to the grimoire
-#cast
-        echo ++"$ANSWER"++ ;;
+        cast -c $SPELL_NAME
+      ;;
     esac
 
   done
diff --git a/var/lib/quill/ChangeLog b/var/lib/quill/ChangeLog
index ce04422..2586af9 100644
--- a/var/lib/quill/ChangeLog
+++ b/var/lib/quill/ChangeLog
@@ -1,3 +1,13 @@
+2007-01-14 Jaka Kranjc <lynxlynxlynx at sourcemage.org>
+	* libcore: made quill_final_put_in_grimoire be optionally non-interactive
+	  quill_rc creates the QUILL_SPELL_DIR now
+	  made quill_edit edit only text files
+	  improved a few messages
+	* quill: further improvements in the update code
+	* libupdate: a new module that holds a few update specific functions
+	* version: 0.1.11
+	  TODO: custom copy+config, robusting and then it's 0.2-ready
+
 2007-01-10 Andraž "ruskie" Levstik <ruskie at mages.ath.cx>
 	* libperlcpan: fixed searching for the proper module
 	  better spell name setup
diff --git a/var/lib/quill/modules/libcore b/var/lib/quill/modules/libcore
index 83faede..b9839e4 100644
--- a/var/lib/quill/modules/libcore
+++ b/var/lib/quill/modules/libcore
@@ -89,6 +89,7 @@ function quill_rc() {
             "\nGURU_NAME=\"${GURU_NAME}\"" \
             "\nGURU_EMAIL=\"${GURU_EMAIL}\"" \
             "\nQUILL_SPELL_DIR=\"${QUILL_SPELL_DIR}\"" > $QUILL_QUILLRC
+    mkdir -p $QUILL_SPELL_DIR
     exit 0
   else
      . ${QUILL_QUILLRC}
@@ -98,7 +99,7 @@ function quill_rc() {
 #---
 ## @Synopsis The welcome message for quill
 function quill_welcome() {
-  message "Welcome to SourceMage GNU/Linux quill - a spell creator script."
+  message "Welcome to SourceMage GNU/Linux quill - a spell creator and updater script."
   message "-----------------------------------------------------------------------------"
   message "This makes an immediately useable spell from some minor data or "
   message "updates an exsisting one.."
@@ -114,11 +115,17 @@ function quill_welcome() {
 ## @Synopsis used to edit spell files
 #---
 function quill_edit() {
+  local spell_file type
+
   message "Now invoking $EDITOR to edit spell files."
   cd ${QUILL_SPELL_DIR}/${SPELL_NAME}
-  for SPELL_FILE in ${1:-*}
+  for spell_file in ${1:-*}
   do
-    $EDITOR ${SPELL_FILE}
+    type=$(file -bi $spell_file)
+    if list_find "$type" "text/plain;"
+    then
+      $EDITOR $spell_file
+    fi
   done
   message "All modifications complete."
 }
@@ -151,49 +158,60 @@ function quill_set_executable_bit() {
 }
 
 #---
-## @Synopsis function to put the spell into the grimoire
+## @Synopsis function to put the spell into the grimoire. The first two args
+##           toggle interactivity and the third the reindexing of the grimoire
+##
+## @param internal flag toggling interactivity - grimoire (canonical)
+## @param internal flag toggling interactivity - section
+## @param flag toggling scribe reindex, set it to "no" to toggle
 #---
 function quill_final_put_in_grimoire() {
 
-  query_list "Into which grimoire do you wish to put the spell:" QUILL_GRIM_NAME \
-    "" $(codex_get_all_grimoires | get_basenames)
-  echo
-  QUILL_GRIM_NAME=$(codex_canonicalize_grimoire_name $QUILL_GRIM_NAME)
-
-  # can't use query_list, as the section count can be bigger than the available index
-  message "Available sections in grimoire $QUILL_GRIM_NAME:"
-  codex_get_section_names $QUILL_GRIM_NAME | column
-  query_string QUILL_SECT_NAME "Into which section do you wish to put the spell: "
-
-  if [[ -e $QUILL_GRIM_NAME/$QUILL_SECT_NAME/$SPELL_NAME ]]; then
-    message "${MESSAGE_COLOR}There is an exsisting spell for $SPELL_NAME in $QUILL_GRIM_NAME/$QUILL_SECT_NAME"
-    if ! query "Do you want to overwrite it?" y; then
-      quill_final_put_in_grimoire
-      return
+  if [[ -z $2 ]]; then
+    query_list "Into which grimoire do you wish to put the spell:" QUILL_GRIM_NAME \
+      "" $(codex_get_all_grimoires | get_basenames)
+    echo
+    QUILL_GRIM_NAME=$(codex_canonicalize_grimoire_name $QUILL_GRIM_NAME)
+
+    # can't use query_list, as the section count can be bigger than the available index
+    message "Available sections in grimoire $QUILL_GRIM_NAME:"
+    codex_get_section_names $QUILL_GRIM_NAME | column
+    query_string QUILL_SECT_NAME "Into which section do you wish to put the spell: "
+
+    if [[ -e $QUILL_GRIM_NAME/$QUILL_SECT_NAME/$SPELL_NAME ]]; then
+      message "${MESSAGE_COLOR}There is an exsisting spell for $SPELL_NAME in $QUILL_GRIM_NAME/$QUILL_SECT_NAME"
+      if ! query "Do you want to overwrite it?" y; then
+        quill_final_put_in_grimoire
+        return
+      fi
     fi
+  else
+    QUILL_GRIM_NAME="$1"
+    QUILL_SECT_NAME="$2"
   fi
-
-  message "Scribbling spell into $QUILL_GRIM_NAME/$QUILL_SECT_NAME/$SPELL_NAME ..."
+  message "Copying spell into $QUILL_GRIM_NAME/$QUILL_SECT_NAME/$SPELL_NAME ..."
 
   quill_final_put_in_grimoire_sub(){
     mkdir -p $QUILL_GRIM_NAME/$QUILL_SECT_NAME
     cp -r $QUILL_SPELL_DIR/$SPELL_NAME $QUILL_GRIM_NAME/$QUILL_SECT_NAME/
     if [[ $? != 0 ]]; then
-      echo "Scribbling failed!"
+      echo "Copying failed!"
       return 1
     else
-      echo "Scribbling succeded"
-      echo
-      echo "Running scribe reindex on $QUILL_GRIM_NAME ..."
-      scribe reindex $(basename $QUILL_GRIM_NAME)
+      echo "Copying succeded"
+      if [[ $1 != no ]]; then
+        echo
+        echo "Running scribe reindex on $QUILL_GRIM_NAME ..."
+        scribe reindex $(basename $QUILL_GRIM_NAME)
+      fi
     fi
   }
   if [[ $UID == 0 ]]; then
-    quill_final_put_in_grimoire_sub
+    quill_final_put_in_grimoire_sub $3
   else
     export QUILL_GRIM_NAME QUILL_SECT_NAME QUILL_SPELL_DIR SPELL_NAME
     su -c "$(declare -f quill_final_put_in_grimoire_sub); \
-      quill_final_put_in_grimoire_sub"
+      quill_final_put_in_grimoire_sub $3"
   fi
 
 }
diff --git a/var/lib/quill/modules/libupdate b/var/lib/quill/modules/libupdate
new file mode 100644
index 0000000..d5923fd
--- /dev/null
+++ b/var/lib/quill/modules/libupdate
@@ -0,0 +1,82 @@
+#---
+## @Synopsis Sets up some global variables that contain sources and urls
+#---
+function get_sources_and_urls()
+{
+  sources_and_urls=$(eval ${if_var:-:}; . DETAILS &> /dev/null; get_spell_files_and_urls)
+  sources=$(sed 's/^\(\S*\)\s.*$/\1/' <<< "$sources_and_urls" )
+  source_urls=$(sed 's/^\S*\s\(.\S*\)\s.*$/\1/' <<< "$sources_and_urls" )
+}
+
+#---
+## @Synopsis Sets a variable from details, first setting the flag if_var
+## @param variable to set
+#---
+function conditional_set_var()
+{
+  eval ${if_var:-:}; . DETAILS &> /dev/null; eval echo -n \$$1
+}
+
+#---
+## @Synopsis Increments or removes PATCHLEVEL or SECURITY_PATCH. Ask first
+## @Synopsis unless the second argument is "skip"
+##
+## @param PATCHLEVEL or SECURITY_PATCH - work with which wone?
+## @param (optional) skip the query? skip to skip
+## @param (optional) remove or increment? remove to remove
+## @param (optional) default answer for the query, default is n
+#---
+function update_patchlevel()
+{
+  local current_value
+
+  current_value=$(conditional_set_var $1)
+  if [[ ! -z $current_value ]]
+  then
+    if [[ $2 != skip ]]
+    then
+      if query "Do you want to increment $1?" ${4:-n}
+      then
+        update_patchlevel_sub $1 $current_value $3
+      fi
+    else
+      update_patchlevel_sub $1 $current_value $3
+    fi
+  fi
+}
+
+function update_patchlevel_sub()
+{
+  local current_value=$2 action=$3 new_value
+  new_value=$(( current_value+=1 ))
+
+  if (( $(grep -c "^[^#]*$1=$current_value" DETAILS) > 1 ))
+  then
+    message "Two or more $1 variables with the same value found."
+    message "All will be changed - revert the bad ones manually."
+  fi
+  if [[ $action != remove ]]
+  then
+    sed -i "/^[^#]*$1=$current_value/ s,=.*$,=$new_value," DETAILS
+  else #PATCHLEVEL removal on version updates
+    sed -i "/^[^#]*$1=$current_value/d" DETAILS
+  fi
+}
+
+#---
+##
+## This software is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This software is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this software; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+##
+#---



More information about the SM-Commit mailing list