2007-01-25 Dispell Terminal

Mac OSX greatness! I’m using 10.3.9 (Panther) on my laptop. Open a terminal, and try the following:

`for f in`port contents libtasn1|grep ’^ ’`; do if test -f $f; then echo $f exists; else echo $f is missing; exit 1; fi; done`

On my system, this closes the terminal window! ☠

Trying to build it piece by piece I get here:

`for f in`port contents libtasn1|grep ’^ ’`ugg; do if test $f; then echo ok $f; else echo MISSING $f; exit 1; fi; done`

As soon as I add a the **-f** to the test, I get the behaviour mentioned above.

It turns out that I made two mistakes:

1. The output of port contents includes \r. Those are invisible in Terminal.app, but result in failing test -f.

2. Adding the exit will not abort the for loop but exit the current shell. Doh. 💡

So here we go:

`for f in`port contents libtasn1|tr -d ’\r’|grep ’^ ’`ugg; do if test ! -f $f; then echo MISSING "$f"; fi; done`

What I really want to do is loop through all installed ports, however, because I am trying to check my MacPorts installation (2007-01-24 DarwinPorts or MacPorts & comments).

MacPorts

2007-01-24 DarwinPorts or MacPorts

`for f in`port contents installed|tr -d ’\r’|grep ’^ ’`ugg; do if test ! -f $f; then echo MISSING "$f"; fi; done`

This gives me tons of missing files. But I’m just interested in the broken packages...

List of packages, without versions and ignoring active/inactive:

`port installed|sed -n 's/^ \([^ ]*\)/-- \1/p'|uniq`

So now a double loop, producing a message for every failing port, and piping it all through uniq so that I get only one message per port:

`for port in`port installed|sed -n ’s/^ \([^ ]*\).*_\1_p’|uniq`; do for f in`port contents $port|tr -d ’\r’|grep ’^ ’`; do if test ! -f $f; then echo file missing in $port; fi; done; done|uniq`

Yikes!

file missing in bzip2
file missing in gd2
file missing in gnutls
file missing in id3lib
file missing in id3tool
file missing in id3v2
file missing in libexif
file missing in libpcap
file missing in libsigc++2
file missing in libxslt
file missing in mmencode
file missing in mp3info
file missing in opencdk
file missing in p5-xml-parser
file missing in texinfo
file missing in tidy
file missing in wget
file missing in zlib

So how could I copy the missing files from my old tree to the new one?

This gives me the files of a port:

`port contents bzip2|tr -d '\r'|sed 's/^ \(.*\)/\1/'`

Now, let me strip the `/opt/local/` and create a test, first. Note how the sed uses *-n* to suppress the first line of fluff:

`for f in`port contents bzip2|tr -d ’\r’|sed -n ’s/^ \*opt\local\\(.*\)_\1_p’`; do if test ! -f ~/Desktop/DarwinPorts-local-1.102/$f; then echo missing $f; fi; done`

Now, run this test for all the packages that have been found failing. Yeah, no need to do the loop withing a loop thing again. Just reusing the names from the output above...

`for port in bzip2 gd2 gnutls id3lib id3tool id3v2 libexif libpcap libsigc++2 libxslt mmencode mp3info opencdk p5-xml-parser texinfo tidy wget zlib; do for f in`port contents $port|tr -d ’\r’|sed -n ’s/^ \*opt\local\\(.*\)_\1_p’`; do if test ! -f ~/Desktop/DarwinPorts-local-1.102/$f; then echo missing file in $port; fi; done; done|uniq`

And all I get is this:

missing file in tidy

Very good! That means I can move all the files over, and worry about tidy later. I propose the following:

`for port in bzip2 gd2 gnutls id3lib id3tool id3v2 libexif libpcap libsigc++2 libxslt mmencode mp3info opencdk p5-xml-parser texinfo wget zlib; do for f in`port contents $port|tr -d ’\r’|sed -n ’s/^ \*opt\local\\(.*\)_\1_p’`; do mv ~/Desktop/DarwinPorts-local-1.102/$f /opt/local/$f; done; done`

warning: But wait!

What’s this?

override rwxr-xr-x  root/admin for /opt/local/bin/bunzip2? (y/n [n])

Hm... Let me try again with the very first statement:

`for f in`port contents bzip2|tr -d ’\r’|grep ’^ ’`; do if test ! -f $f; then echo MISSING "$f"; fi; done`

The result:

MISSING /opt/local/bin/bzcmp
MISSING /opt/local/bin/bzegrep
MISSING /opt/local/bin/bzfgrep
MISSING /opt/local/bin/bzless

lightbulb: Ah! Those are soft links. I’ll have to do it all again!

`for port in`port installed|sed -n ’s/^ \([^ ]*\).*_\1_p’|uniq`; do for f in`port contents $port|tr -d ’\r’|grep ’^ ’`; do if test ! -f $f -a ! -L $f; then echo file missing in $port; fi; done; done|uniq`

file missing in gd2
file missing in gnutls
file missing in id3lib
file missing in id3tool
file missing in id3v2
file missing in libexif
file missing in libpcap
file missing in libsigc++2
file missing in libxslt
file missing in mmencode
file missing in mp3info
file missing in opencdk
file missing in p5-xml-parser
file missing in texinfo
file missing in wget
file missing in zlib

Well, the list is not much smaller; it no longer contains tidy and bzip2.

Let’s try it again without those two, use *sudo su*, and *mv -i*:

`for port in gd2 gnutls id3lib id3tool id3v2 libexif libpcap libsigc++2 libxslt mmencode mp3info opencdk p5-xml-parser texinfo wget zlib; do for f in`port contents $port|tr -d ’\r’|sed -n ’s/^ \*opt\local\\(.*\)_\1_p’`; do mv -i ~/Desktop/[http://darwinports.opendarwin.org/ DarwinPorts]-local-1.102/$f /opt/local/$f; done; done`

Argh. Forgot `mkdir -p`dirname ~*Desktop*DarwinPorts-local-1.102/$f``in there somewhere, and changing ~ to`_home_alex`.

DarwinPorts

Enough time wasted. Just uninstall -f the buggers and redo it.

`for port in gd2 gnutls id3lib id3tool id3v2 libexif libpcap libsigc++2 libxslt mmencode mp3info opencdk p5-xml-parser texinfo wget zlib; do sudo port -f uninstall $port; done; for port in gd2 gnutls id3lib id3tool id3v2 libexif libpcap libsigc++2 libxslt mmencode mp3info opencdk p5-xml-parser texinfo wget zlib; do sudo port install $port; done`

Result: I’m back in business with the exception of gnutls! 👊

So what I need now is this:

1. Verify that the installed packages are all complete.

2. Verify that the stuff I compiled myself in `/usr/local` still works. Perhaps I uninstalled some library it needed?

3. Get rid of multiple variants.

​#Software