source: trunk/base/src/package1.0/portpkg.tcl @ 16589

Last change on this file since 16589 was 13738, checked in by pguyot (Paul Guyot), 15 years ago

Add a lot of missing $Id$

  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
1# et:ts=4
2# portpkg.tcl
3# $Id: portpkg.tcl,v 1.5 2005/08/27 00:07:27 pguyot Exp $
4#
5# Copyright (c) 2002 - 2003 Apple Computer, Inc.
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# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
17#    may be used to endorse or promote products derived from this software
18#    without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31#
32
33package provide portpkg 1.0
34package require portutil 1.0
35
36set com.apple.pkg [target_new com.apple.pkg pkg_main]
37target_runtype ${com.apple.pkg} always
38target_provides ${com.apple.pkg} pkg
39if {[option portarchivemode] == "yes"} {
40        target_requires ${com.apple.pkg} unarchive destroot
41} else {
42        target_requires ${com.apple.pkg} destroot
43}
44
45# define options
46options package.type package.destpath
47
48# Set defaults
49default package.destpath {${workpath}}
50
51set_ui_prefix
52
53proc pkg_main {args} {
54    global portname portversion portrevision package.type package.destpath UI_PREFIX
55
56    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating pkg for %s-%s"] ${portname} ${portversion}]"
57
58    return [package_pkg $portname $portversion $portrevision]
59}
60
61proc package_pkg {portname portversion portrevision} {
62    global UI_PREFIX portdbpath destpath workpath prefix portresourcepath description package.destpath long_description homepage portpath
63
64    set resourcepath ${workpath}/pkg_resources
65    # XXX: we need to support .lproj in resources.
66    set pkgpath ${package.destpath}/${portname}-${portversion}.pkg
67
68    if {[file readable $pkgpath] && ([file mtime ${pkgpath}] >= [file mtime ${portpath}/Portfile])} {
69        ui_msg "$UI_PREFIX [format [msgcat::mc "Package for %s-%s is up-to-date"] ${portname} ${portversion}]"
70        return 0
71    }
72       
73    system "mkdir -p -m 0755 ${pkgpath}/Contents/Resources"
74    write_PkgInfo ${pkgpath}/Contents/PkgInfo
75    write_info_plist ${pkgpath}/Contents/Info.plist $portname $portversion $portrevision
76    write_description_plist ${pkgpath}/Contents/Resources/Description.plist $portname $portversion $description
77    # long_description, description, or homepage may not exist
78    foreach variable {long_description description homepage} {
79        if {![info exists $variable]} {
80            set pkg_$variable ""
81        } else {
82            set pkg_$variable [set $variable]
83        }
84    }
85    write_welcome_html ${pkgpath}/Contents/Resources/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
86    file copy -force -- ${portresourcepath}/package/background.tiff ${pkgpath}/Contents/Resources/background.tiff
87    system "mkbom ${destpath} ${pkgpath}/Contents/Archive.bom"
88    system "cd ${destpath} && pax -x cpio -w -z . > ${pkgpath}/Contents/Archive.pax.gz"
89
90    write_sizes_file ${pkgpath}/Contents/Resources/Archive.sizes ${portname} ${portversion} ${pkgpath} ${destpath}
91
92    return 0
93}
94
95proc write_PkgInfo {infofile} {
96        set infofd [open ${infofile} w+]
97        puts $infofd "pmkrpkg1"
98        close $infofd
99}
100
101# XXX: deprecated
102proc write_info_file {infofile portname portversion description} {
103        set infofd [open ${infofile} w+]
104        puts $infofd "Title ${portname}
105Version ${portversion}
106Description ${description}
107DefaultLocation /
108DeleteWarning
109
110### Package Flags
111
112NeedsAuthorization YES
113Required NO
114Relocatable NO
115RequiresReboot NO
116UseUserMask YES
117OverwritePermissions NO
118InstallFat NO
119RootVolumeOnly NO"
120        close $infofd
121}
122
123proc xml_escape {s} {
124        regsub -all {&} $s {\&} s
125        regsub -all {<} $s {\&lt;} s
126        regsub -all {>} $s {\&gt;} s
127        return $s
128}
129
130proc write_info_plist {infofile portname portversion portrevision} {
131        set portname [xml_escape $portname]
132        set portversion [xml_escape $portversion]
133        set portrevision [xml_escape $portrevision]
134
135        set infofd [open ${infofile} w+]
136        puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
137<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
138<plist version="1.0">
139}
140        puts $infofd "<dict>
141        <key>CFBundleGetInfoString</key>
142        <string>${portname} ${portversion}</string>
143        <key>CFBundleIdentifier</key>
144        <string>org.opendarwin.darwinports.${portname}</string>
145        <key>CFBundleName</key>
146        <string>${portname}</string>
147        <key>CFBundleShortVersionString</key>
148        <string>${portversion}</string>
149        <key>IFMajorVersion</key>
150        <integer>${portrevision}</integer>
151        <key>IFMinorVersion</key>
152        <integer>0</integer>
153        <key>IFPkgFlagAllowBackRev</key>
154        <true/>
155        <key>IFPkgFlagAuthorizationAction</key>
156        <string>RootAuthorization</string>
157        <key>IFPkgFlagDefaultLocation</key>
158        <string>/</string>
159        <key>IFPkgFlagInstallFat</key>
160        <false/>
161        <key>IFPkgFlagIsRequired</key>
162        <false/>
163        <key>IFPkgFlagRelocatable</key>
164        <false/>
165        <key>IFPkgFlagRestartAction</key>
166        <string>NoRestart</string>
167        <key>IFPkgFlagRootVolumeOnly</key>
168        <false/>
169        <key>IFPkgFlagUpdateInstalledLanguages</key>
170        <false/>
171        <key>IFPkgFormatVersion</key>
172        <real>0.10000000149011612</real>
173</dict>
174</plist>"
175        close $infofd
176}
177
178proc write_description_plist {infofile portname portversion description} {
179        set portname [xml_escape $portname]
180        set portversion [xml_escape $portversion]
181        set description [xml_escape $description]
182       
183        set infofd [open ${infofile} w+]
184        puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
185<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
186<plist version="1.0">
187}
188        puts $infofd "<dict>
189        <key>IFPkgDescriptionDeleteWarning</key>
190        <string></string>
191        <key>IFPkgDescriptionDescription</key>
192        <string>${description}</string>
193        <key>IFPkgDescriptionTitle</key>
194        <string>${portname}</string>
195        <key>IFPkgDescriptionVersion</key>
196        <string>${portversion}</string>
197</dict>
198</plist>"
199        close $infofd
200}
201
202proc write_welcome_html {filename portname portversion long_description description homepage} {
203    set fd [open ${filename} w+]
204    if {$long_description == ""} {
205        set long_description $description
206    }
207
208        set portname [xml_escape $portname]
209        set portversion [xml_escape $portversion]
210        set long_description [xml_escape $long_description]
211        set description [xml_escape $description]
212        set homepage [xml_escape $homepage]
213       
214puts $fd "
215<html lang=\"en\">
216<head>
217        <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">
218        <title>Install ${portname}</title>
219</head>
220<body>
221<font face=\"Helvetica\"><b>Welcome to the ${portname} for Mac OS X Installer</b></font>
222<p>
223<font face=\"Helvetica\">${long_description}</font>
224<p>"
225
226    if {$homepage != ""} {
227        puts $fd "<font face=\"Helvetica\">${homepage}</font><p>"
228    }
229
230    puts $fd "<font face=\"Helvetica\">This installer guides you through the steps necessary to install ${portname} ${portversion} for Mac OS X. To get started, click Continue.</font>
231</body>
232</html>"
233
234    close $fd
235}
236
237proc write_sizes_file {sizesfile portname portversion pkgpath destpath} {
238   
239    if {[catch {set numFiles [exec lsbom -s ${pkgpath}/Contents/Archive.bom | wc -l]} result]} {
240        return -code error [format [msgcat::mc "Reading package bom failed: %s"] $result]
241    }
242    if {[catch {set compressedSize [expr [dirSize ${pkgpath}] / 1024]} result]} {
243        return -code error [format [msgcat::mc "Error determining compressed size: %s"] $result]
244    }
245    if {[catch {set installedSize [expr [dirSize ${destpath}] / 1024]} result]} {
246        return -code error [format [msgcat::mc "Error determining installed size: %s"] $result]
247    }
248    if {[catch {set infoSize [file size ${pkgpath}/Contents/Info.plist]} result]} {
249       return -code error [format [msgcat::mc "Error determining plist file size: %s"] $result]
250    }
251    if {[catch {set bomSize [file size ${pkgpath}/Contents/Archive.bom]} result]} {
252        return -code error [format [msgcat::mc "Error determining bom file size: %s"] $result]
253    }
254    incr installedSize $infoSize
255    incr installedSize $bomSize
256       
257    set fd [open ${sizesfile} w+]
258    puts $fd "NumFiles $numFiles
259InstalledSize $installedSize
260CompressedSize $compressedSize"
261    close $fd
262}
Note: See TracBrowser for help on using the repository browser.