Home | History | Annotate | Line # | Download | only in scripts
      1  1.1  haad #!/bin/sh
      2  1.1  haad #$Header: /tank/opengrok/rsync2/NetBSD/src/external/gpl2/lvm2/dist/scripts/last_cvs_update.sh,v 1.1.1.1 2008/12/22 00:18:57 haad Exp $
      3  1.1  haad ################################################################################
      4  1.1  haad ##
      5  1.1  haad ##    Copyright 2001 Sistina Software, Inc.
      6  1.1  haad ##
      7  1.1  haad ##    This is free software released under the GNU General Public License.
      8  1.1  haad ##    There is no warranty for this software.  See the file COPYING for
      9  1.1  haad ##    details.
     10  1.1  haad ##
     11  1.1  haad ##    See the file CONTRIBUTORS for a list of contributors.
     12  1.1  haad ##
     13  1.1  haad ##    This file is maintained by:
     14  1.1  haad ##      AJ Lewis <lewis (at] sistina.com>
     15  1.1  haad ## 
     16  1.1  haad ##    File name: last_cvs_update.sh
     17  1.1  haad ##
     18  1.1  haad ##    Description: displays the last file updated by CVS commands and the date
     19  1.1  haad ##                 it was updated.  May be given a relative or absolute path.
     20  1.1  haad ##                 Based on this information, you should be able to do a 
     21  1.1  haad ##                 cvs co -D $date GFS and get the same version of the source
     22  1.1  haad ##                 tree as this tool was run on.
     23  1.1  haad ##                 
     24  1.1  haad ##                 Will also give you the CVS tag the source tree is based off
     25  1.1  haad ##                 off when appropriate
     26  1.1  haad ## 
     27  1.1  haad ##                 Output format:
     28  1.1  haad ##                 [Tag:  $TAG]
     29  1.1  haad ##                 The last file updated by CVS was:
     30  1.1  haad ##                 $path/$file
     31  1.1  haad ##                 on
     32  1.1  haad ##                 $date
     33  1.1  haad ##
     34  1.1  haad ################################################################################
     35  1.1  haad 
     36  1.1  haad if [[ -z $1 ]];
     37  1.1  haad  then path=.;
     38  1.1  haad else
     39  1.1  haad  if [[ $1 == "-h" ]];
     40  1.1  haad    then echo "usage: $0 [ -h | path ]"
     41  1.1  haad         exit 0;
     42  1.1  haad  else
     43  1.1  haad    if [[ -d $1 ]]
     44  1.1  haad      then path=$1;
     45  1.1  haad    else
     46  1.1  haad      echo "usage: $0 [ -h | path ]"
     47  1.1  haad      exit 0;
     48  1.1  haad    fi
     49  1.1  haad  fi
     50  1.1  haad fi
     51  1.1  haad 
     52  1.1  haad # grab the tag from the path passed in
     53  1.1  haad if [[ -f $path/CVS/Tag ]];
     54  1.1  haad   then echo "Tag: " `cat $path/CVS/Tag | sed -e 's/^[NT]//'`
     55  1.1  haad fi
     56  1.1  haad 
     57  1.1  haad awk '
     58  1.1  haad BEGIN {                            
     59  1.1  haad   FS = "/"                         
     60  1.1  haad }
     61  1.1  haad {
     62  1.1  haad     # find the path for the Entries file
     63  1.1  haad     path = FILENAME
     64  1.1  haad     sub(/^\.\//, "", path)
     65  1.1  haad     
     66  1.1  haad     # remove the CVS part of it
     67  1.1  haad     sub(/CVS\/Entries/, "", path)
     68  1.1  haad     
     69  1.1  haad     # add the path the the filename that was modified, and put the date it was
     70  1.1  haad     # modified in as well
     71  1.1  haad     print path $2 " " $4
     72  1.1  haad 
     73  1.1  haad }' `find $path -name "Entries" -printf "%h/%f "` | awk '
     74  1.1  haad # converts string name of month the a numeral
     75  1.1  haad function cvt_month(month) {
     76  1.1  haad   if(month == "Jan")
     77  1.1  haad     return 0
     78  1.1  haad   if(month == "Feb")
     79  1.1  haad     return 1
     80  1.1  haad   if(month == "Mar")
     81  1.1  haad     return 2
     82  1.1  haad   if(month == "Apr")
     83  1.1  haad     return 3
     84  1.1  haad   if(month == "May")
     85  1.1  haad     return 4
     86  1.1  haad   if(month == "Jun")
     87  1.1  haad     return 5
     88  1.1  haad   if(month == "Jul")
     89  1.1  haad     return 6
     90  1.1  haad   if(month == "Aug")
     91  1.1  haad     return 7
     92  1.1  haad   if(month == "Sep")
     93  1.1  haad     return 8
     94  1.1  haad   if(month == "Oct")
     95  1.1  haad     return 9
     96  1.1  haad   if(month == "Nov")
     97  1.1  haad     return 10
     98  1.1  haad   if(month == "Dec")
     99  1.1  haad     return 11
    100  1.1  haad   return -1
    101  1.1  haad }
    102  1.1  haad BEGIN {                            
    103  1.1  haad   FS = " "                         
    104  1.1  haad   latest=""
    105  1.1  haad   maxyear = 0
    106  1.1  haad   maxdate = 0
    107  1.1  haad   maxmonth = "Jan"
    108  1.1  haad   maxtime = "00:00:00"
    109  1.1  haad }
    110  1.1  haad {
    111  1.1  haad    # check year first
    112  1.1  haad    if (maxyear < $6) {
    113  1.1  haad       date = $2 " " $3 " " $4 " " $5 " " $6
    114  1.1  haad       file = $1
    115  1.1  haad       maxyear = $6
    116  1.1  haad       maxmonth = $3
    117  1.1  haad       maxdate = $4
    118  1.1  haad       maxtime = $5
    119  1.1  haad    }
    120  1.1  haad    else {
    121  1.1  haad       if (maxyear == $6) {
    122  1.1  haad         # then month if year is the same
    123  1.1  haad         if (cvt_month(maxmonth) < cvt_month($3)) {
    124  1.1  haad           date = $2 " " $3 " " $4 " " $5 " " $6
    125  1.1  haad           file = $1
    126  1.1  haad 	  maxmonth = $3
    127  1.1  haad 	  maxdate = $4
    128  1.1  haad 	  maxtime = $5
    129  1.1  haad         }
    130  1.1  haad         else {
    131  1.1  haad           if (cvt_month(maxmonth) == cvt_month($3)) {
    132  1.1  haad 	    #then date if month is the same
    133  1.1  haad             if (maxdate < $4) {
    134  1.1  haad               date = $2 " " $3 " " $4 " " $5 " " $6
    135  1.1  haad               file = $1
    136  1.1  haad 	      maxdate = $4
    137  1.1  haad 	      maxtime = $5
    138  1.1  haad 	    }
    139  1.1  haad 	    else {
    140  1.1  haad 	      if (maxdate == $4) {
    141  1.1  haad 	        # then time if date is the same
    142  1.1  haad 	        if (maxtime < $5) {
    143  1.1  haad 		  date = $2 " " $3 " " $4 " " $5 " " $6
    144  1.1  haad                   file = $1
    145  1.1  haad 		  maxtime = $5
    146  1.1  haad 		}
    147  1.1  haad               }
    148  1.1  haad 	    }
    149  1.1  haad 	  }
    150  1.1  haad         }
    151  1.1  haad       }
    152  1.1  haad    }
    153  1.1  haad }
    154  1.1  haad 
    155  1.1  haad END {
    156  1.1  haad    # strip leading "./" from filename
    157  1.1  haad    sub(/^\.\//, "", file)
    158  1.1  haad    print "The last file updated by CVS was:"
    159  1.1  haad    print file 
    160  1.1  haad    print "on"
    161  1.1  haad    print date " GMT"
    162  1.1  haad }'
    163  1.1  haad 
    164