home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume02 / mkshar < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  4.9 KB

  1. From mipos3!intelca!oliveb!ames!necntc!ncoast!allbery Sat Feb  6 16:04:23 PST 1988
  2. Article 282 of comp.sources.misc:
  3. Path: td2cad!mipos3!intelca!oliveb!ames!necntc!ncoast!allbery
  4. From: allbery@ncoast.UUCP (Brandon S. Allbery)
  5. Newsgroups: comp.sources.misc
  6. Subject: v02i029: a shar shell script
  7. Message-ID: <7154@ncoast.UUCP>
  8. Date: 30 Jan 88 21:46:22 GMT
  9. Sender: allbery@ncoast.UUCP
  10. Lines: 146
  11. Approved: allbery@ncoast.UUCP
  12. X-Archive: comp.sources.misc/8801/27
  13. Comp.sources.misc: Volume 2, Issue 29
  14. Submitted-By: The Moderator <allbery@ncoast.UUCP>
  15. Archive-Name: mkshar
  16.  
  17. Comp.sources.misc: Volume 2, Issue 29
  18. Submitted-By: The Moderator <allbery@ncoast.UUCP>
  19. Archive-Name: mkshar
  20.  
  21. I have received quite a number of postings recently that weren't in "shar"
  22. format.  Some of them (man pages, etc.) are quite at risk for being munched
  23. if they aren't shar'ed or if the shar program used doesn't insert a protective
  24. character in front of a line; also, it can be difficult to detect some
  25. transmission errors.
  26.  
  27. This is my "shar" program.  It can split shars into multiple files automatically
  28. based on size; it does overwrite protection; and it does a character count on
  29. the transmitted files to catch transmission errors.
  30.  
  31. Please -- use this or some other *good* shar program (K&P "bundle" won't do,
  32. not in these days of non-UNIX machines on the net) to pack your submissions
  33. to comp.sources.misc.  Or to any other source group, for that matter.  If you
  34. don't, you're the one who loses.
  35.  
  36. (This is shar'ed with mkshar, by the way.)
  37.  
  38. #--------------------------------CUT HERE-------------------------------------
  39. #! /bin/sh
  40. #
  41. # This is a shell archive.  Save this into a file, edit it
  42. # and delete all lines above this comment.  Then give this
  43. # file to sh by executing the command "sh file".  The files
  44. # will be extracted into the current directory owned by
  45. # you with default permissions.
  46. #
  47. # The files contained herein are:
  48. #
  49. # -rwxr-xr-x   1 allbery  System      2638 Jan 30 16:43 mkshar
  50. #
  51. echo 'x - mkshar'
  52. if test -f mkshar; then echo 'shar: not overwriting mkshar'; else
  53. sed 's/^X//' << '________This_Is_The_END________' > mkshar
  54. X: #! /bin/sh
  55. X#
  56. X# shar - make a "shell archive" for net.sources, etc.
  57. X#
  58. X
  59. XFILE=/tmp/shar$$
  60. XTFILE=/tmp/sharx$$
  61. Xhead=shar
  62. Xsize=0
  63. Xverbose=1
  64. X
  65. Xcat > "$TFILE" << '________This_Is_The_End________'
  66. X#--------------------------------CUT HERE-------------------------------------
  67. X#! /bin/sh
  68. X#
  69. X# This is a shell archive.  Save this into a file, edit it
  70. X# and delete all lines above this comment.  Then give this
  71. X# file to sh by executing the command "sh file".  The files
  72. X# will be extracted into the current directory owned by
  73. X# you with default permissions.
  74. X#
  75. X# The files contained herein are:
  76. X#
  77. X________This_Is_The_End________
  78. Xecho "#" > "$FILE"
  79. Xwhile [ "$#" -gt 0 ]; do
  80. X    case "$1" in
  81. X    -v)    verbose=0
  82. X        ;;
  83. X    -s)    size="$2"
  84. X        shift
  85. X        ;;
  86. X    -h)    head="$2"
  87. X        shift
  88. X        ;;
  89. X    *)    if [ ! -r "$1" ]; then
  90. X            echo "shar: can't read $1" >&2
  91. X        else
  92. X            files="$files $1"
  93. X        fi
  94. X    esac
  95. X    shift
  96. Xdone
  97. Xif [ "$files" = "" ]; then
  98. X    echo "usage: shar [-v] [-s size] [-h header] files..." >&2
  99. X    exit 1
  100. Xfi
  101. Xif [ "$size" -ne 0 ]; then
  102. X    count=1
  103. Xelse
  104. X    count=
  105. Xfi
  106. Xif [ "$verbose" = 1 ]; then
  107. X    echo "o - $head$count"
  108. Xfi
  109. Xfor file in $files; do
  110. X    f=`basename $file`
  111. X    case "$verbose" in
  112. X    1)    echo "a - $f"
  113. X    esac
  114. X    if [ "$size" -ne 0 ]; then
  115. X        set -- `ls -l "$FILE"`
  116. X        csize=$5
  117. X        set -- `ls -l "$file"`
  118. X        if [ "$size" -lt `expr "$csize" + $5` ]; then
  119. X            echo "exit 0" >> "$FILE"
  120. X            cat "$TFILE" "$FILE" > "$head$count"
  121. X            cat > "$TFILE" << '________This_Is_The_End________'
  122. X#--------------------------------CUT HERE-------------------------------------
  123. X#! /bin/sh
  124. X#
  125. X# This is a shell archive.  Save this into a file, edit it
  126. X# and delete all lines above this comment.  Then give this
  127. X# file to sh by executing the command "sh file".  The files
  128. X# will be extracted into the current directory owned by
  129. X# you with default permissions.
  130. X#
  131. X# The files contained herein are:
  132. X#
  133. X________This_Is_The_End________
  134. X            echo "#" > "$FILE"
  135. X            count=`expr $count + 1`
  136. X            if [ "$verbose" = 1 ]; then
  137. X                echo "o - $head$count"
  138. X            fi
  139. X        fi
  140. X    fi
  141. X    echo '# \c' >> "$TFILE"
  142. X    ls -l "$file" >> "$TFILE"
  143. X    wcl=`wc -l < $f | sed 's/^  *//'`
  144. X    echo "echo 'x - $f'" >> "$FILE"
  145. X    echo "if test -f $f; then echo 'shar: not overwriting $f'; else" >> "$FILE"
  146. X    echo "sed 's/^X//' << '________This_Is_The_END________' > $f" >> "$FILE"
  147. X    sed 's/^/X/' < "$file" >> "$FILE"
  148. X    echo '________This_Is_The_END________' >> "$FILE"
  149. X    echo 'if test `wc -l < '"$f"'` -ne '"$wcl"'; then' >> "$FILE"
  150. X    echo "    echo 'shar: $f was damaged during transit (should have been $wcl bytes)'" >> "$FILE"
  151. X    echo "fi" >> "$FILE"
  152. X    echo "fi        ; : end of overwriting check" >> "$FILE"
  153. Xdone
  154. Xecho "exit 0" >> "$FILE"
  155. Xcat "$TFILE" "$FILE" > "$head$count"
  156. Xrm "$FILE" "$TFILE"
  157. ________This_Is_The_END________
  158. if test `wc -l < mkshar` -ne 103; then
  159.     echo 'shar: mkshar was damaged during transit (should have been 103 bytes)'
  160. fi
  161. fi        ; : end of overwriting check
  162. exit 0
  163.  
  164.  
  165.