Wednesday, April 2, 2008

OSX Leopard hamachi auto start

For those of you waiting to have a Leopard compatible gui for hamachi... This should help for now. This will get you up and running with the command line.


The following should start tuncfg on boot (as root) and then hamachi will start up on login.


First install the leopard tun/tap drivers.

You need to make sure that Xcode tools are installed (you can install them from your leopard disc -- find them under optional installs) or them from Apple's Developer connection. If this is not installed you will get an error when attempting to use "make".

You will them be able to install hamachi.

After you get hamachi working properly from the command line.... use the follow (very rough) steps to get it to auto-start for you.




Here's what I did:



created directory:

sudo mkdir /Library/BootScripts

created file:

sudo vi /Library/BootScripts/loadtuncfg.sh

filecontents of loadtuncf.sh

----- snip -----

#!/bin/bash

sleep 30
/usr/sbin/tuncfg

------- end of snip ------

sudo chmod 755 /Library/BootScripts/loadtuncfg.sh
(file is owned by root:admin on my machine)


created file:

sudo vi /Library/LaunchDaemons/com.loadtuncfg.launchd.loadtuncfg.plist



file contents of com.loadtuncfg.launchd.loadtuncfg.plist:


-------snip---------


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.loadtuncfg.launchd.loadtuncfg</string>

<key>KeepAlive</key>
<false/>

<key>ProgramArguments</key>
<array>
<string>/Library/BootScripts/loadtuncfg.sh</string>
<string>run</string>
</array>

<key>RunAtLoad</key>
<true/>
</dict>
</plist>


----------end of snip -----


All of the above should start tuncfg on boot (after 30 sec delay).




Now to start hamachi after local user login...

Make sure to change "yourusername" to the user that you use. Even in the .plist file below.




created directory: (notice not using sudo)

mkdir /Users/yourusername/Library/LoginScripts/

created file: (notice not using sudo)

vi /Users/yourusername/Library/LoginScripts/loadhamachi.sh

file contents of loadhamachi.sh:

-------- snip --------

#!/bin/bash
sleep 40
hamachi start
hamachi login
hamachi go-online yournetworkname

---- end of snip -----

chmod 755 /Users/yourusername/Library/LoginScripts/loadhamachi.sh
(file is owned by yourusername:yourusername)

created directory: (notice not using sudo and directory may already exist)

mkdir /Users/yourusername/Library/LaunchAgents


created file: (notice not using sudo)

vi /Users/yourusername/Library/LaunchAgents/com.loadhamachi.launchd.loadhamachi.plist

file contents of com.loadhamachi.launchd.loadhamachi.plist:

--- snip ----

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.loadhamachi.launchd.loadhamachi</string>

<key>KeepAlive</key>
<false/>

<key>ProgramArguments</key>
<array>
<string>/Users/yourusername/Library/LoginScripts/loadhamachi.sh</string>
<string>run</string>
</array>

<key>RunAtLoad</key>
<true/>
</dict>
</plist>

------ end of snip ------

file is 644 (as created and owned by youusername)


Now reboot...

tuncfg will load in 30 seconds after boot up..

hamachi will load 40 seconds after login.. (delayed longer to ensure that tuncfg loaded)..

(Credit: Most of this was from GirthP post at http://forums.macrumors.com/showthread.php?t=458736)



I hope this helps.

5 comments:

darwin said...

Thanks for great walkthrough. It worked for me with two minor changes:

1. When I followed hamachi readme, I probably did "sudo hamachi-init", and I ended with ~/.hamachi folder set to root/staff rights. I have fixed it with call: sudo chown -R myusername ~/.hamachi

2. I also needed to add some extra sleep time into shell scripts (set 60 seconds for tuncfg and 80 for hamachi start

David | Feed Me A Stray Cat said...

Thanks for the walkthrough. Worked like a charm. :)

Anonymous said...

Unfortunately this excellent walkthrough still isn't working for me.

Each folder is in the correct place, each file has the correct permissions, and I created each via the command line with and without sudo as your guide instructs.

I've tried adding to the timeout and chown-ing the ~/hamachi folder like Antonin suggested, but to no avail.

Basically when I run hamachi list at command line after boot up I find that neither hamachi or tuncfg have started.

Any ideas would be greatly appreciated!

Anonymous said...

Just a comment to insure any follow up comments are emailed to me...

Greg said...

Thanks!! It worked for 10.4 Tiger !!