BLAG

BLAG Forums
It is currently Tue Dec 23, 2014 3:48 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Comps Script
PostPosted: Tue Jan 26, 2010 10:11 pm 
Offline
Site Admin

Joined: Sun Mar 14, 2004 6:08 pm
Posts: 973
Location: Canada
As requested on IRC, here's the comps script I wrote several years ago:
Code:
#!/bin/bash
# (C) 2006-2007 Stephen Clement (stevo32). Licensed under the GNU GPL.
# This script will merge core + extras comps.xml
# Check the comments at the end of the output.
CORE=comps-core-clean.xml
EXTRAS=comps-extras-clean.xml
APPEND=comps-append.xml
MERGED=comps-merge.xml
MERGEDTEMP=comps-merge-temp.xml
CONT=true
PLUS=0
GROUPEXISTS=2

cp $CORE $MERGED
rm $APPEND

for a in `grep -n "<group>" $EXTRAS | cut -f1 -d:`
   do #echo A $a
   while true; do
      #echo DEBUG1
      LINE=`expr $a + $PLUS`
      #echo LINE $LINE
      OUTPUT=`head -n $LINE $EXTRAS|tail -n 1`
      #echo OUTPUT $OUTPUT
      if [[ "$OUTPUT" == "  </group>" ]] ; then
         #echo DEBUG2
         if [[ "$GROUPEXISTS" == "1" ]] ; then
            echo "$OUTPUT" >> $APPEND
         fi
         PLUS=0
         GROUPEXISTS=2
         break
      elif [[ "$OUTPUT" == *\<id>*\</id> ]] ; then
         #echo DEBUG3
         #ID=`echo $OUTPUT |sed -e 's/<id>//g' -e 's/</id>//g'`;
         #echo $ID
         if [[ "`grep "$OUTPUT" $CORE`" == $OUTPUT ]] ; then
            #echo DEBUG8
            GROUPEXISTS=0 # Found it! Now let's inject these new packages...
            #echo "Append these lines somewhere around line" `grep -n "$OUTPUT" $CORE |cut -f1 -d:`
            INJECTLINE=`grep -n "$OUTPUT" $MERGED |cut -f1 -d:`
            #echo INJECTLINEPREDEBUG9 $INJECTLINE
            while [[ "$CONT" == "true" ]] ; do
               #echo DEBUG9
               INJECTLINE=`expr $INJECTLINE + 1`
               INJECTOUTPUT=`head -n $INJECTLINE $MERGED |tail -n 1`
               if [[ "$INJECTOUTPUT" == *\<packagereq>*\</packagereq> ]]; then
                  CONT=false
               fi
            done
            CONT=true
         else
            GROUPEXISTS=1 # We'll need to recreate it and append it to the end of the file...
            echo >> $APPEND
            echo "  <group>" >> $APPEND
            echo "$OUTPUT" >> $APPEND
         fi
         PLUS=`expr $PLUS + 1`
      elif [[ "$OUTPUT" == *\<packagereq>*\</packagereq> ]]; then
         #echo DEBUG4
         #echo $ID $OUTPUT
         if [[ "$GROUPEXISTS" == "0" ]] ; then
            #echo DEBUG10
            MERGEDLENGTH=`wc -l <MERGED> $MERGEDTEMP
            echo "$OUTPUT" >> $MERGEDTEMP
            tail -n `expr $MERGEDLENGTH - $INJECTLINE` $MERGED >> $MERGEDTEMP
            cp $MERGEDTEMP $MERGED
         elif [[ "$GROUPEXISTS" == "1" ]] ; then
            echo "$OUTPUT" >> $APPEND
         else
            echo "WHOA THERE! DEBUG7 AT LINE $LINE WITH CONTENTS $OUTPUT"
            echo "Continuing despite errors..."
         fi
         PLUS=`expr $PLUS + 1`
      elif [[ "$OUTPUT" == "</comps>" ]] ; then # This really ought to be unnecessary. This'll stop the script if it goes haywire.
         #echo DEBUG6
         echo "ERROR11"
         exit;
      else
         if [[ "$GROUPEXISTS" == "1" ]] ; then
            echo "$OUTPUT" >> $APPEND
         fi
         #echo DEBUG5
         PLUS=`expr $PLUS + 1`
      fi
   done
continue
done

# This finds out where we're supposed to merge the two scripts.
MERGEPLUS=1
while true;
   #echo MERGEPLUS $MERGEPLUS
   do MERGEOUTPUT=`tail -n $MERGEPLUS $MERGED|head -n 1`
   #echo MERGEOUTPUT $MERGEOUTPUT
   if [[ $MERGEOUTPUT == "  </group>" ]] ; then
      MERGEPLUS=`expr $MERGEPLUS - 1`
      break;
   elif [[ $MERGEOUTPUT == "<comps>" ]] ; then
      echo ERROR12
      exit
   else
      MERGEPLUS=`expr $MERGEPLUS + 1`
   fi
done

# We're going to start outputting the final result now.
MERGEWC=`wc -l < $MERGED`
head -n `expr $MERGEWC - $MERGEPLUS` $MERGED
cat $APPEND
tail -n $MERGEPLUS $MERGED

APPENDLINE=1
APPENDWC=`wc -l < $APPEND`
while true;
   do APPENDOUTPUT=`head -n $APPENDLINE $APPEND|tail -n 1`
   if [[ $APPENDOUTPUT == *\<id>*\</id> ]] ; then
      APPENDID=`echo $APPENDOUTPUT |sed -e 's/<id>//g' -e 's/</id>//g'`;
      echo "<Add>"
      APPENDLINE=`expr $APPENDLINE + 1`
   elif [[ "$APPENDLINE" == "$APPENDWC" ]] ; then
      break
   else
      APPENDLINE=`expr $APPENDLINE + 1`
   fi
done

_________________
E-mail me at s.clement@localhost (replace localhost with sympatico.ca) or stevo32@localhost (replace localhost with blagblagblag.org).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2011 8:54 am 
Offline

Joined: Thu May 26, 2011 5:34 pm
Posts: 2
Whats this code is not support in my PC.Its for general use or any thing special.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group