Advertisement
Guest User

cic - "ci with checksum"

a guest
Sep 18th, 2010
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.59 KB | None | 0 0
  1. ######################################################
  2. #! /bin/bash
  3. #
  4. # cic -  "ci with checksum"
  5. #
  6. # cic file_name "revision log"
  7. # Sha1 checksum gets prepended before optional log message, $2
  8. # File_name get expanded by $1
  9. # Any other option to ci could be appended, like -l
  10. #
  11. # Use only after the initial commit
  12. #
  13.  
  14.  
  15. # The filename needs to be quoted in the following way,
  16. # Or else ci -m $1 will fail, due to wrong escaping.
  17. # Taken from Nautilus File Manager Scripts FAQ
  18. # http://g-scripts.sourceforge.net/faq.php
  19.  
  20. # file[spaces]name in $1 gets properly quoted here, in $quoted
  21. quoted=$(echo -e "$1" | awk 'BEGIN {
  22. FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
  23.  
  24. # Get file's checksum
  25. chksm=`sha1deep -q "$1"`
  26.  
  27. # Check-in file, prepending checksum to log message
  28. # and temporarily store ci message
  29. eval "ci -m'$chksm- $2'" $quoted &> RCS/rev.tmp
  30.  
  31. cd RCS
  32.  
  33. # Get revision from ci message; get rid of tmp file
  34.  
  35. # One just has to love awk!
  36. #rvsn=`awk '(/revision/) {print $2}' rev.tmp`
  37. rvsn=`awk '(/revision/) {print substr($3,1,3)}' rev.tmp`
  38. rm rev.tmp
  39.  
  40. # co revision (unlocked)
  41. co -r$rvsn "$1"
  42.  
  43. # Rename checkout as revision; -f because file is unlocked
  44. mv -f "$1" "$1".$rvsn
  45.  
  46. # Write revision's checksum to disk as well
  47. sha1deep -q "$1".$rvsn > "$1".$rvsn.sha1
  48.  
  49. # un-unixesque trivial message, just to check
  50. # Delete when sure everything is hunky-dory
  51. echo Revision $rvsn of file "$1" has been checked-in with:
  52. echo Log msg: "$2"
  53. echo Checksum: $chksm
  54. echo The revision is also available as RCS/"$1".$rvsn
  55.  
  56. ######################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement