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

Last change on this file since 32116 was 32116, checked in by jmpp@…, 13 years ago

More whitespace fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.1 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
2# portpkg.tcl
3# $Id: portpkg.tcl 32116 2007-12-17 06:14:28Z jmpp@macports.org $
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 org.macports.pkg [target_new org.macports.pkg pkg_main]
37target_runtype ${org.macports.pkg} always
38target_provides ${org.macports.pkg} pkg
39if {[option portarchivemode] == "yes"} {
40    target_requires ${org.macports.pkg} unarchive destroot
41} else {
42    target_requires ${org.macports.pkg} destroot
43}
44
45# define options
46options package.type package.destpath package.flat
47
48# Set defaults
49default package.destpath {${workpath}}
50default package.flat     false
51
52set_ui_prefix
53
54proc pkg_main {args} {
55    global portname portversion portrevision package.type package.destpath package.flat UI_PREFIX
56
57    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating pkg for %s-%s"] ${portname} ${portversion}]"
58
59    return [package_pkg $portname $portversion $portrevision]
60}
61
62proc package_pkg {portname portversion portrevision} {
63    global UI_PREFIX portdbpath destpath workpath prefix portresourcepath description package.destpath package.flat long_description homepage portpath
64    global os.version os.major
65
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    set packagemaker "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
74    if ([file exists "$packagemaker"]) {
75        set resourcepath ${workpath}/pkg_resources
76    } else {
77        set resourcepath "${pkgpath}/Contents/Resources"
78    }
79
80    set language "English"
81    system "mkdir -p -m 0755 ${resourcepath}/$language.lproj"
82       
83    # long_description, description, or homepage may not exist
84    foreach variable {long_description description homepage} {
85        if {![info exists $variable]} {
86            set pkg_$variable ""
87        } else {
88            set pkg_$variable [set $variable]
89        }
90    }
91    write_welcome_html ${resourcepath}/${language}.lproj/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
92    file copy -force -- ${portresourcepath}/package/background.tiff ${resourcepath}/${language}.lproj/background.tiff
93
94    foreach dir {etc var tmp} {
95        if ([file exists "${destpath}/$dir"]) {
96            # certain toplevel directories really are symlinks. leaving them as directories make pax lose the symlinks. that's bad.
97            system "mkdir -p ${destpath}/private/$dir; mv ${destpath}/$dir/* ${destpath}/private/$dir; rm -r \"${destpath}/$dir\""
98        }
99    }
100
101    if ([file exists "$packagemaker"]) {
102
103        ui_debug "Calling $packagemaker for $portname pkg"
104        if {${os.major} >= 9} {
105            if {${package.flat}} {
106                set pkgtarget "10.5"
107                set pkgresources ""
108                set infofile "${workpath}/PackageInfo"
109                write_package_info ${workpath}/PackageInfo $portname $portversion $portrevision
110            } else {
111                set pkgtarget "10.3"
112                set pkgresources " --resources ${resourcepath} --title \"$portname-$portversion\""
113                set infofile "${workpath}/Info.plist"
114                write_info_plist ${workpath}/Info.plist $portname $portversion $portrevision
115            }
116            system "PMResourceLocale=${language} $packagemaker -AppleLanguages \"(${language})\" --root ${destpath} --out ${pkgpath} ${pkgresources} --info $infofile --target $pkgtarget --domain system --id org.macports.$portname"
117        } else {
118            write_info_plist ${workpath}/Info.plist $portname $portversion $portrevision
119            write_description_plist ${workpath}/Description.plist $portname $portversion $description
120            system "$packagemaker -build -f ${destpath} -p ${pkgpath} -r ${resourcepath} -i ${workpath}/Info.plist -d ${workpath}/Description.plist"
121        }
122
123        file delete ${workpath}/Info.plist
124        file delete ${workpath}/PackageInfo
125        file delete ${workpath}/Description.plist
126        file delete -force ${workpath}/pkg_resources
127
128    } else {
129
130        write_PkgInfo ${pkgpath}/Contents/PkgInfo
131        write_info_plist ${pkgpath}/Contents/Info.plist $portname $portversion $portrevision
132
133        system "mkbom ${destpath} ${pkgpath}/Contents/Archive.bom"
134        system "cd ${destpath} && pax -x cpio -w -z . > ${pkgpath}/Contents/Archive.pax.gz"
135
136        write_description_plist ${resourcepath}/Description.plist $portname $portversion $description
137        write_sizes_file ${resourcepath}/Archive.sizes ${portname} ${portversion} ${pkgpath} ${destpath}
138
139    }
140
141    foreach dir {etc var tmp} {
142        if ([file exists "${destpath}/private/$dir"]) {
143            # restore any directories that were moved, to avoid confusing the rest of the ports system.
144            system "mv ${destpath}/private/$dir ${destpath}/$dir; rmdir ${destpath}/private 2>/dev/null"
145        }
146    }
147
148    return 0
149}
150
151proc write_PkgInfo {infofile} {
152    set infofd [open ${infofile} w+]
153    puts $infofd "pmkrpkg1"
154    close $infofd
155}
156
157# XXX: deprecated
158proc write_info_file {infofile portname portversion description} {
159    set infofd [open ${infofile} w+]
160    puts $infofd "Title ${portname}
161Version ${portversion}
162Description ${description}
163DefaultLocation /
164DeleteWarning
165
166### Package Flags
167
168NeedsAuthorization YES
169Required NO
170Relocatable NO
171RequiresReboot NO
172UseUserMask YES
173OverwritePermissions NO
174InstallFat NO
175RootVolumeOnly NO"
176    close $infofd
177}
178
179proc xml_escape {s} {
180    regsub -all {&} $s {\&} s
181    regsub -all {<} $s {\&lt;} s
182    regsub -all {>} $s {\&gt;} s
183    return $s
184}
185
186proc write_info_plist {infofile portname portversion portrevision} {
187    set portname [xml_escape $portname]
188    set portversion [xml_escape $portversion]
189    set portrevision [xml_escape $portrevision]
190
191    set infofd [open ${infofile} w+]
192    puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
193<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
194<plist version="1.0">
195    }
196    puts $infofd "<dict>
197    <key>CFBundleGetInfoString</key>
198    <string>${portname} ${portversion}</string>
199    <key>CFBundleIdentifier</key>
200    <string>org.macports.${portname}</string>
201    <key>CFBundleName</key>
202    <string>${portname}</string>
203    <key>CFBundleShortVersionString</key>
204    <string>${portversion}</string>
205    <key>IFMajorVersion</key>
206    <integer>${portrevision}</integer>
207    <key>IFMinorVersion</key>
208    <integer>0</integer>
209    <key>IFPkgFlagAllowBackRev</key>
210    <true/>
211    <key>IFPkgFlagAuthorizationAction</key>
212    <string>RootAuthorization</string>
213    <key>IFPkgFlagDefaultLocation</key>
214    <string>/</string>
215    <key>IFPkgFlagInstallFat</key>
216    <false/>
217    <key>IFPkgFlagIsRequired</key>
218    <false/>
219    <key>IFPkgFlagRelocatable</key>
220    <false/>
221    <key>IFPkgFlagRestartAction</key>
222    <string>NoRestart</string>
223    <key>IFPkgFlagRootVolumeOnly</key>
224    <false/>
225    <key>IFPkgFlagUpdateInstalledLanguages</key>
226    <false/>
227    <key>IFPkgFormatVersion</key>
228    <real>0.10000000149011612</real>
229</dict>
230</plist>"
231    close $infofd
232}
233
234proc write_description_plist {infofile portname portversion description} {
235    set portname [xml_escape $portname]
236    set portversion [xml_escape $portversion]
237    set description [xml_escape $description]
238
239    set infofd [open ${infofile} w+]
240    puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
241<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
242<plist version="1.0">
243    }
244    puts $infofd "<dict>
245    <key>IFPkgDescriptionDeleteWarning</key>
246    <string></string>
247    <key>IFPkgDescriptionDescription</key>
248    <string>${description}</string>
249    <key>IFPkgDescriptionTitle</key>
250    <string>${portname}</string>
251    <key>IFPkgDescriptionVersion</key>
252    <string>${portversion}</string>
253</dict>
254</plist>"
255    close $infofd
256}
257
258proc write_welcome_html {filename portname portversion long_description description homepage} {
259    set fd [open ${filename} w+]
260    if {$long_description == ""} {
261        set long_description $description
262    }
263
264    set portname [xml_escape $portname]
265    set portversion [xml_escape $portversion]
266    set long_description [xml_escape $long_description]
267    set description [xml_escape $description]
268    set homepage [xml_escape $homepage]
269       
270    puts $fd "
271<html lang=\"en\">
272<head>
273        <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">
274        <title>Install ${portname}</title>
275</head>
276<body>
277<font face=\"Helvetica\"><b>Welcome to the ${portname} for Mac OS X Installer</b></font>
278<p>
279<font face=\"Helvetica\">${long_description}</font>
280<p>"
281
282    if {$homepage != ""} {
283        puts $fd "<font face=\"Helvetica\"><a href=\"${homepage}\">${homepage}</a></font><p>"
284    }
285
286    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>
287</body>
288</html>"
289
290    close $fd
291}
292
293proc write_sizes_file {sizesfile portname portversion pkgpath destpath} {
294   
295    if {[catch {set numFiles [exec lsbom -s ${pkgpath}/Contents/Archive.bom | wc -l]} result]} {
296        return -code error [format [msgcat::mc "Reading package bom failed: %s"] $result]
297    }
298    if {[catch {set compressedSize [expr [dirSize ${pkgpath}] / 1024]} result]} {
299        return -code error [format [msgcat::mc "Error determining compressed size: %s"] $result]
300    }
301    if {[catch {set installedSize [expr [dirSize ${destpath}] / 1024]} result]} {
302        return -code error [format [msgcat::mc "Error determining installed size: %s"] $result]
303    }
304    if {[catch {set infoSize [file size ${pkgpath}/Contents/Info.plist]} result]} {
305       return -code error [format [msgcat::mc "Error determining plist file size: %s"] $result]
306    }
307    if {[catch {set bomSize [file size ${pkgpath}/Contents/Archive.bom]} result]} {
308        return -code error [format [msgcat::mc "Error determining bom file size: %s"] $result]
309    }
310    incr installedSize $infoSize
311    incr installedSize $bomSize
312       
313    set fd [open ${sizesfile} w+]
314    puts $fd "NumFiles $numFiles
315InstalledSize $installedSize
316CompressedSize $compressedSize"
317    close $fd
318}
319
320proc write_package_info {infofile portname portversion portrevision} {
321    set portname [xml_escape $portname]
322    set portversion [xml_escape $portversion]
323    set portrevision [xml_escape $portrevision]
324
325    set infofd [open ${infofile} w+]
326    puts $infofd "
327<pkg-info install-location=\"/\" relocatable=\"false\" auth=\"root\">
328</pkg-info>"
329    close $infofd
330}
Note: See TracBrowser for help on using the repository browser.