In the ongoing saga of the recent server upgrade I experienced some difficulty with my installation of MacPorts immediately after the upgrade to Mac OS X 10.6 Snow Leopard Server. The first problem was resolved by upgrading my version of Xcode to be current with 10.6. If you do not have Xcode 3.2.2 currently installed on your Snow Leopard Server then you will need to fetch it from http://connect.apple.com with your Apple ID.
After the download completed I was able to successfully upgrade my Xcode to the current version from the one previously installed under Mac OS X 10.5 Leopard Server. The whole process took approximately 25 minutes.
After it is installed you can install the MacPorts system from MacPorts.org. MacPorts was derived from the FreeBSD Ports which is an efficient application packaging system that enable packages to be built completely from source code including all dependencies. If you come from the Linux world and have ever experienced the hell that is RPMs you will probably fall in love with ports
At this point I reviewed a few things on in the terminal. I ran port selfupdate just to ensure that my ports database was up to date. I also ran port upgrade outdated to ensure that all of the old ports were rebuilt with the new tools (Xcode & MacPorts). Unfortunately this is where things began to fall apart. During the upgrade I discovered numerous stale or inactive ports. So I wrote a quick shell command to remove them from the system.
port installed |grep -v "(active)" >cleanupports
The above command will list all of the installed ports but the grep filter will eliminate all of the active ports from the output. this is handy as I can now capture this output into a file which can be used to create a shell script or simply as input to a script. In this case I edited the file adding the port -f uninstall command so that I could forcibly remove all of the inactive ports.
Unfortunately even after this cleanup was I encountered a new issue. The MacPorts failed to upgrade the previously installed ports. After tailing the build log of the nano port I discovered the root of the problem see the excerpt below;
:info:configure config.status: error: could not create Makefile :info:configure shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_editors_nano/nano/work/nano-2.2.3" && ./configure --prefix=/opt/local --disable-wrapping-as-root --enable-utf8 " returned error 1
I immediately referenced the search engines and discovered that my only option at this point is to uninstall all of the ports and then reinstall them. Now this was going to become a messy endeavor. However before i gave into despair I decided to try automating the process. I mean if I could script the removal the stale ports why not uninstall all of them? So I wrote another shell command but this time using awk in lieu of grep. To make matter more interesting I decided to write two one for removal and one for re-installation.
port installed |awk '/(active)/{print "port -f uninstall " $1 " " $2}'>uninstallports port installed |awk '/(active)/{print "port install " $1 }'>reinstallports
The nice thing about awk is that you can customize the output which is handy if you want to generate a quick one time use script. I pipe the output of port installed into awk then massage that into commands which I deposit in the appropriate script container. Finally I added port installed to the end of uninstallports and then run the new command.
sh uninstallports ---> Deactivating a52dec @0.7.4_0 ---> Uninstalling a52dec @0.7.4_0 ---> Unable to uninstall apache2 @2.2.14_0+darwin+darwin_9+preforkmpm, the following ports depend on it: ---> mod_fastcgi @2.4.6_0 ---> php5 @5.2.10_0+apache2+fastcgi+macosx+mysql5+pcntl+pear+postgresql83+sockets+tidy Warning: Uninstall forced. Proceeding despite dependencies. ---> Deactivating apache2 @2.2.14_0+darwin+darwin_9+preforkmpm ---> Unable to deactivate apache2 @2.2.14_0+darwin+darwin_9+preforkmpm, the following ports depend on it: ---> mod_fastcgi @2.4.6_0 ---> php5 @5.2.10_0+apache2+fastcgi+macosx+mysql5+pcntl+pear+postgresql83+sockets+tidy Warning: Deactivate forced. Proceeding despite dependencies. ---> Uninstalling apache2 @2.2.14_0+darwin+darwin_9+preforkmpm ---> Deactivating apr @1.4.5_1 ---> Cleaning apr ---> Uninstalling apr @1.4.5_1 No ports are installed.
As you can see from the sample output all of the ports have been successfully uninstalled from the system. At this point I decided that I was not comfortable with simply reinstalling all of them again. First I ran port install nano to see if I had indeed fixed the problem.
At this point my system is cleaned up and ready for business again but I decided to only install the ports that I need on a case by case basis. There are far too many that were experiments that I never properly cleaned up when they were no longer required.
ABOUT THE AUTHOR: Mikel King has been a leader in the Information Technology Services field for over 20 years. He is currently the CEO of Olivent Technologies, a professional creative services partnership in NY. Additionally he is currently serving as the Secretary of the BSD Certification group as well as a Senior Editor for the BSD News Network and JAFDIP.
Related articles
- Name Based Vhosting in Mac OS X Snow Leopard Server (jafdip.com)
- How to Use MacPorts (lockergnome.com)
- Combining PDf files into a single document (jafdip.com)
Laurel says
Great blog! Do you have any suggestions for aspiring writers? I’m planning to start my own website soon but I’m a little lost on everything. Would you recommend starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely confused .. Any recommendations? Thanks a lot!
Mikel King says
Start with WordPress and see where it goes.
Clemens says
Note that most of the grep’ing wasn’t really necessary in this
case, because MacPorts natively support a number of expression that
will do the filtering for you. For example, to list all inactive
ports (i.e., all ports that aren’t active), use
port
. Also, instead of re-installing all portsinstalled inactive
manually, you could have only reinstalled the ports you manually
installed at some point back in time and let MacPorts take care of
their dependencies for you. To do that, store the output of
port installed requested
orport echo
, uninstall all installed ports (requested
sudo port
) and re-install the requested ports. Theuninstall installed
bottom of our Migration wiki page has a script that can automate
this task: https://trac.macports.org/wiki/Migration#automatic.
Mikel King says
I did try a number of things when this occurred and what I came up with was the only thing that worked the time. In any event this is good to know and may help someone else in the future.
Thanks!
m
Nils P. Ellingsen says
Thanks! this really helped me clean up my ports-directory 🙂
Mikel King says
I am glad that you found it useful. Look forward to seeing your responses to other posts…