AppleScript for installing software on bunch of macs

Discussion in 'Mac Programming' started by urello, Feb 28, 2014.

  1. urello, Feb 28, 2014
    Last edited: Feb 28, 2014

    urello macrumors newbie

    Joined:
    Feb 28, 2014
    #1
    Hi,
    I have about 50 macs and i wish to control it with puppet software. I need a script that will install puppet on macs in one click (if not installed before).
    I never used applescript before so I googled a bit and wrote a following code:
    Code:
    #!/bin/bash
    FULLSTRING=""
    
    # Mounting share
    mkdir /Volumes/MacInstall
    if ! (mount | grep 'MacInstall.*afpfs' > /dev/null); then
    	if ! (mount_afp afp://192.168.1.2/MacInstall /Volumes/MacInstall/); then
    	osascript -e 'tell application "SystemUIServer" to display alert "ERROR!" message "Some error ocuured. Call admin"' 
    	exit 33
    	fi
    fi
    
    
    
    # Checking installed soft (dmg)
    for dmgname in `ls /Volumes/MacInstall/ |grep .dmg$`; do
    	searchname="com.puppetlabs.`echo "$dmgname" | cut -d - -f 1`"	
    	pkgname=`echo $dmgname | cut -d - -f 1`
    	if ! (pkgutil --pkgs |grep $searchname > /dev/null); then
    		FULLSTRING="${FULLSTRING}$pkgname "
    	fi
    done
    sleep 1
    
    
    
    if [ -n "$FULLSTRING" ]; then 
    
    #Checking user password
    osascript $FULLSTRING <<EOF
    
    set the current_user to (get the long user name of (system info)) as string
    repeat
       tell application "SystemUIServer"
       set answer to text returned of (display dialog "Enter your password" with icon caution default answer "" with hidden answer)
       end tell
    
    try 
    	tell application "SystemUIServer" to do shell script "true" user name the current_user password answer with administrator privileges
    	exit repeat
    on error --incorrect password
        tell application "SystemUIServer" to display dialog "Sorry. You entered the wrong password." buttons{"Try Again","Cancel"}
    end try
    end repeat
    
    #Installing software
    on run argv
    repeat with var from 1 to (count of argv)
    do shell script "hdiutil mount /Volumes/MacInstall/" & item var of argv & ".dmg -mountpoint /Volumes/TempAppInstall"
    do shell script "installer -package /Volumes/TempAppInstall/" & item var of argv & ".pkg" user name the current_user password answer with administrator privileges
    end repeat
    end run
    EOF
    
    fi
    umount /Volumes/MacInstall
    
    When i'm trying to run i'm getting the error
    Code:
    syntax error: The run handler is specified more than once, or there were top-level commands in addition to the run handler. (-2752)
    Any suggestions?
     
  2. chrfr macrumors 603

    Joined:
    Jul 11, 2009
    #2
    Go here and ask: https://groups.google.com/forum/#!forum/puppet-users

    You won't likely get useful feedback on Puppet here.
     
  3. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium

Share This Page