Ticket #14482: upgrade_sources_conf_default.tcl

File upgrade_sources_conf_default.tcl, 1.9 KB (added by blb@…, 15 years ago)

sources.conf upgrade script

Line 
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
12if {[llength $::argv] == 0} {
13   puts "Usage: ${::argv0} <prefix>"
14   exit 1
15}
16
17set prefix [lindex $::argv 0]
18set sourcesConf ${prefix}/etc/macports/sources.conf
19
20set mktempChannel [open "|/usr/bin/mktemp -t macports_sources_upgrade" r]
21set tempfile [read -nonewline $mktempChannel]
22close $mktempChannel
23
24set sourcesConfChannel [open $sourcesConf r]
25set tempfileChannel [open $tempfile w]
26set defaultSeen false
27
28while {[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}
52close $tempfileChannel
53close $sourcesConfChannel
54
55file rename ${sourcesConf} "${sourcesConf}.mpsaved"
56file rename ${tempfile} ${sourcesConf}
57