1 | # et:ts=4 |
---|
2 | # portstartupitem.tcl |
---|
3 | # |
---|
4 | # $Id: $ |
---|
5 | # |
---|
6 | # Copyright (c) 2004 Markus W. Weissman <mww@opendarwin.org>, |
---|
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 are |
---|
11 | # met: |
---|
12 | # |
---|
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 Computer, Inc. nor the names of its |
---|
19 | # contributors may be used to endorse or promote products derived from |
---|
20 | # this software without specific prior written permission. |
---|
21 | # |
---|
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
25 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
26 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
27 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
28 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
29 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
32 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
33 | # |
---|
34 | |
---|
35 | package provide portstartupitem 1.0 |
---|
36 | |
---|
37 | proc startupitem_create {args} { |
---|
38 | global prefix destroot portname os.platform |
---|
39 | global startupitem.name startupitem.requires |
---|
40 | global startupitem.start startupitem.start startupitem.start |
---|
41 | ui_msg "creating startup item/script" |
---|
42 | |
---|
43 | if {${os.platform} == "darwin"} { |
---|
44 | set scriptdir ${prefix}/etc/startup |
---|
45 | if { ![exists startupitem.name] } { |
---|
46 | set startupitem.name ${portname} |
---|
47 | } |
---|
48 | if { ![exists startupitem.start] } { |
---|
49 | set startupitem.start "sh ${scriptdir}/${portname}.sh start" |
---|
50 | } |
---|
51 | if { ![exists startupitem.stop] } { |
---|
52 | set startupitem.stop "sh ${scriptdir}/${portname}.sh stop" |
---|
53 | } |
---|
54 | if { ![exists startupitem.restart] } { |
---|
55 | set startupitem.restart "sh ${scriptdir}/${portname}.sh restart" |
---|
56 | } |
---|
57 | if { ![exists startupitem.requires] } { |
---|
58 | set startupitem.requires "\"Disks\", \"NFS\"" |
---|
59 | } |
---|
60 | set itemname [string toupper ${startupitem.name}] |
---|
61 | set itemdir ${prefix}/etc/StartupItems/${startupitem.name} |
---|
62 | file mkdir ${destroot}${itemdir} |
---|
63 | set item [open "${destroot}${itemdir}/${startupitem.name}" a] |
---|
64 | puts ${item} "#!/bin/sh" |
---|
65 | puts ${item} "#\n# DarwinPorts generated StartupItem\n#\n" |
---|
66 | puts ${item} ". ${prefix}/etc/rc.common\n" |
---|
67 | puts ${item} "StartService ()\n\{" |
---|
68 | puts ${item} "\tif \[ \"\$\{${itemname}:=-NO-\}\" = \"-YES-\" \]; then" |
---|
69 | puts ${item} "\t\tConsoleMessage \"Starting ${startupitem.name}\"" |
---|
70 | puts ${item} "\t\t${startupitem.start}" |
---|
71 | puts ${item} "\tfi\n\}\n" |
---|
72 | puts ${item} "StopService ()\n\{" |
---|
73 | puts ${item} "\t\tConsoleMessage \"Stopping ${startupitem.name}\"" |
---|
74 | puts ${item} "\t\t${startupitem.stop}" |
---|
75 | puts ${item} "\}\n" |
---|
76 | puts ${item} "RestartService ()\n\{" |
---|
77 | puts ${item} "\tif \[ \"\$\{${itemname}:=-NO-\}\" = \"-YES-\" \]; then" |
---|
78 | puts ${item} "\t\tConsoleMessage \"Restarting ${startupitem.name}\"" |
---|
79 | puts ${item} "\t\t${startupitem.restart}" |
---|
80 | puts ${item} "\tfi\n\}\n" |
---|
81 | puts ${item} "RunService \"\$1\"" |
---|
82 | close ${item} |
---|
83 | set para [open "${destroot}${itemdir}/StartupParameters.plist" a] |
---|
84 | puts ${para} "\{" |
---|
85 | puts ${para} "\tDescription\t= \"${startupitem.name}\";" |
---|
86 | puts ${para} "\tProvides\t= (\"${startupitem.name}\");" |
---|
87 | puts ${para} "\tRequires\t= (${startupitem.requires});" |
---|
88 | puts ${para} "\tOrderPreference\t= \"None\";" |
---|
89 | puts ${para} "\}" |
---|
90 | close ${para} |
---|
91 | file mkdir ${destroot}/Library/StartupItems |
---|
92 | system "cd ${destroot}/Library/StartupItems && ln -sf ${itemdir}" |
---|
93 | } else { |
---|
94 | ui_warn "WARNING: startupitem is not implemented on ${os.platform}." |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|