Kaseya Community

Mac - Silent Agent Deploy / Install Script [Bash] [PKG Install]

  • Although I've found no official support for this, I've come up with a tested method of deploying Mac Agents via bash script. I've tested this on OS X 10.6-10.9.4 as well as VSA servers 6.3 - 7.0. In addition, using a packaging tool, it is possible to include this script in a payload-free package to generate an always up-to-date .PKG based installer. 

    This became necessary for me since the official Agent installer was never designed for deployment; being that it includes files that, once unzipped, are consumed upon execution. These files are located within the hidden folder '~/Agent/.KcsSetup/' and contain the unique config files required to bind the agent to your VSA server, file the agent to in a specific Organization or Group, customize the Agent icon, and deploy the initial configuration settings. 

    My initial goals:

    • Use a generic installer with switches to deploy and file the agent to specific Organizations or Groups without requiring a unique agent deployment package for each one
    • Make on-boarding easier for environments that already used ARD (Apple Remote Desktop)
    • Have a re-usable installer that is always up-to-date 

    After picking apart the installer for some time, I realized that wouldn't be completely possible. 

     

    First, my understanding of the Agent installation process:

    • A Download link for a specific agent deployment package is clicked
      • A request is sent to the server to compile a fresh agent install corresponding to the specified package ID (this happens on every download)
      • After a brief pause, the fresh KcsSetup.zip corresponding to this package ID begins downloading 
    • The KcsSetup.zip archive is expanded resulting in the following hierarchy 
      • '~/Agent/KcsSetup.app/' - This directory contains the latest (relevant to your server) generic binary for Agent installations
      • '~/Agent/.KcsSetup/' - This hidden directory contains the customizations relevant to that specific deployment package
    • KcsSetup.app is executed - This executes the binary '~./Agent/KcsSetup.app/Contents/MacOS/KcsSetup' which does the following
      • Expands the generic agent installer to '/var/tmp/KAgentSilent.mpkg'
      • Moves the contents of '~/Agent/.KcsSetup/*' to '/var/tmp/*' (this is why a second execution of the installer does not work)
      • Executes the '/var/tmp/KAgentSilent.mpkg' package install
    • The package '/var/tmp/KAgentSilent.mpkg' is dependent on the files moved from '~/Agent/.KcsSetup/*' to '/var/tmp/' for a successful install with expected results

    After understanding how the installer worked, I realized that the files needed for what I wanted to do with it contain too much information to be passed in as switches. The binary '~./Agent/KcsSetup.app/Contents/MacOS/KcsSetup' accepts switches(as noted several places in the forums and seen below) but does not accept the GROUP_OPTION or MACHINE_OPTION displayed in the dialogue. I suspect this is because a 'key' gets generated that binds an deployment package and group ID when created that is unique to that package. This key or config file is visible in the hidden directory('~/Agent/.KcsSetup/KaseyaDConf.ini')

     

    All of that being said, here is the script I came up with to get me most of the way there. 

    #!/bin/bash
    #
    # Valiant Technology
    # julio@valiant-ny.com
    # 7/29/2014
    #
    # This script allows silent command based installation of the Kaseya Agent Packages on Macs
    # Tested on OS X 10.6-10.9.4 & Kaseya 6.3 - 7.0
    #

    # Set your working environment and unique package download ID.
    # Package ID is found by copying the download link and the string after 'id='
    # Example: setupDownload("/mkDefault.asp?id=123456789")
    InstallDir="/var/tmp/InstallAgent"
    vsaURL="https://kaseya.yourcompany.com"
    agentID="123456789"

    mkdir -p "$InstallDir"
    cd "$InstallDir"
    # this curl sends the command to the VSA server to generate a fresh package for download
    # this step is important to ensuring you've downloaded the most up to date version of the package
    curl "$vsaURL/mkDefault.asp?id=$agentID" -H "Connection: keep-alive" --compressed
    # download the agent 
    curl -O "$vsaURL/install/VSA-default-$agentID/KcsSetup.zip"
    unzip "KcsSetup.zip"
    chmod 755 ./Agent/KcsSetup.app/Contents/MacOS/KcsSetup
    ./Agent/KcsSetup.app/Contents/MacOS/KcsSetup -s
    rm -R -f "$InstallDir"

     

    After coming up with this, I used a packaging tool to add it as a post-flight script to generate an empty 2KB .pkg installer that is always up-to-date and has the ability to be installed silently via 'installer -pkg ~/KaseyaInstaller.pkg -target /'.

    http://s.sudre.free.fr/Software/Packages/about.html for a GUI based packaging tool 

    https://github.com/unixorn/luggage for a more automation friendly command-line packaging tool



    Weird formatting
    [edited by: VT-Julio at 5:21 PM (GMT -7) on Jul 29, 2014]
  • Thank you so much, Julio!  Being able to deploy the Kaseya agent on the Macs using our other tools has been invaluable to us.

    Based on your work, I've created a Makefile using The Luggage.  Here's the code.  I haven't gotten variables to work yet, but otherwise I'm pretty happy with this.  My preference was to have a local copy of the installer, but I do like your approach of puling down the latest agent.

    Worth noting, I can't seem to get the /r switch working properly in this context - so when we want to upgrade the agent, we'll need to do it through the Kaseya console instead of pushing out a new version of this package.  Not a huge deal in our org, but it'd be nice if that worked (I'm pretty sure it worked with 6.5).

    https://gist.github.com/flammable/167ce9d134575fe27c3c



    Moved to a GitHub Gist, as the forums messed up my formatting.
    [edited by: flammable at 11:47 AM (GMT -8) on Nov 17, 2014]
  • Nice script had do add a user agent for Curl/Kaseya to serve Macversion of client.

    #!/bin/bash

    #

    # Valiant Technology

    # julio@valiant-ny.com

    # 7/29/2014

    #

    # This script allows silent command based installation of the Kaseya Agent Packages on Macs

    # Tested on OS X 10.6-10.9.4 & Kaseya 6.3 - 7.0

    #

    # Set your working environment and unique package download ID.

    # Package ID is found by copying the download link and the string after 'id='

    # Example: setupDownload("/mkDefault.asp?id=123456789")

    # useragent needs to get Macversion of client

    useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.56 (KHTML, like Gecko) Version/9.0 Safari/601.1.56"

    InstallDir="/var/tmp/InstallAgent"

    vsaURL="https://kaseya.yourcompany.com"

    agentID="123456789"

    mkdir -p "$InstallDir"

    cd "$InstallDir"

    # this curl sends the command to the VSA server to generate a fresh package for download

    # this step is important to ensuring you've downloaded the most up to date version of the package

    curl -A "$useragent" "$vsaURL/mkDefault.asp?id=$agentID" -H "Connection: keep-alive" --compressed

    # download the agent

    curl -O "$vsaURL/install/VSA-default-$agentID/KcsSetup.zip"

    unzip "KcsSetup.zip"

    chmod 755 ./Agent/KcsSetup.app/Contents/MacOS/KcsSetup

    ./Agent/KcsSetup.app/Contents/MacOS/KcsSetup -s

    rm -R -f "$InstallDir"

    exit