Subnet Aware LANDesk Agent Deployment Startup Script for Apple/OSX

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

Happy New Year!

Happy New Year everyone! 2012

Shortcuts!

Working on a deployment solution that doesn’t create a desktop and or start menu shortcut for all users? No command line function for it? Don’t want to repackage a piece of software that already has native deployment options? No problem! Below is a VBscript you can use to create a shortcut in the All Users Desktop and/or All Users Start Menu folders on Windows XP/Vista/7.

The script is split up into sections to make it easily readable and pretty easy to configure. Simply plug in your desired options into the shortcut parameters (leaving the undesired options as empty strings “”) and deploy the script! No other editing is needed!

Shortcut Script v2.1

'********************************************************
'*  Creating Desktop and StartMenu Shortcuts                 *
'*  By Joseph Ascanio - Desktop Engineer                     *
'*                                                           *
'*  Change Log:                                              *
'*  Version 1.0  - 9/2/2011                                  *
'*  -Created the Script                                      *
'*  Version 2.0  - 11/8/2011                                 *
'*  -Created IF Statements to detect blank variables         *
'*  -Modified script structure for organization              *
'*  -Added Cleanup at the end                                *
'*  Version 2.1  - 11/8/2011                        (\(\     *
'*  -Change the shortcut creation into a function.  (='.')   *
'*  -Added a function to auto fill in extension     o(_")")  *
'*************************************************************

'Engage Saftey belt
on error resume next

'---------------------Variables and Objects---------------------
'Objects
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.shell")

'Enviroment Variables
strProgramFiles = oShell.ExpandEnvironmentStrings("%programfiles%") 'Optional
strWindows = oShell.ExpandEnvironmentStrings("%windir%") 'Optional

'Shortcut Parameters - Leave unused as "" if you do not wish to use one of them.
strStartMenuFolder = ""
strShortcutName = ""
strShortcutDescription = ""
strShortcutTarget = ""  'Target of the shortcut (if website make sure it starts in HTTP)
strWorkingDirectory = ""
strIconLocation = ""
strArguments = ""  

'Location Variables
strAllUsersDesktop = oshell.SpecialFolders("AllUsersDesktop") & "\"
strAllUsersStartMenu = oshell.SpecialFolders("AllUsersPrograms") & "\" &_
 strStartMenuFolder & "\"

'Extension Variable
ext = extension

'---------------Create the shortcuts and folders ------------

If strStartMenuFolder = "" Then
Else
	'Creating StartMenu Folder to hold goodies
	if not fso.folderexists(strAllUsersStartMenu) then
		set Folder = FSO.CreateFolder(strAllUsersStartMenu)
	end if

'Creating Icon in the StartMenu
	Set myShortcut = oShell.CreateShortcut(strAllUsersStartMenu & strShortcutName & ext)
		shortcut
	set myShortcut = nothing
end if

'Creating Desktop Icon
Set myShortcut=oShell.CreateShortcut(strAllUsersDesktop & strShortcutName & ext)
		shortcut

'Clean up
set myShortcut = nothing
set FSO = nothing
set oShell = nothing

'---------------Functions------------------

function extension()
	'Check first 4 characters for HTTP
	IF Left(strShortcutTarget, 4) = "http" Then
		'If HTTP then obviously it's a website... so give it a url extension
		ext = ".url"
	else
		'otherwise give it a .lnk extension
		ext = ".lnk"
	end if
	extension = ext
end function

function shortcut
	'Apply the shortcut parameters if the string has a value
	IF strShortcutTarget = "" Then
		else
			myShortcut.TargetPath = strShortcutTarget
		end if
		IF strArguments = "" Then
		else
			myShortcut.Arguments = strArguments
		end if
		IF strWorkingDirectory = "" Then
		else
			myShortcut.WorkingDirectory = strWorkingDirectory
		end IF
		IF strShortcutDescription = "" Then
		else
			myShortcut.Description = strShortcutDescription
		end if
		IF strIconLocation = "" Then
		else
			myShortcut.IconLocation = strIconLocation
		end if
		myShortcut.Save
end function

 

Mass Creation Security Groups in Active Directory

Creating AD security groups is always time consuming (at least when your environment is as large as ours). Thousands of groups and users all needing to be created, deleted, modified, poked and prodded. Every now and then there will be requests to create a single group for every department. This can easily become time consuming if you plan on doing this by hand. Fortunately like most Desktop Engineers.. we are lazy and would rather spend 10 min coding a quick script to accomplish this task then doing it by hand.

This script creates Security Groups in the OU defined with the name located in a CSV file using dsadd group. The concept is create the csv, double click the script and enjoy the flashing windows while your groups get created. Then it is a simple move to the proper OU and close that request. You can also use the User Mod script to add any attributes you also need before moving the objects. See this post

'###########################################'
'#  AD Security Group Creation v1.0        #'
'#                                         #'
'#     by: Brian Salvaggio - Desktop Engi  #'
'#                                         #'
'#    Change Log:                          #'
'#    9/2/2011 -- Creation                 #'
'#                                (\(\     #'
'#                                (='.')   #'
'#                                o(_")")  #'
'###########################################'

'saftey belt of some what awesomeness
On Error Resume Next

' Var's and Const's
Const strCSV = "\\path\to\file.csv"

Const ForReading = 1
Const ForWriting = 2
'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objCSVFile = objFSO.OpenTextFile(strCSV,ForReading)

'wscript.echo "Engaging AD breakage"
do While NOT objCSVFile.AtEndOfStream
		arrStr = split(objCSVFile.ReadLine , ",")
	strRun = "dsadd group -s ds03 " & chr(34) & "cn=" & arrStr(0) &_
 ",OU=Template,OU=VendorConsult,OU=School District of PBC,DC=palmbeach,DC=k12,DC=fl,DC=us" &_
 chr(34) & " -secgrp yes -scope g -samid " & chr(34) & arrStr(0) & chr(34) & " -desc " &_
 chr(34) & arrStr(1) & chr(34)
	'wscript.echo strRun
	'wscript.echo "running add group"
	objShell.Run strRun
	loop
	'wscript.echo "closing CSV File"
	objCSVFile.Close
	wscript.echo "Groups added"

Google Mail and AD Custom Attributes

     Congratulations! Your company has decided to move all corporate email to the cloud. Now you have this awesome new attribute that you must populate on all users in order to automate the creation of the GMail accounts. Well we have created a two part script for creating new accounts as well as modifying old ones. All you need is a CSV File and a wonderful free tool made by joeware.net’s AdMod 

     We use this to provision new accounts to our system that require an Email Account on our Google Apps. Exporting a CSV or creating one for new users is required. You must modify the arrStr(#) to correspond with information you would like to use. Just remember chr(34) = ” and arrays start with 0!

'###########################################'
'#  User GoogleUN Modify v1.0              #'
'#                                         #'
'#     by: Brian Salvaggio - Desktop Engi  #'
'#                                         #'
'#    Change Log:                          #'
'#    9/2/2011 -- Creation                 #'
'#                                (\(\     #'
'#                                (='.')   #'
'#                                o(_")")  #'
'###########################################'

'saftey belt of some what awesomeness
On Error Resume Next

' Var's and Const's
Const strCSV = "\\some\csv\file.csv"
Const strADMod = "\\path\to\admod.exe"

Const ForReading = 1
Const ForWriting = 2

'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objCSVFile = objFSO.OpenTextFile(strCSV,ForReading)

'wscript.echo "Engaging AD breakage" <-- begin exec the script
	do While NOT objCSVFile.AtEndOfStream
		arrStr = split(objCSVFile.ReadLine , ",")
	strRun = chr(34) & strADMod & chr(34) & " -h somedomainserver -b " &_
	chr(34) & "CN=" & arrStr(3) & ",OU=location,OU=of,OU=users,DC=domain,DC=com" &_
	chr(34) & " " & chr(34) & "GoogleUN::" & arrStr(1) & "." & arrStr(2) &_
	"@someemail.com" & chr(34) & " " & chr(34) & "mail::" & arrStr(1) &_
	"." & arrStr(2) & "@someemail.com" & chr(34)
	'wscript.echo strRun	<-- for Testing Comment run statement for view of cmd.
	objShell.Run strRun ' Oh yeah baby Mod Them Users!
	loop
	'wscript.echo "closing CSV File"
	objCSVFile.Close
	wscript.echo "Users modified"