Like many of us managing large desktop environments we suffer the multi-platform/geographical client locations. Recently it has come to our attention that our management program (LANDesk) is not installed on our Apple devices. Getting the agent on these devices presents a problem due to our environment being split up based on geographical location. This became a challenge when trying to identify a deployment solution that can be managed via Group Policy as well as making sure the correct agent gets installed. But have no fear! Desktopengi has created a subnet aware deployment script that enables us to deploy multiple agents from multiple core servers. This script has been tested successful on OSX 10.6.8 and 10.7.2 deploying the LANDesk agent versions sp2 and sp3. You will have to do some editing to make it work for your environment but we made it pretty simple.
This script in a nutshell determines the computers location based on the second octet of the IP address and compares it to a CSV file to identify what management server it should attach to. Then pulls the agent from the http share that LANDesk hosts based on the agent name on line 26 and installs. Everything gets logged in /var/log/landesk.log and each time the script executes it rotates that log to landesk.bak. This way if their is an issue we can check the last two script executions to identify the problem.
Credit where credit is due! Ty Ramos an Apple SE really helped us in getting the ball rolling on this script and we give him many thanks for his assistance!
The CSV should look like this:
==================================
|Friendly Name | Core Server Name | Second Octet |
==================================
Site A,ldatl,171
LANDesk OSX Agent Deployment Subnet Aware
#!/bin/sh
#' ==============================================================================
#' = Subnet/OS Aware LANDesk SS Deployment System OSX =
#' = =
#' = By: Brian Salvaggio (salvaggio.brian at gmail dot com) =
#' = With Thanks to Ty Ramos, Apple SE =
#' = =
#' = Copyright 2012 SDPBC. All rights reserved. =
#' = V: 1.2 =
#' ==============================================================================
#' = Don't forget to change line 87 to your csv store and the unmount on 113 =
#' ==============================================================================
#' = Change Log: =
#' = Added the following on 02/14/2012 =
#' = Cleaned up all mount points on exit =
#' = Added the Following on 02/14/2012 =
#' = Service Detection =
#' = Date Time for Logging =
#' = Updated mount commands to work with root on OSX Lion =
#' = Proper log rotation =
#' = Created 02/13/2012 =
#' ==============================================================================
# SETUP VARIABLES
AGENTNAME="MacC.mpkg.zip" # Name of the agent package to install:
SUBNET="" # Start with an empty SUBNET variable
# Date and Time coding for logs
date=$(date +%D)
time=$(date +%H:%M:%S)
# Setup Logging
LANDESKLOG="/var/log/landesk.log"
LANDESKBKUPLOG="/var/log/landesk.bak"
[ -f "$LANDESKLOG" ] && LOGEXISTS=1 || LOGEXISTS=0
[ -f "$LANDESKBKUPLOG" ] && BAKLOGEXISTS=1 || BAKLOGEXISTS=0
# Logfile setup
# First see if there's a backup log
if [ "$BAKLOGEXISTS" = 1 ]; then
# Remove the existing backup log
rm -rf $LANDESKBKUPLOG
fi
# Test to see if there's a regular log
if [ "$LOGEXISTS" = 1 ]; then
# backup the existing log
mv "$LANDESKLOG" "$LANDESKBKUPLOG"
# make a claen log
touch $LANDESKLOG
else
# make a clean log
touch $LANDESKLOG
fi
# Let's get started
echo "==================">>$LANDESKLOG
#check if LANDesk is Running
PROCESS=[l]dcron
number=$(ps aux | grep $PROCESS | wc -l)
if [ $number -gt 0 ];then
echo "$date $time :: LANDesk Agent is installed Exiting!!!">>$LANDESKLOG
echo "==================">>$LANDESKLOG
exit
fi
# Determine where we are (district Area)
echo "Determining district area" >>$LANDESKLOG
# Get the subnet of the interface
# First determine if the Mac is it on networking (all Macs except MBAir en0 = Wired networking)
# check wired networking
SUBNET=$(ifconfig en0 | grep "inet " | awk -F. '{if (/inet/) {print $2}}')
if [ -z "$SUBNET" ]; then
# Check Wireless/Airport networking
SUBNET=$(ifconfig en1 | awk -F. '{if (/inet/) { print $2 }}')
fi
if [ -z "$SUBNET" ]; then
echo "$date $time :: ERROR - SUBNET UNABLE TO BE DETERMINED">>$LANDESKLOG
echo "==================">>$LANDESKLOG
exit
fi
# Mount the share containing the CSV we want to parse
echo "$date $time :: mounting the ldcore...">>$LANDESKLOG
osascript -e 'mount volume "smb://User:Password@Server/SHARENAME"'
# FIND the second Octet in the file and stuff it into variable LOCATION
echo "$date $time :: Determining location...">>$LANDESKLOG
LOCATION=$(awk -v subnet="$SUBNET" 'BEGIN {FS = ","}; {if ($0 ~ subnet) {print $2}}' /Volumes/conf/landesk.csv)
echo "$date $time :: Location determined to be: $LOCATION">>$LANDESKLOG
# Pull Agent (curl off a location)
echo "$date $time :: pulling proper agent from http://$LOCATION/ldlogon/mac/$AGENTNAME">>$LANDESKLOG
curl http://$LOCATION/ldlogon/mac/$AGENTNAME -o /tmp/$AGENTNAME
# extract the downloaded agent
echo "$date $time :: extracting the downloaded .zip...">>$LANDESKLOG
tar -xf /tmp/$AGENTNAME -C /tmp
# install the LanDesk Agent
echo "$date $time :: installing the extracted .mpkg...">>$LANDESKLOG
installer -pkg /tmp/LDMSClient.mpkg -target /
echo "$date $time :: Installation complete, Checking if services are running">>$LANDESKLOG
#check if LANDesk is Running
number=$(ps aux | grep $PROCESS | wc -l)
if [ $number -gt 0 ];then
echo "$date $time :: LANDesk Agent is installed Exiting!!!">>$LANDESKLOG
echo "==================">>$LANDESKLOG
echo "Unmounting Conf directory on LDCore">>$LANDESKLOG
umount /Volumes/SHARENAME
exit
fi