source: trunk/base/src/port1.0/portactivate.tcl @ 116820

Last change on this file since 116820 was 116820, checked in by cal@…, 6 years ago

portactivate: move startupitem.autoload after any post-activate hooks for the upcoming mpstats port

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 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# portactivate.tcl
3# $Id: portactivate.tcl 116820 2014-02-07 23:39:28Z cal@macports.org $
4#
5# Copyright (c) 2005, 2007, 2009-2011 The MacPorts Project
6# Copyright (c) 2004 Robert Shaw <rshaw@opendarwin.org>
7# Copyright (c) 2002 - 2003 Apple Inc.
8# All rights reserved.
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions
12# are met:
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18# 3. Neither the name of Apple Inc. nor the names of its contributors
19#    may be used to endorse or promote products derived from this software
20#    without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32# POSSIBILITY OF SUCH DAMAGE.
33#
34
35# the 'activate' target is provided by this package
36
37package provide portactivate 1.0
38package require portutil 1.0
39
40set org.macports.activate [target_new org.macports.activate portactivate::activate_main]
41target_runtype ${org.macports.activate} always
42target_state ${org.macports.activate} no
43target_provides ${org.macports.activate} activate
44target_requires ${org.macports.activate} main archivefetch fetch checksum extract patch configure build destroot install
45target_prerun ${org.macports.activate} portactivate::activate_start
46target_postrun ${org.macports.activate} portactivate::activate_finish
47
48namespace eval portactivate {
49}
50
51options activate.asroot
52default activate.asroot no
53
54proc portactivate::activate_start {args} {
55    global prefix
56    if {![file writable $prefix] || ([getuid] == 0 && [geteuid] != 0)} {
57        # if install location is not writable, need root privileges
58        elevateToRoot "activate"
59    }
60}
61
62proc portactivate::activate_main {args} {
63    global env subport version revision portvariants user_options PortInfo startupitem.autostart UI_PREFIX
64
65    registry_activate $subport $version $revision $portvariants [array get user_options]
66
67    # Display notes at the end of the activation phase.
68    if {[info exists PortInfo(notes)] && $PortInfo(notes) ne {}} {
69        ui_notice ""
70        foreach note $PortInfo(notes) {
71            # If env(COLUMNS) exists, limit each line's width to this width.
72            if {[info exists env(COLUMNS)]} {
73                set maxlen $env(COLUMNS)
74
75                foreach line [split $note "\n"] {
76                    set joiner ""
77                    set lines ""
78                    set newline ""
79
80                    foreach word [split $line " "] {
81                        if {[string length $newline] + [string length $word] >= $maxlen} {
82                            lappend lines $newline
83                            set newline ""
84                            set joiner ""
85                        }
86                        append newline $joiner $word
87                        set joiner " "
88                    }
89                    if {$newline ne {}} {
90                        lappend lines $newline
91                    }
92                    ui_notice [join $lines "\n"]
93                }
94            } else {
95                ui_notice $note
96            }
97        }
98        ui_notice ""
99    }
100
101    return 0
102}
103
104proc portactivate::activate_finish {args} {
105    global subport startupitem.autostart UI_PREFIX
106
107    # Do this _after_ activate_main, because post-activate hooks might create
108    # the files needed for this
109    if {[tbool startupitem.autostart]} {
110        ui_notice "$UI_PREFIX [format [msgcat::mc "Loading %s"] $subport]"
111        if {[eval_targets "load"]} {
112            ui_error [format [msgcat::mc "Failed to load %s"] $subport]
113            return 1
114        }
115    }
116
117    return 0
118}
Note: See TracBrowser for help on using the repository browser.