home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume2 / mkshar < prev    next >
Internet Message Format  |  1991-08-07  |  5KB

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