1 | : Use /bin/sh |
---|
2 | # |
---|
3 | # $Id: makeshar,v 1.1.1.1 1997-09-03 21:08:09 ghudson Exp $ |
---|
4 | # |
---|
5 | # Copyright 1993, Geoff Kuenning, Granada Hills, CA |
---|
6 | # All rights reserved. |
---|
7 | # |
---|
8 | # Redistribution and use in source and binary forms, with or without |
---|
9 | # modification, are permitted provided that the following conditions |
---|
10 | # are met: |
---|
11 | # |
---|
12 | # 1. Redistributions of source code must retain the above copyright |
---|
13 | # notice, this list of conditions and the following disclaimer. |
---|
14 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
15 | # notice, this list of conditions and the following disclaimer in the |
---|
16 | # documentation and/or other materials provided with the distribution. |
---|
17 | # 3. All modifications to the source code must be clearly marked as |
---|
18 | # such. Binary redistributions based on modified source code |
---|
19 | # must be clearly marked as modified versions in the documentation |
---|
20 | # and/or other materials provided with the distribution. |
---|
21 | # 4. All advertising materials mentioning features or use of this software |
---|
22 | # must display the following acknowledgment: |
---|
23 | # This product includes software developed by Geoff Kuenning and |
---|
24 | # other unpaid contributors. |
---|
25 | # 5. The name of Geoff Kuenning may not be used to endorse or promote |
---|
26 | # products derived from this software without specific prior |
---|
27 | # written permission. |
---|
28 | # |
---|
29 | # THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND |
---|
30 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
31 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
32 | # ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE |
---|
33 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
34 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
35 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
36 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
37 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
38 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
39 | # SUCH DAMAGE. |
---|
40 | # |
---|
41 | # Make a shar file, keeping file sizes below a maximum, but as large as |
---|
42 | # possible. The output files are put in file01.shar through filenn.shar, |
---|
43 | # where "file" is the output base name (default "prog"). |
---|
44 | # |
---|
45 | # If one of the output files is named "README", it is placed first in the |
---|
46 | # first shar file. |
---|
47 | # |
---|
48 | # Usage: |
---|
49 | # |
---|
50 | # makeshar [-f n] [-n] [-m max-size] [-o output-base ] [shar-switches] file-list |
---|
51 | # |
---|
52 | # $Log: not supported by cvs2svn $ |
---|
53 | # Revision 1.7 1994/01/25 07:11:57 geoff |
---|
54 | # Get rid of all old RCS log lines in preparation for the 3.1 release. |
---|
55 | # |
---|
56 | # |
---|
57 | SHAR_SW= |
---|
58 | MAXSIZE=60000 |
---|
59 | OUTPUT_BASE=prog |
---|
60 | NUM_SHARS=no |
---|
61 | FROM=1 |
---|
62 | TMP=${TMPDIR:-/tmp}/ms$$ |
---|
63 | |
---|
64 | while [ $# -gt 0 ] |
---|
65 | do |
---|
66 | case "$1" in |
---|
67 | -f) |
---|
68 | FROM=$2 |
---|
69 | shift; shift |
---|
70 | ;; |
---|
71 | -m) |
---|
72 | MAXSIZE=$2 |
---|
73 | shift; shift |
---|
74 | ;; |
---|
75 | -n) |
---|
76 | NUM_SHARS=yes |
---|
77 | shift |
---|
78 | ;; |
---|
79 | -o) |
---|
80 | OUTPUT_BASE="$2" |
---|
81 | shift; shift |
---|
82 | ;; |
---|
83 | -*) |
---|
84 | SHAR_SW="$SHAR_SW $1" |
---|
85 | shift |
---|
86 | ;; |
---|
87 | *) |
---|
88 | break |
---|
89 | ;; |
---|
90 | esac |
---|
91 | done |
---|
92 | trap "/bin/rm -f ${TMP}; exit 1" 1 2 15 |
---|
93 | trap "/bin/rm -f ${TMP}; exit 0" 13 |
---|
94 | sed -e "s;OUTPUT_BASE;$OUTPUT_BASE;" -e "s;SHAR_SW;$SHAR_SW;" \ |
---|
95 | -e "s;FROM;$FROM;" \ |
---|
96 | -e "s;MAXSIZE;$MAXSIZE;" > ${TMP} << 'EOF_AWK_SCRIPT' |
---|
97 | BEGIN { nfiles = 0 } |
---|
98 | { |
---|
99 | if ($3 == "total") |
---|
100 | next |
---|
101 | # Shar adds one extra character per line |
---|
102 | size[nfiles] = $1 + $2 |
---|
103 | files[nfiles] = $3 |
---|
104 | nfiles++ |
---|
105 | } |
---|
106 | END \ |
---|
107 | { |
---|
108 | outbase = "OUTPUT_BASE" |
---|
109 | sharcount = FROM |
---|
110 | for (filesdone = 0; filesdone < nfiles; sharcount++) |
---|
111 | { |
---|
112 | printf ("%s", "isharSHAR_SW") |
---|
113 | totsize = 0 |
---|
114 | for (i = 0; filesdone == 0 && i < nfiles; i++) |
---|
115 | { |
---|
116 | if (files[i] == "README") |
---|
117 | { |
---|
118 | filesdone++ |
---|
119 | totsize += size[i] |
---|
120 | printf (" %s", files[i]) |
---|
121 | files[i] = "" |
---|
122 | size[i] = 0 |
---|
123 | } |
---|
124 | } |
---|
125 | for (i = 0; totsize < MAXSIZE && i < nfiles; i++) |
---|
126 | { |
---|
127 | if (files[i] != "" \ |
---|
128 | && (totsize == 0 || size[i] < MAXSIZE - totsize)) |
---|
129 | { |
---|
130 | filesdone++ |
---|
131 | totsize += size[i] |
---|
132 | printf (" %s", files[i]) |
---|
133 | files[i] = "" |
---|
134 | size[i] = 0 |
---|
135 | } |
---|
136 | } |
---|
137 | printf (" > %s%2.2d.shar\n", outbase, sharcount) |
---|
138 | } |
---|
139 | print "echo", sharcount - 1 |
---|
140 | } |
---|
141 | EOF_AWK_SCRIPT |
---|
142 | nshars=`wc -lc "$@" \ |
---|
143 | | sort -rn \ |
---|
144 | | awk -F ${TMP} \ |
---|
145 | | sh` |
---|
146 | if [ $NUM_SHARS = yes ] |
---|
147 | then |
---|
148 | echo $nshars |
---|
149 | else |
---|
150 | echo $nshars shar files: |
---|
151 | ls -l $OUTPUT_BASE??.shar |
---|
152 | fi |
---|
153 | |
---|
154 | /bin/rm -f ${TMP} |
---|