Snow LeopardにしたらMacPortsが動かなくなった

Snow Leopardにしてからportコマンドエラーが出るようになった。

dlopen(/Library/Tcl/macports1.0/MacPorts.dylib, 10): no suitable image found.  Did find:
     /Library/Tcl/macports1.0/MacPorts.dylib: mach-o, but wrong architecture
    while executing
"load /Library/Tcl/macports1.0/MacPorts.dylib"
    ("package ifneeded macports 1.0" script)
    invoked from within
"package require macports"
    (file "/opt/local/bin/port" line 39)

もともとMacPortsは、単一のOS・CPUで動作するように設計されており、OSやCPUが変わると再インストールが必要なようだ。

http://trac.macports.org/wiki/Migrationに移行方法が書かれていたので実践してみる。

Portsを再インストール

まずはSnow Leopard版のXcodeが必要なのでインストールディスクからインストールしておく。
次にSnow Leopard版のMacPortshttp://www.macports.org/install.php
から最新のdmgをダウンロードし、インストールし直す。 (現時点で最新は1.9.2)


続いてインストール済みリストを書き出す。

$ port installed > myports.txt

インストール済みのポートをすべてアンインストール。

$ sudo port -f uninstall installed

ビルドやアーカイブを削除。

$ sudo port clean --work --archive all

最後に、myports.txを見ながら適切なvariantを設定しつつ、1つずつインストールする。

$ sudo port install portname +variant1 +variant2 ...

1つずつインストールする…。
…。
いやいや、めんどくさい。
201個もあるんだよ、ムリムリ。

自動再インストール

幸い実験的ではあるけど、自動インストールスクリプトrestore_ports.tclが用意されている。
次のコマンドでダウンロード・実行可能にする。

$ curl -O http://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl
$ chmod +x restore_ports.tcl

以前にインストールしていたポートのリスト(myports.txt)を指定して実行。

$ sudo ./restore_ports.tcl myports.txt

そのままでは恐らく次のようなエラーが出るので

couldn't read file "/Library/Tcl/macports1.0/macports_fastload.tcl": no such file or directory
    while executing
"source ${macportsTclPath}/macports1.0/macports_fastload.tcl"
    (file "./restore_ports.tcl" line 244)

-tでtclのパスを指定してあげる。

$ sudo ./restore_ports.tcl -t /opt/local/share/macports/Tcl myports.txt

あとは自動的にイントールしてくれるので、基本的には待つだけ。

エラーがでた場合

依存関係によっては、ポートをdeactivateできなくてエラーがでることも。

--->  Deactivating p5-compress-raw-zlib
--->  Unable to uninstall/deactivate p5-compress-raw-zlib @2.027_0, the following ports depend on it:
--->       p5-io-compress @2.027_0
port deactivate failed: Please uninstall the ports that depend on p5-compress-raw-zlib first.
    while executing
"install_ports $operationList"
    (file "./restore_ports.tcl" line 264)

この場合は、dependentsで依存しているポートを調べて

$ port dependents p5-compress-raw-zlib

uninstallしてみる。

$ sudo port uninstall p5-io-compress

再度、restore_ports.tclを実行すればOK。

終わりに

restore_ports.tclは一気にインストールするため、かなりの時間がかかる。
再インストールのリスト(myports.txt)は実行前に整理して、不要なポートは削っておくといいと思う。
ただ、ここまで書いといてなんだけど、かなりの確立でエラーが発生するので
ポートの数が少ないなら個別にインストールしたほうが簡単かもしれない。