| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | package require darwinports |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | set portdir . |
|---|
| 37 | array set ui_options {} |
|---|
| 38 | |
|---|
| 39 | proc ui_prefix {priority} { |
|---|
| 40 | return "" |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | proc ui_channels {priority} { |
|---|
| 44 | return {} |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | proc copy_package_if_available {portname basepath destpath} { |
|---|
| 50 | |
|---|
| 51 | set dependencies {} |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | if {$portname == "XFree86"} { return {} } |
|---|
| 56 | |
|---|
| 57 | if {[catch {set res [dportsearch "^$portname\$"]} error]} { |
|---|
| 58 | puts stderr "Internal error: port search failed: $error" |
|---|
| 59 | return |
|---|
| 60 | } |
|---|
| 61 | foreach {name array} $res { |
|---|
| 62 | array set portinfo $array |
|---|
| 63 | if {![info exists portinfo(name)]} { return -1 } |
|---|
| 64 | if {![info exists portinfo(version)]} { return -1 } |
|---|
| 65 | if {![info exists portinfo(categories)]} { return -1 } |
|---|
| 66 | |
|---|
| 67 | set portname $portinfo(name) |
|---|
| 68 | set portversion $portinfo(version) |
|---|
| 69 | set category [lindex $portinfo(categories) 0] |
|---|
| 70 | |
|---|
| 71 | set depends {} |
|---|
| 72 | if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" } |
|---|
| 73 | if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" } |
|---|
| 74 | |
|---|
| 75 | foreach depspec $depends { |
|---|
| 76 | set dep [lindex [split $depspec :] end] |
|---|
| 77 | set result [copy_package_if_available $dep $basepath $destpath] |
|---|
| 78 | if {$result == -1} { |
|---|
| 79 | return -1 |
|---|
| 80 | } else { |
|---|
| 81 | eval "lappend dependencies $result" |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | set pkgname "${portname}-${portversion}.pkg" |
|---|
| 86 | lappend dependencies $pkgname |
|---|
| 87 | set pkgpath "${basepath}/${category}/${pkgname}" |
|---|
| 88 | if {[file readable "${pkgpath}/Contents/Info.plist"]} { |
|---|
| 89 | puts stderr "copying package: ${pkgpath} to ${destpath}" |
|---|
| 90 | if {[catch {system "cp -R ${pkgpath} ${destpath}/"} error]} { |
|---|
| 91 | puts stderr "Internal error: $error" |
|---|
| 92 | } |
|---|
| 93 | } else { |
|---|
| 94 | puts stderr "package ${pkgname} not found" |
|---|
| 95 | return -1 |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | return $dependencies |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | proc write_description_plist {infofile portname portversion description} { |
|---|
| 103 | set infofd [open ${infofile} w+] |
|---|
| 104 | puts $infofd {<?xml version="1.0" encoding="UTF-8"?> |
|---|
| 105 | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|---|
| 106 | <plist version="1.0"> |
|---|
| 107 | } |
|---|
| 108 | puts $infofd "<dict> |
|---|
| 109 | <key>IFPkgDescriptionDeleteWarning</key> |
|---|
| 110 | <string></string> |
|---|
| 111 | <key>IFPkgDescriptionDescription</key> |
|---|
| 112 | <string>${description}</string> |
|---|
| 113 | <key>IFPkgDescriptionTitle</key> |
|---|
| 114 | <string>${portname}</string> |
|---|
| 115 | <key>IFPkgDescriptionVersion</key> |
|---|
| 116 | <string>${portversion}</string> |
|---|
| 117 | </dict> |
|---|
| 118 | </plist>" |
|---|
| 119 | close $infofd |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | proc write_welcome_html {filename portname portversion long_description description homepage} { |
|---|
| 123 | set fd [open ${filename} w+] |
|---|
| 124 | if {$long_description == ""} { |
|---|
| 125 | set long_description $description |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | puts $fd " |
|---|
| 129 | <html lang=\"en\"> |
|---|
| 130 | <head> |
|---|
| 131 | <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\"> |
|---|
| 132 | <title>Install ${portname}</title> |
|---|
| 133 | </head> |
|---|
| 134 | <body> |
|---|
| 135 | <font face=\"Helvetica\"><b>Welcome to the ${portname} for Mac OS X Installer</b></font> |
|---|
| 136 | <p> |
|---|
| 137 | <font face=\"Helvetica\">${long_description}</font> |
|---|
| 138 | <p>" |
|---|
| 139 | |
|---|
| 140 | if {$homepage != ""} { |
|---|
| 141 | puts $fd "<font face=\"Helvetica\">${homepage}</font><p>" |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | 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> |
|---|
| 145 | </body> |
|---|
| 146 | </html>" |
|---|
| 147 | |
|---|
| 148 | close $fd |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | proc write_PkgInfo {infofile} { |
|---|
| 152 | set infofd [open ${infofile} w+] |
|---|
| 153 | puts $infofd "pmkrpkg1" |
|---|
| 154 | close $infofd |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | proc mpkg_write_info_plist {infofile portname portversion portrevision destination dependencies} { |
|---|
| 158 | set vers [split $portversion "."] |
|---|
| 159 | |
|---|
| 160 | if {[string index $destination end] != "/"} { |
|---|
| 161 | append destination / |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | set depxml "" |
|---|
| 165 | foreach dep $dependencies { |
|---|
| 166 | append depxml "<dict> |
|---|
| 167 | <key>IFPkgFlagPackageLocation</key> |
|---|
| 168 | <string>${dep}</string> |
|---|
| 169 | <key>IFPkgFlagPackageSelection</key> |
|---|
| 170 | <string>selected</string> |
|---|
| 171 | </dict> |
|---|
| 172 | " |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | set infofd [open ${infofile} w+] |
|---|
| 176 | puts $infofd {<?xml version="1.0" encoding="UTF-8"?> |
|---|
| 177 | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|---|
| 178 | <plist version="1.0"> |
|---|
| 179 | } |
|---|
| 180 | puts $infofd "<dict> |
|---|
| 181 | <key>CFBundleGetInfoString</key> |
|---|
| 182 | <string>${portname} ${portversion}</string> |
|---|
| 183 | <key>CFBundleIdentifier</key> |
|---|
| 184 | <string>org.opendarwin.darwinports.mpkg.${portname}</string> |
|---|
| 185 | <key>CFBundleName</key> |
|---|
| 186 | <string>${portname}</string> |
|---|
| 187 | <key>CFBundleShortVersionString</key> |
|---|
| 188 | <string>${portversion}</string> |
|---|
| 189 | <key>IFMajorVersion</key> |
|---|
| 190 | <integer>${portrevision}</integer> |
|---|
| 191 | <key>IFMinorVersion</key> |
|---|
| 192 | <integer>0</integer> |
|---|
| 193 | <key>IFPkgFlagComponentDirectory</key> |
|---|
| 194 | <string>./Contents/Resources</string> |
|---|
| 195 | <key>IFPkgFlagPackageList</key> |
|---|
| 196 | <array> |
|---|
| 197 | ${depxml}</array> |
|---|
| 198 | <key>IFPkgFormatVersion</key> |
|---|
| 199 | <real>0.10000000149011612</real> |
|---|
| 200 | </dict> |
|---|
| 201 | </plist>" |
|---|
| 202 | close $infofd |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | proc fatal args { |
|---|
| 209 | global argv0 |
|---|
| 210 | puts stderr "$argv0: $args" |
|---|
| 211 | exit |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | array set options [list] |
|---|
| 216 | array set variations [list] |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | if {[catch {dportinit ui_options options variations} result]} { |
|---|
| 220 | puts "Failed to initialize ports system, $result" |
|---|
| 221 | exit 1 |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | package require Pextlib |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | if {[llength $argv] == 0} { |
|---|
| 228 | lappend argv ".*" |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | foreach pname $argv { |
|---|
| 232 | |
|---|
| 233 | if {[catch {set res [dportsearch "^${pname}\$"]} result]} { |
|---|
| 234 | puts "port search failed: $result" |
|---|
| 235 | exit 1 |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | foreach {name array} $res { |
|---|
| 239 | global prefix |
|---|
| 240 | array unset portinfo |
|---|
| 241 | array set portinfo $array |
|---|
| 242 | |
|---|
| 243 | if {![info exists portinfo(porturl)]} { |
|---|
| 244 | puts stderr "Internal error: no porturl for $name" |
|---|
| 245 | continue |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | set pkgbase "/darwinports/pkgs/" |
|---|
| 249 | set mpkgbase "/darwinports/mpkgs/" |
|---|
| 250 | set porturl $portinfo(porturl) |
|---|
| 251 | set prefix "/opt/local" |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | if {[regsub {^file://} $portinfo(porturl) "" portpath]} { |
|---|
| 255 | if {[info exists portinfo(name)] && |
|---|
| 256 | [info exists portinfo(version)] && |
|---|
| 257 | [info exists portinfo(categories)]} { |
|---|
| 258 | set portname $portinfo(name) |
|---|
| 259 | set portversion $portinfo(version) |
|---|
| 260 | set category [lindex $portinfo(categories) 0] |
|---|
| 261 | set mpkgfile ${mpkgbase}/${category}/${portname}-${portversion}.mpkg/Contents/Info.plist |
|---|
| 262 | if {[file readable $mpkgfile] && ([file mtime ${mpkgfile}] > [file mtime ${portpath}/Portfile])} { |
|---|
| 263 | puts stderr "Skipping ${portname}-${portversion}; meta-package is up to date." |
|---|
| 264 | continue |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | set portname "" |
|---|
| 276 | set portversion "" |
|---|
| 277 | set description "" |
|---|
| 278 | set long_description "" |
|---|
| 279 | set homepage "" |
|---|
| 280 | set category "" |
|---|
| 281 | |
|---|
| 282 | if {[info exists portinfo(name)]} { set portname $portinfo(name) } |
|---|
| 283 | if {[info exists portinfo(version)]} { set portversion $portinfo(version) } |
|---|
| 284 | if {[info exists portinfo(description)]} { set description $portinfo(description) } |
|---|
| 285 | if {[info exists portinfo(long_description)]} { set long_description $portinfo(long_description) } |
|---|
| 286 | if {[info exists portinfo(homepage)]} { set homepage $portinfo(homepage) } |
|---|
| 287 | if {[info exists portinfo(categories)]} { set category [lindex $portinfo(categories) 0] } |
|---|
| 288 | if {[info exists portinfo(maintainers)]} { set maintainers $portinfo(maintainers) } |
|---|
| 289 | |
|---|
| 290 | puts "meta-packaging ${category}/${portname}-${portversion}" |
|---|
| 291 | |
|---|
| 292 | set mpkgpath "${mpkgbase}/${category}/${portname}-${portversion}.mpkg" |
|---|
| 293 | |
|---|
| 294 | if {[catch {system "mkdir -p -m 0755 ${mpkgpath}/Contents/Resources"} error]} { |
|---|
| 295 | puts stderr "Internal error: $error" |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | set dependencies {} |
|---|
| 301 | set result [copy_package_if_available ${portname} $pkgbase "${mpkgpath}/Contents/Resources/"] |
|---|
| 302 | if {$result == -1} { |
|---|
| 303 | puts stderr "aborting; one or more dependencies was missing." |
|---|
| 304 | if {[catch {system "rm -R ${mpkgpath}"} error]} { |
|---|
| 305 | puts stderr "Internal error: $error" |
|---|
| 306 | } |
|---|
| 307 | continue |
|---|
| 308 | } else { |
|---|
| 309 | set result [lsort -uniq $result] |
|---|
| 310 | eval "lappend dependencies $result" |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | write_PkgInfo ${mpkgpath}/Contents/PkgInfo |
|---|
| 317 | mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $prefix $dependencies |
|---|
| 318 | write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description |
|---|
| 319 | |
|---|
| 320 | foreach variable {long_description description homepage} { |
|---|
| 321 | if {![info exists $variable]} { |
|---|
| 322 | set pkg_$variable "" |
|---|
| 323 | } else { |
|---|
| 324 | set pkg_$variable [set $variable] |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | write_welcome_html ${mpkgpath}/Contents/Resources/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage |
|---|
| 328 | file copy -force -- /opt/local/share/darwinports/resources/port1.0/package/background.tiff \ |
|---|
| 329 | ${mpkgpath}/Contents/Resources/background.tiff |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | } |
|---|
| 336 | |
|---|