| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | if {[llength $::argv] == 0} { |
|---|
| 15 | puts "Usage: ${::argv0} <prefix>" |
|---|
| 16 | exit 1 |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | set prefix [lindex $::argv 0] |
|---|
| 20 | set sourcesConf ${prefix}/etc/macports/sources.conf |
|---|
| 21 | if {[catch {set sourcesConfChannel [open $sourcesConf r]}]} { |
|---|
| 22 | exit 0 |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | set mktempChannel [open "|/usr/bin/mktemp -t macports_sources_upgrade" r] |
|---|
| 27 | set tempfile [read -nonewline $mktempChannel] |
|---|
| 28 | close $mktempChannel |
|---|
| 29 | |
|---|
| 30 | set tempfileChannel [open $tempfile w] |
|---|
| 31 | set defaultSeen false |
|---|
| 32 | set defaultWritten false |
|---|
| 33 | |
|---|
| 34 | while {[gets $sourcesConfChannel line] >= 0} { |
|---|
| 35 | set addDefault false |
|---|
| 36 | if {!$defaultSeen && ![regexp {^\s* |
|---|
| 37 | if {[regexp {^([\w-]+://\S+)(?:\s+\[(\w+(?:,\w+)*)\])?$} $line -> url flags]} { |
|---|
| 38 | set flags [split $flags ,] |
|---|
| 39 | if {[lsearch $flags default] >= 0} { |
|---|
| 40 | set defaultSeen true |
|---|
| 41 | } elseif {[regexp {rsync://rsync\.(macports|darwinports)\.org/(release|dpupdate)/d?ports} $url]} { |
|---|
| 42 | set addDefault true |
|---|
| 43 | } elseif {[regexp {file://(/.+)} $url -> filepath]} { |
|---|
| 44 | if {[file exists [file join ${filepath} .svn]]} { |
|---|
| 45 | set svnChannel [open "|svn info ${filepath}" r] |
|---|
| 46 | set svnURL {} |
|---|
| 47 | while {[gets $svnChannel svnLine] >= 0} { |
|---|
| 48 | regexp {^URL: (.*)} $svnLine -> svnURL |
|---|
| 49 | } |
|---|
| 50 | close $svnChannel |
|---|
| 51 | if {[regexp {^https?://svn\.(macports|macosforge)\.org/repository/macports/trunk/dports} $svnURL]} { |
|---|
| 52 | set addDefault true |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | if {$addDefault} { |
|---|
| 57 | lappend flags default |
|---|
| 58 | set line "$url \[[join $flags ,]\]" |
|---|
| 59 | set defaultSeen true |
|---|
| 60 | set defaultWritten true |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | puts $tempfileChannel $line |
|---|
| 65 | } |
|---|
| 66 | close $tempfileChannel |
|---|
| 67 | close $sourcesConfChannel |
|---|
| 68 | |
|---|
| 69 | if {$defaultWritten} { |
|---|
| 70 | set attributes [file attributes ${sourcesConf}] |
|---|
| 71 | if {[catch {file rename ${sourcesConf} "${sourcesConf}.mpsaved"}]} { |
|---|
| 72 | file rename -force ${sourcesConf} "${sourcesConf}.mpsaved_[clock seconds]" |
|---|
| 73 | } |
|---|
| 74 | file rename ${tempfile} ${sourcesConf} |
|---|
| 75 | eval file attributes ${sourcesConf} $attributes |
|---|
| 76 | } else { |
|---|
| 77 | file delete ${tempfile} |
|---|
| 78 | if {!$defaultSeen} { |
|---|
| 79 | puts "[string repeat - 72] |
|---|
| 80 | Warning, your source config file at: |
|---|
| 81 | |
|---|
| 82 | $sourcesConf |
|---|
| 83 | |
|---|
| 84 | needs to have a \[default\] tag added to the primary MacPorts repository, |
|---|
| 85 | however the proper entry could not be determined. Please add the tag |
|---|
| 86 | manually by either appending \[default\] to the end of the correct line, |
|---|
| 87 | or if there are already tags, adding it to the list, eg, |
|---|
| 88 | \[nosync,default\]. |
|---|
| 89 | [string repeat - 72]" |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | exit 0 |
|---|