1 | #!/usr/bin/tclsh |
---|
2 | # |
---|
3 | # Upgrade sources.conf for a given prefix (passed as the first and only |
---|
4 | # argument). |
---|
5 | # |
---|
6 | # For an rsync: repository, if it is the standard MacPorts one and not |
---|
7 | # already tagged, then make it default, if another wasn't already default. |
---|
8 | # For a file:// respository, if it is an svn checkout from the MacPorts |
---|
9 | # server, then make it default if another hasn't already been tagged. |
---|
10 | # |
---|
11 | |
---|
12 | if {[llength $::argv] == 0} { |
---|
13 | puts "Usage: ${::argv0} <prefix>" |
---|
14 | exit 1 |
---|
15 | } |
---|
16 | |
---|
17 | set prefix [lindex $::argv 0] |
---|
18 | set sourcesConf ${prefix}/etc/macports/sources.conf |
---|
19 | |
---|
20 | set mktempChannel [open "|/usr/bin/mktemp -t macports_sources_upgrade" r] |
---|
21 | set tempfile [read -nonewline $mktempChannel] |
---|
22 | close $mktempChannel |
---|
23 | |
---|
24 | set sourcesConfChannel [open $sourcesConf r] |
---|
25 | set tempfileChannel [open $tempfile w] |
---|
26 | set defaultSeen false |
---|
27 | |
---|
28 | while {[gets $sourcesConfChannel line] >= 0} { |
---|
29 | if {!$defaultSeen && ![regexp {^\s*#|^$} $line]} { |
---|
30 | if {[string first {[default]} $line] >= 0} { |
---|
31 | set defaultSeen true |
---|
32 | } elseif {[regexp {^\s*rsync://rsync\.macports\.org/release/ports/} $line]} { |
---|
33 | set line "$line \[default\]" |
---|
34 | set defaultSeen true |
---|
35 | } elseif {[regexp {^\s*file://(/[^ #]+)} $line -> filepath]} { |
---|
36 | if {[file exists [file join ${filepath} .svn]]} { |
---|
37 | set svnChannel [open "|svn info ${filepath}" r] |
---|
38 | set svnURL {} |
---|
39 | while {[gets $svnChannel svnLine] >= 0} { |
---|
40 | regexp {^URL: (.*)} $svnLine -> svnURL |
---|
41 | } |
---|
42 | close $svnChannel |
---|
43 | if {[regexp {^https?://svn\.macports\.org/repository/macports/trunk/dports} $svnURL]} { |
---|
44 | set line "${line} \[default\]" |
---|
45 | set defaultSeen true |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | } |
---|
50 | puts $tempfileChannel $line |
---|
51 | } |
---|
52 | close $tempfileChannel |
---|
53 | close $sourcesConfChannel |
---|
54 | |
---|
55 | file rename ${sourcesConf} "${sourcesConf}.mpsaved" |
---|
56 | file rename ${tempfile} ${sourcesConf} |
---|
57 | |
---|