1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Loading tuncfg and hamachi at startup... I did it!!

Discussion in 'Mac Programming' started by GirthP, Mar 22, 2008.

  1. macrumors regular

    #1
    Finally.

    If any of the specifics are wrong, please reply, I'm a beginner, and love to learn.

    I thought I'd post this thread in case anyone else ever needs this info, and was starting at the beginning like me with launchd and bash scripting.

    I wanted to startup hamachi on leopard automatically at login or boot.

    For those that don't know, leopard doesn't have a functioning GUI yet for hamachi. One must sudo tuncfg, and then start hamachi manually at the command line every time you want to run it.

    If you don't know what hamachi or tuncfg is, that's outside of the scope of this post, but I'll reply to any questions :)

    Starting at the ending.
    1) tuncfg is called from a bash script at startup

    2) hamachi start, hamachi login, and hamachi go-online networkname are called at login

    I wrote two .plist files and two bash scripts to accomplish this.

    The files

    This is the bash script that runs tuncfg. It lives in my computer at /Library/BootScripts.
    I have the script wait 30 seconds before it runs, to wait for the tun kernel extensions to load (meaningless details that were not meaningless when it wouldn't work!! ;) )
    Code:
    #!/bin/bash
    
    sleep 30s
    tuncfg
    
    Here is the script that loads hamachi. It lives in my computer at /Library/BootScripts.
    Code:
    #!/bin/bash
    
    hamachi start
    hamachi login
    hamachi go-online [I]YourNetworkNameHere[/I]
    
    
    Both of those scripts have to be chmod 770 and chown root:wheel I believe.

    The .plist files

    The first launchd .plist file goes in /Library/LaunchDaemons. It loads tuncfg at startup.

    Here it is...
    Code:
    <?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.boothamachi.launchd.boothamachi</string>
    		
    		<key>KeepAlive</key>
    		<false/>
    	
    		<key>ProgramArguments</key>
    		<array>
    			<string>/Library/BootScripts/boothamachi.sh</string>
    			<string>run</string>
    		</array>
    
    		<key>RunAtLoad</key>
    		<true/>
    	</dict>
    	</plist>
    

    And the second .plist file lives in /Library/LauchAgents. It runs at login.

    Code:
    <?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>/Library/BootScripts/loadhamachi.sh</string>
    			<string>run</string>
    		</array>
    
    		<key>RunAtLoad</key>
    		<true/>
    	</dict>
    	</plist>
    
    Okay.

    That is all the info.

    I learned about bash scripting, chmod, chown, launchd.plist, launchctl...

    This took me a few days of not getting it before it came together.

    Things to remember... change the ownership of the .plist files and scripts. Look at the Console.app readout if things aren't working. It's worth the time to learn what it is saying...

    Thanks for stopping by!
     
  2. macrumors member

    #2
    great thing only it doesn't work for me :(

    do i have to do anything with the plist files?
    What exact names do i need to name all the files?


    I will try using an automator script as a startup item and see if that works
     
  3. macrumors regular

    #3
    what do you mean "do" with the .plist files?

    I slaved over them for a day or two ;), if that's what you mean... you can check and see what is going on in the console readout.

    If you can tell me what the console is saying, I can probably help you.

    I know it's not easy, and I could have missed a step or two... so feel free to ask, or chat me up.
     
  4. macrumors member

    #4
    ended up creating an applescript that starts when my user logs on and executes the .sh file to start hamachi, works for me, so thanks for the .sh examples :)
     
  5. macrumors newbie

    #5
    Kinda confused

    Ok, i'm very new to this so let me see if i got it....
    The first 2 scripts i can create by putting them in a plaintext file with the ending .sh and they go in /Library/Bootscripts
    And the 2 plist files i can make the same way with a .plist ending and they go in /Library/LauchAgents and /Library/LauchDaemons
    How do i change the permissions? Would get info and changing it there work? or do i have to use terminal? If i do, then how do i do it?

    And finally after i do that it should work?
     
  6. macrumors newbie

    #6
    Oh and if that's easier could you either send it or tell me how? :)
     
  7. macrumors member

    #7
    i will pack up a zipped pack with a manual as soon as i have some more time on my hands, i promise!
     

Share This Page