home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d811 / bsh.lha / bsh / shar < prev    next >
Text File  |  1993-02-14  |  4KB  |  159 lines

  1. # shar - group files into distribution package.  Shar creates an archive
  2. # which can be unpacked on an Amiga using bsh or on a **IX system using
  3. # the Bourne shell.  To use the -c option, you must have wc and test
  4. # somewhere in your path; to use the -p option, you must have sed in
  5. # your path; the -o option requires that you have test in your path
  6. # when unpacking only.  Note that this script will probably not work
  7. # well with file names containing tabs or spaces; this can easily be
  8. # fixed by quoting "$file" everywhere, but it remains problematical
  9. # whether the receiving system will accept such file names.  Shar can
  10. # also be used to unpack archives by specifying the -u option.  This
  11. # is not fool-proof; some shell-archives have **IX or VMS file-system
  12. # specific constructs which may not work on an Amiga.  Shell-archives
  13. # containing AWK scripts will probably not work at all.  Shar is
  14. # provided as is; no warranty is either expressed or implied as to its
  15. # fitness for any purpose.  Use at your own risk, blah, blah, etc.
  16. if #argv < 2
  17.     label usage
  18.     echo >&2 "usage: shar [-p prefix] [-d delim] [-cov] [>foo.sh] list of files"
  19.     echo >&2 "\t-c add check for correct size to archive"
  20.     echo >&2 "\t-c override overwrite check when unpacking"
  21.     echo >&2 "\t-o check for existing file"
  22.     echo >&2 "\t-v be verbose when unpacking archive"
  23.     echo >&2 "    to unpack, type:"
  24.     echo >&2 " % source foo.sh"
  25.     echo >&2 "  or:
  26.     echo >&2 " % shar -u foo.sh"
  27.     echo >&2 "\tor just type:"
  28.     echo >&2 " % foo"
  29.     echo >&2 "\tto unpack on a **IX system:"
  30.     echo >&2 " $ sh foo.sh"
  31.     return 0
  32. endif
  33. local file j=1 delim="SHAR_EOF" prefix=0 count=0
  34. local overwrite=0 verbose=0 len unpack=0
  35.  
  36. # process arguments
  37. while j < #argv
  38.     if left(argv[j], 1) != '-'
  39.     break
  40.     endif
  41.     if substr(argv[j], 2, 1) == 'p' && j+1 < #argv
  42.     prefix = argv[j+1], j+=2
  43.     continue
  44.     elseif substr(argv[j], 2, 1) == 'd' && j+1 < #argv
  45.     delim = argv[j+1], j+=2
  46.     continue
  47.     elseif substr(argv[j], 2, 1) == 'c'
  48.     count++
  49.     elseif substr(argv[j], 2, 1) == 'o'
  50.     overwrite++
  51.     elseif substr(argv[j], 2, 1) == 'v'
  52.     verbose++
  53.     elseif substr(argv[j], 2, 1) == 'u'
  54.     unpack++
  55.     if j+1 < #argv
  56.         file=argv[j+1]
  57.     else
  58.         file=0
  59.     endif
  60.     else
  61.     goto usage
  62.     endif
  63.     if (len = strlen(argv[j])) > 2
  64.     argv[j] = cat("-", right(argv[j], len - 2))
  65.     else
  66.     j++
  67.     endif
  68. endwhile
  69. if unpack
  70.     # unpack archives
  71.     local flvl vrbs=?_verbose nclbr=?_noclobber str1=""
  72.     onerr goto errxit
  73.     onintr goto errxit
  74.     alias export abort
  75.     set flvl `failat` # obtain current fail level so we can restore it later
  76.     if flvl[2] < 20
  77.     failat 20
  78.     endif
  79.     # remember current setting of verbose, noclobber flags
  80.     if count
  81.     unset _noclobber
  82.     str1="-c"
  83.     endif
  84.     if verbose
  85.     set _verbose 1
  86.     endif
  87.     if file
  88.     source $file $str1
  89.     else
  90.     bsh <&0
  91.     endif
  92.     label errxit
  93.     onintr;onerr
  94.     if vrbs==0; unset _verbose; endif
  95.     if nclbr!=0; set _noclobber 1; endif
  96.     failat $flvl[2]
  97.     unalias export
  98.     return
  99. endif
  100.  
  101. # it is now known to be a packing operation
  102. if j>=#argv
  103.     goto usage
  104. endif
  105. echo "#\tThis is a shell archive."
  106. echo "#\tRemove everything above and including the cut line."
  107. echo "#\tThen run the rest of the file through bsh."
  108. echo "#----cut here-----cut here-----cut here-----cut here----#"
  109. echo "#!/bin/sh"
  110. echo "# shar: Shell Archiver"
  111. echo "#\tRun the following text through bsh to create:"
  112. foreach file ( $argv[$j-*] )
  113.     if -f "$file"        # Don't include non-files in the manifest.
  114.     echo "#\t$file"
  115.     endif
  116. end
  117. echo "# This archive created: `date`"
  118. if $?NAME
  119.     if $?ORGANIZATION
  120.     echo "# By:\t$NAME  ($ORGANIZATION)"
  121.     else
  122.     echo "# By:\t$NAME"
  123.     endif
  124. endif
  125. foreach file ( $argv[$j-*] )
  126.     if -f "$file"
  127.     if verbose
  128.         echo >&2 shar: packing $file
  129.     endif
  130.     if overwrite
  131.         echo "if test -f $file -a \"\$1\" != \"-c\""
  132.         echo "then"
  133.         echo "    echo shar: Will not over-write existing file $file"
  134.         echo "else"
  135.     endif
  136.     echo "echo shar: extracting $file"
  137.     if prefix
  138.         echo "sed 's/^$prefix//' >$file << \\$delim"
  139.         sed s/\^/$prefix/ $file
  140.     else
  141.         echo "cat >$file << \\$delim"
  142.         cat $file
  143.     endif
  144.     echo "$delim"
  145.     if count
  146.         len=-s "$file"
  147.         echo "if test $len -ne \`wc -c $file\`; then"
  148.         echo "    echo shar: $file unpacked with wrong size!"
  149.         echo "fi"
  150.     endif
  151.     if overwrite
  152.         echo "# end of overwrite check"
  153.         echo "fi"
  154.     endif
  155.     endif
  156. end
  157. echo "#\tEnd of shell archive"
  158. echo "exit 0"
  159.