source: branches/gsoc13-tests/src/package1.0/portdmg.tcl @ 139170

Last change on this file since 139170 was 111323, checked in by marius@…, 7 years ago

Merge from trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2# portdmg.tcl
3# $Id: portdmg.tcl 111323 2013-09-18 23:11:02Z marius@macports.org $
4#
5# Copyright (c) 2007, 2009-2011  The MacPorts Project
6# Copyright (c) 2003, 2005 Apple Inc.
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
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. Neither the name of Apple Inc. nor the names of its contributors
18#    may be used to endorse or promote products derived from this software
19#    without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32#
33
34package provide portdmg 1.0
35package require portutil 1.0
36
37set org.macports.dmg [target_new org.macports.dmg portdmg::dmg_main]
38target_runtype ${org.macports.dmg} always
39target_provides ${org.macports.dmg} dmg
40target_requires ${org.macports.dmg} pkg
41
42namespace eval portdmg {
43}
44
45set_ui_prefix
46
47proc portdmg::dmg_main {args} {
48    global subport version revision package.destpath UI_PREFIX
49
50    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating disk image for %s-%s"] ${subport} ${version}]"
51
52    if {[getuid] == 0 && [geteuid] != 0} {
53                seteuid 0; setegid 0
54        }
55
56    return [package_dmg $subport $version $revision]
57}
58
59proc portdmg::package_dmg {portname portversion portrevision} {
60    global UI_PREFIX package.destpath portpath \
61           os.platform os.arch os.version os.major
62
63    if {[expr (${portrevision} > 0)]} {
64        set imagename "${portname}-${portversion}-${portrevision}"
65    } else {
66        set imagename "${portname}-${portversion}"
67    }
68
69    set tmp_image ${package.destpath}/${imagename}.tmp.dmg
70    set final_image ${package.destpath}/${imagename}.dmg
71    set pkgpath ${package.destpath}/${portname}-${portversion}.pkg
72
73    if {[file readable $final_image] && ([file mtime ${final_image}] >= [file mtime ${portpath}/Portfile])} {
74        ui_msg "$UI_PREFIX [format [msgcat::mc "Disk Image for %s version %s is up-to-date"] ${portname} ${portversion}]"
75        return 0
76    }
77
78    # partition for .dmg
79    if {${os.major} >= 9 && ${os.arch} == "i386"} {
80        # GUID_partition_scheme
81        set subdev 1
82    } else {
83        # Apple_partition_scheme (Apple_partition_map is at s1)
84        set subdev 2
85    }
86
87    if {![file isdirectory $pkgpath]} {
88        file mkdir ${package.destpath}/${imagename}
89        file copy $pkgpath ${package.destpath}/${imagename}
90        set pkgpath ${package.destpath}/${imagename}
91    }
92
93    set hdiutil [findBinary hdiutil $portutil::autoconf::hdiutil_path]
94    if {[system "$hdiutil create -quiet -fs HFS+ -volname ${imagename} -srcfolder ${pkgpath} ${tmp_image}"] != ""} {
95        return -code error [format [msgcat::mc "Failed to create temporary image: %s"] ${imagename}]
96    }
97    if {[system "$hdiutil convert ${tmp_image} -format UDCO -o ${final_image} -quiet"] != ""} {
98        return -code error [format [msgcat::mc "Failed to convert to final image: %s"] ${final_image}]
99    }
100    if {[system "$hdiutil internet-enable -quiet -yes ${final_image}"] != ""} {
101        return -code error [format [msgcat::mc "Failed to internet-enable: %s"] ${final_image}]
102    }
103    file delete -force "${tmp_image}"
104
105    return 0
106}
Note: See TracBrowser for help on using the repository browser.