OS X

Topic Table of Contents

  1. How do I create and run shell scripts in OS X?
  2. Where is.... and How do I....?
  3. rsync connection refused
  4. how to create startup items is os x
  5. Installing MySQL in OS X
  6. UFS vs HFS+
  7. preserving OS X meta data with rsync
  8. Moving the user space to a different partition
  9. Startup Keys
  10. G2 OS X setup

How do I create and run shell scripts in OS X?

Text files can be run as shell scripts in several ways.

  1. save the text file with a .app extension and change the permissions to allow execution
  2. drag the text file to the terminal icon in the dock or applications folder
  3. set the application to "open with" as the terminal.

Where is.... and How do I....?

Where is the apache web server config file

/etc/httpd/httpd.conf

How Do I enable php on the local apache

#LoadModule php4_module     libexec/httpd/libphp4.so
#AddModule mod_php4.c
But I lest of the libexec/httpd/libphp4.so bit and it seems to work

How do get mysql to be a recongnized command

rsync connection refused

When I run rsync on OS X I get. This is both with the fink installed on and the reqular one (in /usr/bin/)

The version in /usr/bin is 2.5.7 and the fink version is 2.5.5

jupiter:~ rcortesi$ rsync -v rcortesi@192.168.1.103:mytestfile ~/scripts/.
192.168.1.103: Connection refused
rsync: connection unexpectedly closed (0 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(150)

rsync maybe trying to connect using rsh not ssh

This link, http://lists.samba.org/archive/rsync/2003-September/007163.html

seems to address the problem I'm having. It looks like rsync is trying to connect using rsh not ssh. which both my backup machine and phpwebhosting won't allow.

I only use ssh and set the RSYNC_RSH environment variable.

so now I just need to figure out how to set that environment varible

So I ran the command

export RSYNC_RSH=ssh
and now rsync works correctly in that terminal window. But not the others because environment varible was only set for that particular terminal session. So now I need to figure out how to make that a perment environment variable.

I added the line

RSYNC_RSH=ssh; export RSYNC_RSH
to /etc/profile along with some comments explaining why the line is there.

how to create startup items is os x

This url, http://www.osxfaq.com/Tutorials/LearningCenter/HowTo/Startup/index.ws has a good dicussion of creating startup items in OS X and it used mysql as the example.

Installing MySQL in OS X

I have tried installing MySQL both from fink and the binary distribution. I was working and then I think I messed up the user privliges. So I tried uninstalling and reinstalling using a variety of techniques.

This page on the apple the website has a pretty good discussion of installing it.

permission problem for MySQL 4.0.18 in OS X

This page, http://lists.mysql.com/mysql/161985 described the exact problem I was having with installing MySQL in OS X

Next I'll try installing version 4.0.17 as the page recommends.

This page, http://www.entropy.ch/software/MacOSx/mysql/ is also a good resource for installing MySQL on OS X

Successfull install from source

Installing from the source code (the .tar.gz file) worked by following the instructions here.

http://developer.apple.com/internet/opensource/osdb.html

Mysql now can be run from the command line.

Now I just have to get phpAdmin working.

mysqld options

The man page for mysqld has some good information on starting mysqld.

I think I need to try running mysqld as root with a user (mysql) specified. as a way of starting the server.

phpMyAdmin still can't connect

I entered localhost everywhere in the config.ini.php file for phpmyadmin everywhere I could find looked appropriate. but I still got the same error message.

The odd part is that the error message says it is looking for the socket path in /tmp, not in /usr/local/mysql/run/mysql_socket

phpMyAdmin fixed

I had to change the host to 127.0.0.1, jupiter would expand the external ip address and the server could use that for connection. Using "localhost" caused the
can't connect to socket at /tmp/mysql_socket
error

Install working but wierd

well I have gotten the install working. But there are some strange things.

when connecting via php I have to provide a socket path

/usr/local/mysql/run/mysql_socket

Is there a way of setting the default socket for php?

I creates a mysql user called rcortesiwith a password that matches my webhosting one. This is to allow php pages built here to be moved to php webhosting and the same connection settings to be used. I had to use the MySQL PASSWORD function to add the password the user rcortesi to allow php mysql_connect command to work with the password.

UFS vs HFS+

Here is an article discussing

An Rsync and HFS discussion

So Tom,

I'm continuing the thread of conversation we were having taking advantage of cheap intel based hardware to build secure network storage devices, (I figure chris will have some thoughts on this two).

I have finally ordered a couple of extra drives for my linux box upstairs so I can start experimenting with opendarwin, FreeBSD, and Linux.

I have been doing some more reading on the topic.

One option is format a parition on the mac harddrive as UFS and use this partition for all your media storage. And keep a HFS+ partition for applications and the OS X system files.

On UFS partitions OS X stores the resourse forks as hidden files. So rsync should be able to get to all of them. and restore them back again. This would allow much more flexibility in the choise of operating system on the backup box. I'm not sure how robust Darwin is. There are ports of HFS+ for linux and freeBSD but I have not gotten much of confidence in them from reading about them on the web (mainly because there just doesn't seem to be a lot written about them), but I'll try them out.

I also found this quote here:

Files residing on HFS and HFS+ file systems have their Finder attributes stored in a private fork separate from both resource and data forks. These attributes include type and creator codes. Mac OS X maintains these attributes because they enable the Finder to enhance the user’s experience

Which leads me to believe that the only thing that "should" be lost in the HFS+ ----> Linux/BSD ----> HFS+ would be this finder attibutes like (file creator, file type, finder file comments). If the OS is configured correctly it should be able to determine which app to use to open the file from the extension.

Another quote from the Apple Website:

Finder Attributes:

Finder attributes (also known as Finder Info) can be associated with files and folders in the Mac OS X file system. These attributes affect how the Finder displays or handles these files and folders. The Finder recognizes attributes such as the bundle bit, invisible bit, type code, creator code, label, custom icon, and many other attributes.

In Mac OS X the Finder stores attributes in an invisible per-folder file that contains a data structure that is extensible and volume-format “agnostic.

A comparison of HFS+ and UFS

preserving OS X meta data with rsync

Experiment 1:

  1. I created at disk image in OS X and set its type to UFS.
  2. I created a BBEdit text file and saved it to the new volume (called testimage)
  3. In the finder I added a comment.
  4. from the command line listing all (ls -a) the files in /Volumes/testimage you can see the bbedit file mytest and a hidden file ._mytest.
  5. I used rsync
    rsync -avz /Volumes/testimage/ rcortesi@192.168.1.106:/bigdrive/backuptest/
    To copy the contents of the directory over.
  6. both files were copied. I deleted the original bbedit file in /Voumes/testimage (the OS did delete the hidden file automatically)
  7. I rsync'ed to recover the file from the linux box.
  8. Both mytest and ._mytest were recovered. And OS correctly associated the file with BBEdit (ie it gave it the BBEdit Icon).
  9. The comment entered from the finder was NOT preserved though

Experiment 2:

  1. Same as above but after rsync'ing to the linux box I deleted the ._mytest from the linux box.
  2. When I rsync'ed linux -> mac the mac had no idea what the file type was.

Experiment 3:

  1. I applied a color label and rsync'ed it to the linux box, deleted the origenal, and recovered it.
  2. The color label was preserved.

Experiement 4:

  1. created a sub directory. Put some files in it
  2. from the file info screen on the dir, I indexed the directory and rsync'ed that
  3. The index was preserved.

Conclution

Most of the files meta data is stored in the ._filename. But the comments are stored somewhere else.

Moving the user space to a different partition

An article on setting up OS X from scratch

moving the users directory to another partition in Jaguar

a MacOSXhints article on moving the swap drive

Startup Keys

Listing of OS startup keys

G2 OS X setup

Here are some notes discussing my second generation OS X setup.

Paritioning

I set up the paritions on internal laptop harddrive as follows:
NameSizeFormatRemarks
sysa8 GigHFS+System Parition A
sysb8 GigHFS+System Parition B, periodically updated to match A, so I can experiment with different system configuations, and recover if one fails.
appland16 GigHFS+a place to store non-apple apps
userland50 GigUFSA place to remap user's home directories too. The UFS format allows more flexibility in backing up user paritions to other computers

Moving the User's home directory to a UFS partition

This article describes how to move the user's home directory to a different partition in Jaguar. I got the idea from it, and then had to deviate when I could not get the niuntil command to work.

userland is the name of my UFS partition for users.

First I copied the current user directory to new partition using ditto. This will convert HFS+ resource forks to the hidden "._" files when copying to file systems that don't support resource forks.:

sudo ditto -rsrc /Users/ Volumes/userland/Users

Second, rename the /Users directory on the system parition to a different name, and create a soft link to the new Users directory.

sudo mv /Users /Users_old
sudo ln -s /Volumes/userland/Users /Users

To test if the new path is working. Create a test file in /Volumes/userland/Users/yourusername. Log out and log back in. When you open your directory home directory in the finder you should see 1) your test file and 2) folders with special icons (desktop, documents, library, etc).

You can also add users from the system preferences and you can see that their home directory will be created on the partition userland.

Finally once you have satisfied yourself that your new users partition is working correctly you can get rid of your old users directoy on the file system partition.

sudo rm -dr /Users_old

Setting up the Applications Partition

I have a separate HFS+ partition for installing non-apple applications. I left the /Applications directory on the root file system with the applications that the apple installer installed because I came across and article on the web about how moving the /Applications directoty to a different partition cause some problems. I have NOT verified that moving it does cause problems.

So my solution was to create a separate HFS+ for the applications I install after the initial system install. This would allow me to reinstall the system software without having the reinstall all the apps that I installed afterwards. It also allows me to have multiple system paritions and I can boot from and I don't have to maintain duplicates of all my applications.

I selected HFS+ as the file format incase there were apps that actually used the resource fork and would not play nice with OS X splitting it into sperate files on a UFS partition.

I created a 16 Gig partition called appland and Created a directory in it called myapps. Then I created a soft link to the this directory in the /Applications.

sudo ln -s /Volumes/appland/myapps /Appications/myapps

Installing X11

First I installed the Apple Developer Kit, including the X11 SDK.

The I downloaded and installed the apple X11 implementation.

To see if fink recognizes that I installed the apple X11 system I ran:

shell>fink-virtual-pkgs

....bunch of non-x11 virtual packages listed...

Package: system-xfree86
Status: install ok installed
Version: 2:4.3-2
description: [placeholder for user installed x11]
provides: xserver, x11, libgl, xft2, fontconfig1, rman, xfree86-base-threaded

Package: system-xfree86-dev
Status: install ok installed
Version: 2:4.3-2
description: [placeholder for user installed x11 development tools]
provides: x11-dev, libgl-dev, xft2-dev, fontconfig1-dev
builddependsonly: true

Package: system-xfree86-shlibs
Status: install ok installed
Version: 2:4.3-2
description: [placeholder for user installed x11 shared libraries]
provides: x11-shlibs, libgl-shlibs, xft1-shlibs, xft2-shlibs, fontconfig1-shlibs,
xfree86-base-threaded-shlibs

So it appears that fink does know about apple's x11 package.

Installing Darwin Ports

Here is instructions on getting Darwin Ports. There is a more complete discussion in this chapter of the Darwin Ports Guide.

Here is the summary of what I did:

% cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/Volumes/src/cvs/od login
% cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/Volumes/src/cvs/od co -P darwinports
This creates the darwinports directory in your home directory. Now compile and install darwinports.
% cd ~/darwinports/base
% ./configure
% make
% sudo make install

Now I can install darwin ports with the following command:

% sudo port install portnamehere

This chapter on using the darwin ports lists other options for the ports command.

To be able to use the port command without having to type its full path (/opt/local/bin/port) add the following line to your .profile file (assuming you are using bash).

export PATH="/opt/local/bin/:$PATH"

Darwing ports installs binary executables in this path.

By putting the path to darwinports binaries at the begining of $PATH it means that darwinports' bin direcoty will be checked first. So if there is a version of rsync in darwinports (/opt/local/bin) and a version in /usr/bin the darwinports version will be used.

The other option is to put the darwinports path at the end of $PATH and rename the old verion file that you nolonger want to execute (/usr/bin/rsync in this example). This may be safer because then a bogus command in darwinports won't pre-empt a system function.

I'm not sure which is a better techinque.

Apps Install from Fink or Darwin Ports

Here is a list of apps that I installed from Fink or Darwin Ports:

PackageProviderRemarks
octaveFinka matlab like computational software
rsyncDarwinDarwin ports has a more current version than Fink
hfsrsyncDarwinThe HFS+ aware version on rsync
ImageMagickDarwinDawrin has more uptodate version of ImageMagick than Fink

Things to Do/Add

  • Install Carbon Copy Cloner
  • Backup sysa to sysb
  • Enable php in Apache
  • Enabe GD in php for Apache
  • Install MySQL
  • Insall phpAdmin
  • Setup CVS repository in my Home directory
  • Setup CPAN
  • Install Photoshop
  • setup ssh keys for my other computers
  • install pine
  • figure out how to back up and restore bookmarks in Safari
  • try to get mail working
  • Find other GUI mail reader which supports: IMAP, multiple accounts, and filtering to IMAP mailboxes