MacOS – How to make MacPorts reinstall requested ports from a different boot drive

macosmacportsmigration

I recently changed workstations and went from OSx 10.7.5 to OSX 10.11! Yay!

I have a lot of installation to do. Nuts…. (But worth it!)

I have temporarily mounted my old workstation's hard drive to copy over important files. Since I have a different OS, a different version of XCode (and command line tools), and a different version of MacPorts, I'd rather do a fresh install of all my requested ports rather than semi-blindly copy stuff over from the old drive.

MacPorts has a great Migration guide (link) that shows how to create a list of all installed ports, then reinstall them once software has been upgraded — but that's for upgrading on the same boot drive. My new drive has no installed ports because I just installed MacPorts.

Is there a way to list requested ports on the old hard drive in order to upgrade them on my new drive?

Best Answer

Actually, I think you want the results of port -qv installed to restore your installation but I'll show you how to produce both files.

Mount the old hard drive and copy this file into a folder in your home folder- /opt/local/var/macports/registry/registry.db. Now navigate to that folder.

To produce the requested.txt file:

sqlite3 registry.db 'select name, requested from ports' |
awk -F '|' '{ if ( $2 == 1 ) print $1 }' >requested.txt

To produce the myports.txt file:

sqlite3 registry.db \
'select name,  version, revision, state, os_platform, os_major, archs, date from ports' |
sort |
awk -F'|' '{ if ( $4 == "installed") {act="(active)"} else {act=""} } 
{ cmd = "date -r" $8 " +%Y-%m-%dT%T%z"; cmd | getline mydate; close(cmd) }
{ printf ("%s @%s_%s %s platform=%s %s archs=%s date=%s\n",
    $1, $2, $3, act,$5, $6, $7, mydate)
}' >myports.txt