home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / narc / assemble.csh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1989-01-17  |  6KB  |  287 lines

  1. #!    /bin/csh    -f
  2.  
  3. # Archive management scripts.  Use in conjunction with narc
  4.  
  5. # Geoffrey Leach
  6. # LatiCorp Inc.    
  7. # {att,bellcore,sun,ames,pyramid}!pacbell!laticorp!geoff
  8.  
  9. # assemble    Assemble a group of files into an archive directory
  10. # archive    Put and archive directory in its place
  11. # retrieve    Get an archive directory into the cwd
  12.  
  13. # This shell script implements an archive management facility.  The
  14. # idea is that you have a archive whose path is in the environment
  15. # variable ARCHIVE.  The directories here are your archive.  
  16. # Files in an archive directory are compressed tar files if they were
  17. # put there by this archive.  If they were put there by narc, then they
  18. # are plain text files, which you will assemble into compressed tar, depending
  19. # on how they got there.  Moderated archives are handled in a way that 
  20. # lets you refer to a series of postings with shorthand.  BTW, moderated
  21. # groups are assumed to be organized by volume in your archive.  Retrieve
  22. # just helps you get a particular archive file into your cwd.
  23.  
  24. # Usage - options apply as stated in the usage messages
  25. #
  26. #    -a    Specify ARCDIR.  Forces ARCVOL to ""
  27. #    -e    Extract.  Overrides shorthand for moderated groups
  28. #    -n    Specify archive file.  $1 defaults
  29. #    -s    "Short" assemble; just get the files
  30. #    -v    Specify ARCVOL
  31.  
  32.  
  33. # Environment variable usage 
  34.  
  35. #    ARCHIVE    base directory of archive
  36. #    ARCPATH    directory name
  37. #    ARCVOL    subdirectory name for moderated groups
  38.  
  39. # Commands that are used by this script that you might not have
  40.  
  41. #    unshar
  42.  
  43. set MYNAME   = $0
  44. set MYNAME   = $MYNAME:t
  45.  
  46. # usage
  47. if ( $#argv == 0 ) then
  48.     echo -n "Usage: $MYNAME [-a archive [-v volume]] "
  49.     switch ( $MYNAME )
  50.     case "assemble":
  51.         echo "[-s] [-e name] [-n archive-name] base-issue [number-of-issues]"
  52.         exit
  53.     case "archive":
  54.         echo "file"
  55.         exit
  56.     case "retrieve":
  57.         echo "file"
  58.         exit
  59.     default:
  60.         echo ""
  61.         exit
  62.     endsw
  63. endif
  64.  
  65. # Check for environment usage
  66. if ( ! $?ARCHIVE ) set ARCHIVE
  67. if ( ! $?ARCDIR )  set ARCDIR
  68. if ( ! $?ARCVOL )  set ARCVOL
  69.  
  70. # Check for switches
  71. set SWSCAN
  72. while ( $?SWSCAN )
  73.     switch ( $1 )
  74.     case -a:
  75.         set ARCDIR = $2
  76.     set ARCVOL = ""
  77.     shift
  78.     shift
  79.     breaksw
  80.     case -e:
  81.     if ( ! $?EXTRACT ) then 
  82.         set EXTRACT
  83.     else
  84.         unset EXTRACT
  85.     endif
  86.     shift
  87.     breaksw
  88.     case -n:
  89.     set ARCFILE = $2
  90.     shift
  91.     shift
  92.     breaksw
  93.     case -s:
  94.     set SHORT
  95.     shift
  96.     breaksw
  97.     case -v:
  98.     if ( $2 <= 9 ) then 
  99.         set ARCVOL = v0$2
  100.     else
  101.         set ARCVOL = v$2
  102.     endif
  103.     shift
  104.     shift
  105.     breaksw
  106.     case -*:
  107.     echo "Unrecognized option $1"
  108.     exit
  109.     default:
  110.     unset SWSCAN
  111.     breaksw
  112.     endsw
  113. end
  114.  
  115. if ( $ARCDIR == "" ) then
  116.     echo -n "Archive directory? "
  117.     set ARCDIR = $<
  118. endif
  119.  
  120. if ( $ARCVOL == "" ) then
  121.     switch ( $ARCDIR )
  122.     case x:
  123.     case unix:
  124.     case misc:
  125.     case games:
  126.         echo -n "Archive volume? "
  127.         set ARCVOL = $<
  128.         if ( $ARCVOL <= 9 ) then
  129.         set ARCVOL = v0$ARCVOL
  130.         else
  131.         set ARCVOL = v$ARCVOL
  132.         endif
  133.         breaksw
  134.     default:
  135.         breaksw
  136.     endsw
  137. endif
  138. set PREFIX = ${ARCVOL}i
  139.  
  140. if ( $ARCVOL == "" ) then
  141.     set ARCPATH = $ARCHIVE/$ARCDIR
  142. else
  143.     set ARCPATH = $ARCHIVE/$ARCDIR/$ARCVOL
  144. endif
  145.  
  146. # Here is where we do the real work
  147. switch ( $MYNAME )
  148.     case assemble:
  149.  
  150.     # For moderated groups, we usually have the number of the first posting,
  151.     # and (optionally) the number of postings.  These
  152.     # are combined to give a sequence of file names.  Otherwise, we assume
  153.     # that the argument is the prefix of the file(s) to be retrieved.
  154.     # There may be more than one file with that name as prefix.
  155.     switch ( $ARCDIR )
  156.         case "x":
  157.         case "unix":
  158.         case "misc":
  159.         case "games":
  160.         if ( ! $?EXTRACT ) then
  161.             set MODERATED
  162.             set BASE = $1
  163.             if ( $#argv == 2 ) then
  164.             set COUNT = $2
  165.             else
  166.             set COUNT = 1
  167.             endif
  168.         endif
  169.         breaksw
  170.         default:
  171.         breaksw
  172.     endsw
  173.  
  174.     # Set up the directory structure for the archive.
  175.     # Conditional so that we can assemble into an existing directory.
  176.     # ARCF        is where we put the raw input for later deletion
  177.     # FILES        is the lis of original files, for later deletion
  178.     # HDRS        contains the .hdr files produced by unshar, so you can
  179.     #        find our later where all of this came from.
  180.     # PATCHES    is where you accumulate patch files.  I save these
  181.     #        so they can be un-applied later.  Useful if you are
  182.     #        applying unofficial patches to a maintained source.
  183.     if ( ! $?ARCFILE ) then
  184.         if ( $?MODERATED ) then
  185.         echo -n "Archive name? "
  186.         set ARCFILE = $<
  187.         else
  188.         set ARCFILE = $1
  189.         endif
  190.     endif
  191.     if ( ! -d $ARCFILE ) mkdir $ARCFILE
  192.     cd $ARCFILE
  193.     if ( ! -d HDRS ) mkdir HDRS
  194.     if ( ! -d ARCF ) mkdir ARCF
  195.     if ( ! -d PATCHES ) mkdir PATCHES
  196.  
  197.     if ( $?MODERATED ) then
  198.         while ( $COUNT )
  199.         if ( $BASE <  10 ) set BASE = 0$BASE
  200.         if ( $BASE < 100 ) set BASE = 0$BASE
  201.         set f = $ARCPATH/${PREFIX}${BASE}
  202.         if ( ! -e $f ) echo $f not found
  203.         chmod +w $f
  204.         cp $f .
  205.         echo $f >> FILES
  206.         unshar $f:t
  207.         mv $f:t ARCF
  208.         @ COUNT = $COUNT - 1
  209.         @ BASE = $BASE + 1
  210.         end
  211.     else
  212.         foreach f ( $ARCPATH/$1* )
  213.         chmod +w $f
  214.         cp $f .
  215.         echo $f >> FILES
  216.         # You may want to assemble pre-existing archives.  We handle
  217.         # Compressed files, which may also be tar or shar.
  218.         set f = $f:t
  219.         if ( $f:e == "Z" ) then
  220.             set f = $f:r
  221.             uncompress $f
  222.         endif
  223.         if ( $f:e == "tar" ) then
  224.             tar xvf $f
  225.             set f = $f:r
  226.         else
  227.             unshar $f:t
  228.         endif
  229.         mv $f:t ARCF
  230.         end
  231.     endif
  232.     mv *hdr HDRS
  233.  
  234.     if ( -e ark1isdone ) mv ark*isdone ARCF
  235.  
  236.     if ( $?SHORT ) exit
  237.  
  238.     # This maintains an archive of formatted documentation
  239.     roffit
  240.  
  241.     CheckManifest
  242.     ls -C
  243.     exit
  244.  
  245.     case archive:
  246.     if ( ! $?ARCFILE ) then
  247.         if ( $#argv != 1 ) then
  248.         echo -n "Archive name? "
  249.         set ARCFILE = $<
  250.         else
  251.         set ARCFILE = $1
  252.         endif
  253.     endif
  254.     if ( ! -d $ARCFILE ) then
  255.         echo archive: $ARCFILE not found
  256.         exit
  257.     endif
  258.     if ( -e $ARCFILE/FILES ) then
  259.         set F = ( `cat $ARCFILE/FILES` )
  260.         rm -r $ARCFILE/FILES
  261.     else
  262.         set F
  263.     endif
  264.     if ( ! -d $ARCPATH ) then
  265.         echo "$ARCPATH not found"
  266.         exit
  267.     endif
  268.     if ( -d $ARCFILE/ARCF ) rm -r $ARCFILE/ARCF
  269.     tar cvf $ARCPATH/$ARCFILE.tar $ARCFILE
  270.     if ( -e $ARCPATH/$ARCFILE.tar.Z ) rm -f $ARCPATH/$ARCFILE.tar.Z
  271.     compress $ARCPATH/$ARCFILE.tar
  272.     chmod -w $ARCPATH/$ARCFILE.tar.Z
  273.     rm -rf $ARCFILE $F
  274.     exit
  275.  
  276.     case retrieve:
  277.     set f = $ARCPATH/$1.tar.Z
  278.     if ( ! -e $f ) then
  279.         echo $f not found
  280.         exit
  281.     endif
  282.     zcat $f | tar xvf -
  283.     exit
  284.     default:
  285.     exit
  286. endsw
  287.