home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk1.iso / altsrc / articles / 11349 < prev    next >
Text File  |  1994-10-17  |  3KB  |  75 lines

  1. Newsgroups: alt.sources
  2. Path: wupost!gumby!newsxfer.itd.umich.edu!zip.eecs.umich.edu!yeshua.marcam.com!usc!math.ohio-state.edu!caen!hearst.acc.Virginia.EDU!murdoch!recycle.cebaf.gov!doolitt
  3. From: doolitt@recycle.cebaf.gov (Larry Doolittle)
  4. Subject: clonedir - clone a directory, using symbolic links
  5. Message-ID: <CxtMsE.tq@murdoch.acc.Virginia.EDU>
  6. Followup-To: alt.sources.d
  7. Summary: Helps to track site-specific changes to net.software
  8. Sender: usenet@murdoch.acc.Virginia.EDU
  9. Reply-To: doolittle@cebaf.gov
  10. Organization: CEBAF
  11. X-Newsreader: TIN [version 1.2 PL2]
  12. Date: Mon, 17 Oct 1994 14:26:38 GMT
  13. Lines: 60
  14.  
  15. Hi!
  16.      Perhaps other poeple are in the same situation as me -- trying to
  17. keep track of how I have adapted net.software to work on my machine.
  18. Here is one script I have used with some success to help me with that
  19. process.  I untar a package, clone the tree, and "chmod -R u-w" the
  20. original.  Now I can edit/patch/adapt the clone to my purposes, and
  21. it's always clear what I have done.  I can even reclaim disk space by
  22. deleting the original tree, without losing any information.  I just have
  23. to re-untar it if I want to work on the package again.
  24.  
  25.      If anyone wants to tell me a "better" way (in general, or specific
  26. improvements to the script below), let me know by e-mail or discussion.
  27. Followups set to alt.sources.d .
  28.  
  29.         - Larry Doolittle   doolittle@cebaf.gov
  30.  
  31. -- cut here --
  32. #!/bin/sh
  33. # clonedir - clone a directory, using symbolic links
  34. # Larry Doolittle   doolittle@cebaf.gov   October 16, 1994
  35. # Use and distribute freely
  36. # Tested and used in a GNU environment: i.e., bash, gnu find, gawk, etc.
  37. # YMMV.
  38.  
  39. temp=/tmp/.temp_clone_script
  40.  
  41. if [ $# -ne 2 ]; then
  42.     echo "usage: "`basename $0`" old_dir new_dir"
  43.     echo "       new_dir is created, and is a clone of old_dir"
  44.     exit
  45. fi
  46. if [ -e $2 ]; then
  47.     echo `basename $0`": $2 already exists, not overwritten"
  48.     exit
  49. fi
  50. if [ ! -d $1 ]; then
  51.     echo `basename $0`": $1 is not a directory"
  52.     exit
  53. fi
  54. if [ -e $temp ]; then
  55.     echo "Warning: overwriting stale $temp file"
  56. fi
  57.  
  58. mkdir $2
  59. (cd $1;find . -type d -mindepth 1 -exec mkdir ../$2/\{\} \;)
  60.  
  61. # Ugly, but it works.
  62. find $1 -type f -printf "%d %p\n" | awk  -v old_dir=$1 -v new_dir=$2 '{sub("^"old_dir"/","",$2);i=$1;h="";while (i--) h=h"../";print "ln -s "h old_dir"/"$2" "new_dir"/"$2}' >$temp
  63.  
  64. source $temp
  65. rm $temp
  66. -- cut here --
  67.  
  68. P.S. If that long line above got chopped by your news reader (or my posting
  69. software), here it is again in pieces:
  70.  
  71. find $1 -type f -printf "%d %p\n" | awk  -v old_dir=$1 -v new_dir=$2\
  72.  '{sub("^"old_dir"/","",$2);i=$1;h="";while (i--) h=h"../";print "ln\
  73.  -s "h old_dir"/"$2" "new_dir"/"$2}' >$temp
  74.  
  75.