Macports without root on Leopard (and Tiger)

Posted by Peter Burkholder Mon, 11 Aug 2008 18:02:00 GMT

I don’t have root on my desktop Mac at $WORK, even though I have root on about 1200 production systems. sigh

So, I asked my Mac administrator to install the XCode development tools. Once that was done, all I needed to was the following.

  • Download the MacPort.tar.bz source distribution: http://svn.macports.org/repository/macports/downloads/MacPorts-1.6.0/MacPorts-1.6.0.tar.bz2
  • Note: For Leopard, one needs to apply the patch from http://trac.macports.org/changeset/32105
  • Run the following:
    
      tar -jxf MacPorts-1.6.0.tar.bz2 && cd MacPorts-1.6.0
    
      PATH=/usr/bin:/usr/sbin:/bin:/sbin ./configure \
      --prefix=$HOME/macports \
      --with-install-user=`id -un` \
      --with-install-group=`id -gn` \
      --x-includes=/usr/X11R6/include \
      --x-libraries=/usr/X11R6/lib \
      --with-tclpackage=$HOME/macports/share/macports/Tcl
    
      make
      make install
    
    
  • Add something like the following to your Mac’s .bashrc>
    
      export PATH=$HOME/macports/bin:$HOME/macports/sbin
      export MANPATH=$HOME/macports/share/man:$MANPATH
      export PERL5LIB=$HOME/macports/lib/perl5/5.8.8:$HOME/macports/lib/perl5/vendor_perl/5.8.8:$PERL5LIB
    
  • Run a selfupdate: port selfupdate
  • Now you do can do cool things like learn Scheme over lunch with: port search scheme; port install mzscheme

I’ve added this to the MacPorts wiki

Looking up IPs with mDNS and dns-sd on Mac OS X 10.4 1

Posted by Peter Burkholder Thu, 03 Jan 2008 02:54:00 GMT

I forgot the IP address of my printer on my local area network at home.

And my Mac quite cleverly only had the mdns name in the DeviceURI, but for setting up an older Windows system I really wanted the IP. Here’s how:

  • Browse for printers: dns-sd -B _printers._tcp .. :
    
      Timestamp     A/R Flags if Domain                   Service Type             Instance Name
    21:56:43.972  Add     2  7 local.                   _printer._tcp.           Brother HL-2070N series
  • Lookup the service info for the printer you’ve found: dns-sd -L "Brother HL-2070N series" _printer._tcp:
    
    21:58:30.695  Brother\032HL-2070N\032series._printer._tcp.local. can be reached at BRN-7E6301.local.:515 ...
  • Query on the domain name: dns-sd -Q BRN-7E6301.local.:
    
    Timestamp     A/R Flags if Name                             T   C Rdata
    21:59:52.553  Add     2  7 BRN-7E6301.local.                1   1 192.168.15.103

The reason to bother documenting this? Because the Mac Os X man page for dns-sd doesn’t document the use of the -Q switch.

Grrrrrrrrr.

Forensic Server Project (FSP) on Unix/Macosx 5

Posted by Peter Burkholder Fri, 26 Oct 2007 15:23:00 GMT

I’ve been working with the security incident response tools on the Helix CD, and been intrigued by Harvey Carlan’s Forensic Server Project

However, the Sourceforge files for the FSP server don’t run on MacOSX or other Unix-style machines because it uses the Win32::GetCwd and Win32::SetCwd modules. The simple patch, below, can be saved as, say, “fspc.patch” in the same directory as the unzipped FSP files. To patch, run:

patch -p0 < fscp.patch

Here’s the patch:

--- fspc.pl.orig    2007-10-24 15:40:22.000000000 -0400
+++ fspc.pl    2007-10-24 16:18:09.000000000 -0400
@@ -18,6 +18,7 @@
 use Digest::MD5;
 use Digest::SHA1;
 use Getopt::Long;
+use Cwd;

 #--------------------------------------------------------------------------
 # Globals
@@ -39,7 +40,7 @@
     exit 1;
 }

-$setup{basedir} = Win32::GetCwd();
+$setup{basedir} = getcwd();
 $setup{casedir} = $config{casedir} || "cases";
 $setup{casename} = $config{casename};
 $setup{port} = $config{port} || 7070;
@@ -296,14 +297,14 @@
 #------------------------------------------
 sub _setup {
 # clean up the directory names
-    $setup{basedir} = $setup{basedir}."\\" unless ($setup{basedir} =~ m/\\$/); 
-    $setup{casedir} = $setup{casedir}."\\" unless ($setup{casedir} =~ m/\\$/);
-    $setup{casename} = $setup{casename}."\\" unless ($setup{casename} =~ m/\\$/);
+    $setup{basedir} = $setup{basedir}."/" unless ($setup{basedir} =~ m/\/$/); 
+    $setup{casedir} = $setup{casedir}."/" unless ($setup{casedir} =~ m/\/$/);
+    $setup{casename} = $setup{casename}."/" unless ($setup{casename} =~ m/\/$/);
     my $casedir = $setup{basedir}.$setup{casedir};
     mkdir $casedir if (! -e $casedir && ! -d $casedir);
     my $curr_case = $casedir.$setup{casename};
-    mkdir $curr_case if (! -e $curr_case && ! -d $curr_case);
-    Win32::SetCwd($curr_case);
+     mkdir $curr_case if (! -e $curr_case && ! -d $curr_case);
+    chdir($curr_case);
     print "Setup complete.\n" if ($config{verbose});
 }

@@ -312,5 +313,5 @@
 # clears setup data so it can be renewed
 #------------------------------------------
 sub _reset {
-    Win32::SetCwd($setup{basedir});
+    chdir($setup{basedir});
 }

Mac Finder and smb:// error -36 -- Help from Samba 2

Posted by Peter Burkholder Tue, 16 Oct 2007 16:39:00 GMT

When trying to connect to a remote CIFS share today using the Mac OS X 10.4.10 Finder, I was getting the very unhelpful error:

The finder cannot complete the operation because some data in “smb://myservername” could not be read or written. (Error code -36)

Googling for this (or GoodSearching, in my case) didn’t turn up much of use. The system logs in /var/log/* weren’t of much help either. Far more useful was the smbclient command, which is part of the Samba installation. E.g.:

$ smbclient //server.addomain.univ.edu/Admin -W ADDOMAIN -U USERNAME
Password: 
session setup failed: NT_STATUS_PASSWORD_MUST_CHANGE

Oh! Excellent! That’s right, I’ve not used that password in eons, and it’s expired. Thank god I didn’t waste my time chasing red herrings. Now, how do I change my password from a Mac?

Being a general Windows nincompoop, I actually called technical support first off, but that wasn’t any help. Fifteen seconds of pondering, and 1 minute of reading the man page, and I came up with this:

$ smbpasswd -r aaddomain.univ.edu -U USERNAME
Old SMB password:
New SMB password:
Retype new SMB password:
Password changed for user USERNAME

All done!

Unborking MacOSX 3

Posted by Peter Burkholder Thu, 15 Mar 2007 13:54:00 GMT

Yesterday I rescued a co-worker’s computer from a bad 10.4.9 update. My salvation was this post, to which I added my own comments.

At least I learned a few general principles, namely that mucked up Macs can be saved by the general principle that I carried in from Linux – boot from Knoppix and repair the damage. In this case, we boot from an Install disk (one which explicitly says “Hold down C to to boot to Install” and the Installer will give you a Terminal and a command line. From their it’s a matter of running hdutil and open to mount disk images and launch applications.

I’m having to come up to speed on managing fleet of Macs, and fast, or else their going to eat up all my time. I’d like a week to play with OS X server and Puppet, thank you very much.

Ruby MySQL bindings for Intel Macs

Posted by Peter Burkholder Fri, 17 Nov 2006 22:47:00 GMT

Stefan Saasen points out that the Ruby MySQL bindings are broken on Intel Macs.

Here’s my version of the fix:


sudo gem install mysql -- --include=/opt/local
# select option 2 for Ruby 2.7, it will fail to build
cd /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7
sudo ruby extconf.rb install mysql -- --with-mysql-dir=/opt/local
vim mysql.c
# now here's where you add the line '#define ulong unsigned long' 
# just before the line '#define MYSQL_RUBY_VERSION...'
sudo make
sudo make install

Installing Rails on Mac OS X with MacPort 5

Posted by Peter Burkholder Fri, 17 Nov 2006 21:08:00 GMT

Yesterday I installed Ruby on Rails on my new(-ish) Intel MacBook. Last time around I built with a combination of Fink packages and hand-built applications following this posting at Hivelogic

This time around I’ve been using MacPorts, and it’s making my life much easier. Evan Weaver got me started with his post on building ruby, rails and associated pieces, but enough has changed changed since June 26 to merit my own updated take on the process.

Getting started

As Evan notes, “First, install the Apple Xcode tools from your OS X installation disc”. Please do so.

Next, install a recent version of “MacPorts” (what used to be known as DarwinPorts) from their Subversion respository. Installing from a .dmg file is easiest, then you can let MacPorts upgrade itself later on. As of this writing, Ports 1.3.2 is out, but disk images are only available for 1.3.1, e.g. at DarwinPorts-1.3.1-10.4.dmg

Next, you’ll want to update your executable path so the Ports installations in /opt/local are found before your Apple binaries. You should edit both /etc/profile and your ~/.bashrc (or equivalent if you’re using some other shell. Your path should end up looking something like this:

PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin" 

Install the ports

Now open a terminal (/Applications/Utilities/Terminal) and run the following:

sudo port -d selfupdate 
sudo port install lighttpd +ssl 
sudo port install rb-rubygems
sudo port install rb-fcgi
sudo port install mysql4 +server

Set up MySQL

You’ll also need to get mysql4 set up with these commands:

# set up the mysql database:
sudo -u mysql mysql_install_db
# start the server:
sudo /opt/local/bin/mysqld_safe --user=mysql
# set the root password (picking your own password, of course)
/opt/local/bin/mysqladmin -u root password newpassword

If you want Launcher to start MySQL automatically on reboot, you can run the following:


sudo launchclt load -w  \
  /Library/LaunchDaemons/org.macports.mysql4.plist
# stop the server
sudo launchctl stop org.macports.mysql4
# start the server
sudo launchctl start org.macports.mysql4

Install the gems

Running gems with the ‘-y’ option automatically takes care of prerequisites

sudo gem install -y rails
sudo gem install -y capistrano

Test!

First, are you hitting the right version of Ruby? ruby --version should return something like ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1] not this: ruby 1.8.2 (2004-12-25) [universal-darwin8.0]

Next, can you build a Rails application with


cd ~/tmp
rails widgetapp

Okay? Good. Now let’s cd widgetapp and put the database through it’s paces. Save the following code as test_rails_db.sh (or download it here)


#!/bin/sh

echo -n "Enter MySQL root password: " 
read PASSWD

mysqladmin -u root -p$PASSWD create widgetapp_development

cat >db/create.sql <<EOF
DROP table if exists widgets;

CREATE table widgets (
    id  int not null    auto_increment,
    name    varchar(40)  not null,
    description   varchar(100)   not null,
    primary key (id)
    );

INSERT INTO widgets (name, description) VALUES ("Tool", "Useful item");
INSERT INTO widgets (name, description) VALUES ("Food", "Tasty stuff");

EOF

mysql -u root -p$PASSWD  widgetapp_development < db/create.sql

mv config/database.yml config/database.yml.dist

cat >config/database.yml <<EOF 

development:
  adapter: mysql
  database: widgetapp_development
  username: root
  password: $PASSWD
  socket: /opt/local/var/run/mysqld/mysqld.sock

EOF

and run sh ./test_rails_db.sh. Enter your password when prompted.

Now the proof is in the pudding. If the following run s while you’re in your widgetapp rails directory, you’re golden:


script/generate scaffold Widget
script/server

Now browse to http://0.0.0.0:3000/widgets/list and you should utter a little gasp of joy.

Importing Thunderbird folders into Mail.app

Posted by Peter Burkholder Mon, 09 Oct 2006 23:59:00 GMT

This is also posted on MacOSX Hints

With Mac OS X Tiger (10.4.8, to be exact), Mail.app 2 (2.1.1) and Thunderbird 1.5 (1.5.0.7) the import into Mail.app is very straightforward for importing the Local Folders and Inbox from a Thunderbird POP account. I did this as two imports, first the Local Folders, then the INBOX

Before doing anything, use Thunderbird to “Compact Folders” (which removes messages that have been marked as deleted in your folders).

1) in Mail, select File -> Import Mailboxes, then select Other 2) select the folder (HOME)/Library/Thunderbird/Profiles/Default.lay/Mail/Local Folder 3) Mail then finds all the importable mbox files therein, and all the nested folders and files as well. Confirm the import

Then repeat, but using (HOME)/Library/Thunderbird/Profiles/Default.lay/Mail/(account name) as the base for the import

This leaves you with two new top-level folders in Mail.app: Import and Import-2. You can then rename and re-arrange as needed for your purposes