source: trunk/base/src/package1.0/portdmg.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: 4.2 KB
Line 
1# et:ts=4
2# portdmg.tcl
3# $Id: portdmg.tcl,v 1.4 2005/08/27 00:07:27 pguyot Exp $
4#
5# Copyright (c) 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 portdmg 1.0
34package require portutil 1.0
35
36set com.apple.dmg [target_new com.apple.dmg dmg_main]
37target_runtype ${com.apple.dmg} always
38target_provides ${com.apple.dmg} dmg
39target_requires ${com.apple.dmg} pkg
40
41set_ui_prefix
42
43proc dmg_main {args} {
44    global portname portversion portrevision package.destpath UI_PREFIX
45   
46    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating disk image for %s-%s"] ${portname} ${portversion}]"
47   
48    return [package_dmg $portname $portversion $portrevision]
49}
50
51proc package_dmg {portname portversion portrevision} {
52    global UI_PREFIX package.destpath portpath
53   
54    if {[expr (${portrevision} > 0)]} {
55        set imagename "${portname}-${portversion}-${portrevision}"
56    } else {
57        set imagename "${portname}-${portversion}"
58    }
59   
60    set tmp_image ${package.destpath}/${imagename}.tmp.dmg
61    set final_image ${package.destpath}/${imagename}.dmg
62    set pkgpath ${package.destpath}/${portname}-${portversion}.pkg
63   
64    if {[file readable $final_image] && ([file mtime ${final_image}] >= [file mtime ${portpath}/Portfile])} {
65        ui_msg "$UI_PREFIX [format [msgcat::mc "Disk Image for %s-%s is up-to-date"] ${portname} ${portversion}]"
66        return 0
67    }
68   
69    # size for .dmg
70    set size [dirSize ${pkgpath}]
71    if {[expr ($size < 4194304)]} {
72        # there is a minimum of 8292 512 blocks in a dmg
73        set blocks 8292
74    } else {
75        # this should later be replaced with hdiutil create -srcfolder
76        set blocks [expr ($size/512) + ((($size/512)*3)/100)]
77    }
78   
79    if {[system "hdiutil create -quiet -fs HFS+ -volname ${imagename} -size ${blocks}b ${tmp_image}"] != ""} {
80        return -code error [format [msgcat::mc "Failed to create temporary image: %s"] ${imagename}]
81    }
82    if {[catch {set devicename [exec hdid ${tmp_image} | grep "s2" | awk "{ print \$1 }"]} error]} {
83        return -code error [format [msgcat::mc "Failed to attach temporary image: %s"] ${error}]
84    }
85    set mount_point [exec mount | grep "${devicename}"]
86    regexp {(\/Volumes/[A-Za-z0-9\-\_\s].+)\s\(} $mount_point code mount_point
87    system "ditto -rsrcFork ${pkgpath} '${mount_point}/${portname}-${portversion}.pkg'"
88    system "hdiutil detach ${devicename} -quiet"
89    if {[system "hdiutil convert ${tmp_image} -format UDCO -o ${final_image} -quiet"] != ""} {
90        return -code error [format [msgcat::mc "Failed to convert to final image: %s"] ${final_image}]
91    }
92    if {[system "hdiutil internet-enable -quiet -yes ${final_image}"] != ""} {
93        return -code error [format [msgcat::mc "Failed to internet-enable: %s"] ${final_image}]
94    }
95    system "rm -f ${tmp_image}"
96   
97    return 0
98}
Note: See TracBrowser for help on using the repository browser.