]>
Commit | Line | Data |
---|---|---|
1 | #! /bin/csh -ef | |
2 | # | |
3 | # original script by Chris Roberts (The OS X Package Manager) | |
4 | # slightly modified by Frank Vercruesse (mainly fixed quoting issues) | |
5 | ||
6 | set prog = `/usr/bin/basename $0` | |
7 | set usage = "Usage: $prog [-f] root-dir info-file [tiff-file] [-d dest-dir] [-r resource-dir] [-traditional | -gnutar]" | |
8 | set noglob | |
9 | ||
10 | if (-x /usr/bin/mkbom) then | |
11 | set mkbom=/usr/bin/mkbom | |
12 | set lsbom=/usr/bin/lsbom | |
13 | else | |
14 | set mkbom=/usr/etc/mkbom | |
15 | set lsbom=/usr/etc/lsbom | |
16 | endif | |
17 | ||
18 | if (-x /usr/bin/awk) then | |
19 | set awk=/usr/bin/awk | |
20 | else | |
21 | set awk=/bin/awk | |
22 | endif | |
23 | ||
24 | set gnutar=/usr/bin/gnutar | |
25 | set tar=/usr/bin/tar | |
26 | set pax=/bin/pax | |
27 | ||
28 | # gather parameters | |
29 | if ($#argv == 0) then | |
30 | echo $usage | |
31 | exit(1) | |
32 | endif | |
33 | ||
34 | while ( $#argv > 0 ) | |
35 | switch ( "$argv[1]" ) | |
36 | case -d: | |
37 | if ( $?destDir ) then | |
38 | echo ${prog}: dest-dir parameter already set to ${destDir}. | |
39 | echo $usage | |
40 | exit(1) | |
41 | else if ( $#argv < 2 ) then | |
42 | echo ${prog}: -d option requires destination directory. | |
43 | echo $usage | |
44 | exit(1) | |
45 | else | |
46 | set destDir = "$argv[2]" | |
47 | shift; shift | |
48 | breaksw | |
49 | endif | |
50 | case -f: | |
51 | if ( $?rootDir ) then | |
52 | echo ${prog}: root-dir parameter already set to ${rootDir}. | |
53 | echo $usage | |
54 | exit(1) | |
55 | else if ( $#argv < 2 ) then | |
56 | echo ${prog}: -f option requires package root directory. | |
57 | echo $usage | |
58 | exit(1) | |
59 | else | |
60 | set rootDir = "$argv[2]" | |
61 | set fflag | |
62 | shift; shift | |
63 | breaksw | |
64 | endif | |
65 | case -r: | |
66 | if ( $?resDir ) then | |
67 | echo ${prog}: resource-dir parameter already set to ${resDir}. | |
68 | echo $usage | |
69 | exit(1) | |
70 | else if ( $#argv < 2 ) then | |
71 | echo ${prog}: -r option requires package resource directory. | |
72 | echo $usage | |
73 | exit(1) | |
74 | else | |
75 | set resDir = "$argv[2]" | |
76 | shift; shift | |
77 | breaksw | |
78 | endif | |
79 | case -traditional: | |
80 | set usetar | |
81 | unset usegnutar | |
82 | unset usepax | |
83 | shift | |
84 | breaksw | |
85 | case -gnutar: | |
86 | set usegnutar | |
87 | unset usepax | |
88 | unset usetar | |
89 | shift | |
90 | breaksw | |
91 | case -B: | |
92 | # We got long file names, better use bigtar instead | |
93 | #set archiver = /NextAdmin/Installer.app/Resources/installer_bigtar | |
94 | #echo 2>&1 ${prog}: -B flag is longer relevant. | |
95 | shift | |
96 | breaksw | |
97 | case -*: | |
98 | echo ${prog}: Unknown option: $argv[1] | |
99 | echo $usage | |
100 | exit(1) | |
101 | case *.info: | |
102 | if ( $?info ) then | |
103 | echo ${prog}: info-file parameter already set to ${info}. | |
104 | echo $usage | |
105 | exit(1) | |
106 | else | |
107 | set info = "$argv[1]" | |
108 | shift | |
109 | breaksw | |
110 | endif | |
111 | case *.tiff: | |
112 | if ( $?tiff ) then | |
113 | echo ${prog}: tiff-file parameter already set to ${tiff}. | |
114 | echo $usage | |
115 | exit(1) | |
116 | else | |
117 | set tiff = "$argv[1]" | |
118 | shift | |
119 | breaksw | |
120 | endif | |
121 | default: | |
122 | if ( $?rootDir ) then | |
123 | echo ${prog}: unrecognized parameter: $argv[1] | |
124 | echo $usage | |
125 | exit(1) | |
126 | else | |
127 | set rootDir = "$argv[1]" | |
128 | shift | |
129 | breaksw | |
130 | endif | |
131 | endsw | |
132 | end | |
133 | ||
134 | # check for mandatory parameters | |
135 | if ( ! $?rootDir ) then | |
136 | echo ${prog}: missing root-dir parameter. | |
137 | echo $usage | |
138 | exit(1) | |
139 | else if ( ! $?info) then | |
140 | echo ${prog}: missing info-file parameter. | |
141 | echo $usage | |
142 | exit(1) | |
143 | endif | |
144 | ||
145 | # destDir gets default value if unset on command line | |
146 | if ( $?destDir ) then | |
147 | /bin/mkdir -p "$destDir" | |
148 | else | |
149 | set destDir = . | |
150 | endif | |
151 | ||
152 | # derive the root name for the package from the root name of the info file | |
153 | set root = `/usr/bin/basename $info .info` | |
154 | ||
155 | # create package directory | |
156 | set pkg = "${destDir}/${root}.pkg" | |
157 | echo Generating Installer package $pkg ... | |
158 | if ( -e "$pkg" ) /bin/rm -rf "$pkg" | |
159 | /bin/mkdir -p -m 755 "$pkg" | |
160 | /bin/mkdir -p -m 755 "$pkg/Contents" | |
161 | /bin/mkdir -p -m 755 "$pkg/Contents/Resources" | |
162 | /bin/mkdir -p -m 755 "$pkg/Contents/Resources/English.lproj/" | |
163 | echo -n "pmkrpkg1" >"$pkg/Contents/PkgInfo" | |
164 | chmod 755 "$pkg/Contents/PkgInfo" | |
165 | # (gnu)tar/pax and compress root directory to package archive | |
166 | echo -n " creating package archive ... " | |
167 | if ( $?fflag ) then | |
168 | set pkgTop = "${rootDir:t}" | |
169 | set parent = "${rootDir:h}" | |
170 | if ( "$parent" == "$pkgTop" ) set parent = "." | |
171 | else | |
172 | set parent = "$rootDir" | |
173 | set pkgTop = . | |
174 | endif | |
175 | if ( $?usetar ) then | |
176 | set pkgArchive = "$pkg/Contents/Resources/$root.tar.Z" | |
177 | (cd "$parent"; $tar -w "$pkgTop") | /usr/bin/tar -f -c > "$pkgArchive" | |
178 | else if ( $?usegnutar ) then | |
179 | set pkgArchive = "$pkg/Contents/Resources/$root.tar.gz" | |
180 | (cd "$parent"; $gnutar zcf "$pkgArchive" "$pkgTop") | |
181 | else | |
182 | set pkgArchive = "$pkg/Contents/Resources/$root.pax.gz" | |
183 | (cd "$parent"; $pax -w -z -x cpio "$pkgTop") > "$pkgArchive" | |
184 | endif | |
185 | /bin/chmod 755 "$pkgArchive" | |
186 | echo done. | |
187 | ||
188 | # copy info file to package | |
189 | set pkgInfo = "$pkg/Contents/Resources/English.lproj/$root.info" | |
190 | echo -n " copying ${info:t} ... " | |
191 | /bin/cp $info "$pkgInfo" | |
192 | /bin/chmod 755 "$pkgInfo" | |
193 | echo done. | |
194 | ||
195 | # copy tiff file to package | |
196 | if ( $?tiff ) then | |
197 | set pkgTiff = "$pkg/$root.tiff" | |
198 | echo -n " copying ${tiff:t} ... " | |
199 | /bin/cp $tiff "$pkgTiff" | |
200 | /bin/chmod 444 "$pkgTiff" | |
201 | echo done. | |
202 | endif | |
203 | ||
204 | # copy resources to package | |
205 | if ( $?resDir ) then | |
206 | echo -n " copying ${resDir:t} ... " | |
207 | ||
208 | # don't want to see push/pop output | |
209 | pushd "$resDir" > /dev/null | |
210 | # get lists of resources. We'll want to change | |
211 | # permissions on just these things later. | |
212 | set directoriesInResDir = `find . -type d` | |
213 | set filesInResDir = `find . -type f` | |
214 | popd > /dev/null | |
215 | ||
216 | # copy the resource directory contents into the package directory | |
217 | foreach resFile (`ls "$resDir"`) | |
218 | cp -r "$resDir/$resFile" "$pkg/Contents/Resources" | |
219 | end | |
220 | ||
221 | pushd "$pkg/Contents/Resources" > /dev/null | |
222 | # Change all directories to +r+x, except the package | |
223 | # directory itself | |
224 | foreach resFileItem ($directoriesInResDir) | |
225 | if ( "$resFileItem" != "." ) then | |
226 | chmod 755 $resFileItem | |
227 | endif | |
228 | end | |
229 | # change all flat files to read only | |
230 | foreach resFileItem ($filesInResDir) | |
231 | if ( "$resFileItem" != "./.DS_Store" ) then | |
232 | chmod 755 $resFileItem | |
233 | endif | |
234 | end | |
235 | popd > /dev/null | |
236 | ||
237 | echo done. | |
238 | endif | |
239 | ||
240 | # generate bom file | |
241 | set pkgBom = "$pkg/Contents/Resources/$root.bom" | |
242 | echo -n " generating bom file ... " | |
243 | /bin/rm -f "$pkgBom" | |
244 | if ( $?fflag ) then | |
245 | $mkbom "$parent" "$pkgBom" >& /dev/null | |
246 | else | |
247 | $mkbom "$rootDir" "$pkgBom" >& /dev/null | |
248 | endif | |
249 | /bin/chmod 444 "$pkgArchive" | |
250 | echo done. | |
251 | ||
252 | # generate sizes file | |
253 | set pkgSizes = "$pkg/Contents/Resources/$root.sizes" | |
254 | echo -n " generating sizes file ... " | |
255 | ||
256 | # compute number of files in package | |
257 | set numFiles = `$lsbom -s "$pkgBom" | /usr/bin/wc -l` | |
258 | ||
259 | # compute package size when compressed | |
260 | @ compressedSize = `/usr/bin/du -k -s "$pkg" | $awk '{print $1}'` | |
261 | @ compressedSize += 3 # add 1KB each for sizes, location, status files | |
262 | ||
263 | @ infoSize = `/bin/ls -s "$pkgInfo" | $awk '{print $1}'` | |
264 | @ bomSize = `/bin/ls -s "$pkgBom" | $awk '{print $1}'` | |
265 | if ( $?tiff ) then | |
266 | @ tiffSize = `/bin/ls -s "$pkgTiff" | $awk '{print $1}'` | |
267 | else | |
268 | @ tiffSize = 0 | |
269 | endif | |
270 | ||
271 | @ installedSize = `/usr/bin/du -k -s "$rootDir" | $awk '{print $1}'` | |
272 | @ installedSize += $infoSize + $bomSize + $tiffSize + 3 | |
273 | ||
274 | # echo size parameters to sizes file | |
275 | echo NumFiles $numFiles > "$pkgSizes" | |
276 | echo InstalledSize $installedSize >> "$pkgSizes" | |
277 | echo CompressedSize $compressedSize >> "$pkgSizes" | |
278 | echo done. | |
279 | echo " ... finished generating $pkg." | |
280 | ||
281 | exit(0) | |
282 | ||
283 | # end package |