FAQ   Search   Memberlist  
Profile    Log in to check your private messages    Register    Log in
Comps Script

 
Post new topic   Reply to topic    BLAG Forum Index -> development
View previous topic :: View next topic  
Author Message
stevo32
PostPosted: Tue Jan 26, 2010 10:11 pm    Post subject: Comps Script Reply with quote

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).
Bhantora
PostPosted: Tue May 31, 2011 8:54 am    Post subject: Reply with quote

Whats this code is not support in my PC.Its for general use or any thing special.
Display posts from previous:   
Post new topic   Reply to topic    BLAG Forum Index -> development
Page 1 of 1

Protected by Anti-Spam ACP