Created
March 9, 2012 16:49
-
-
Save talkingmoose/2007455 to your computer and use it in GitHub Desktop.
Shell script to configure Microsoft Lync user name and email address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
########################### About this script ########################## | |
# # | |
# Purpose: Populates user name and email address settings # | |
# for Lync for Mac. This script resides # | |
# in /Library/talkingmoose/Scripts and is launched # | |
# by launch agent net.talkingmoose.LyncSetup.plist. # | |
# # | |
# Created by William Smith # | |
# Last update March 9, 2012 # | |
# # | |
# Version history # | |
# 1.0 Created LyncSetup-1.0.sh script # | |
# # | |
################################################################################## | |
# Running checkSetupDone function to determine if the rest of this script needs to run. | |
# Yes, if $HOME/Library/Preferences/com.microsoft.Lync.plist file does not exist. | |
# Otherwise, assume this setup script has already run for this user and does not | |
# need to run again. | |
checkSetupDone() { | |
if [ -f $HOME/Library/Preferences/com.microsoft.Lync.plist ] ; then | |
exit 0 | |
fi | |
} | |
populateUserInformation() { | |
# Logfile | |
LOGFILE="$HOME/Library/Logs/LyncSetup.log" | |
# Script version | |
SCRIPTVERSION=$0 | |
date "+%A %m/%d/%Y %H:%M:%S Running Script: $SCRIPTVERSION" >> $LOGFILE | |
# Get current username | |
USERNAME=$( id -un ) | |
if [ $? = 0 ] ; then | |
date "+%A %m/%d/%Y %H:%M:%S User name is $USERNAME." >> $LOGFILE | |
else | |
date "+%A %m/%d/%Y %H:%M:%S ERROR! Unable to read user name." >> $LOGFILE | |
fi | |
# Look up user email address | |
# Uncomment next line for Active Directory lookup | |
EMAILADDRESS=$( dscl "/Active Directory/All Domains/" -read /Users/$USERNAME EMailAddress | awk 'BEGIN {FS=" "} {print $2}' ) | |
# Uncomment next line for local directory lookup | |
# EMAILADDRESS=$( dscl . -read /Users/$USERNAME EMailAddress | awk 'BEGIN {FS=" "} {print $2}' ) | |
if [ $? = 0 ] ; then | |
date "+%A %m/%d/%Y %H:%M:%S User email address is $EMAILADDRESS." >> $LOGFILE | |
else | |
date "+%A %m/%d/%Y %H:%M:%S ERROR! Unable to read user email address." >> $LOGFILE | |
fi | |
# Write user information to Lync preferences file | |
defaults write $HOME/Library/Preferences/com.microsoft.Lync UserIDMRU '( { LogonName = '$USERNAME'; UserID = '\"$EMAILADDRESS\"'; } )' | |
if [ $? = 0 ] ; then | |
date "+%A %m/%d/%Y %H:%M:%S User logon name set to $USERNAME and user ID set to $EMAILADDRESS." >> $LOGFILE | |
else | |
date "+%A %m/%d/%Y %H:%M:%S ERROR! Unable to set user logon name to $USERNAME and user ID to $EMAILADDRESS." >> $LOGFILE | |
fi | |
# Accept license agreement - Prevents initial license agreement from appearing for each user | |
defaults write $HOME/Library/Preferences/com.microsoft.Lync acceptedSLT140 -bool true | |
if [ $? = 0 ] ; then | |
date "+%A %m/%d/%Y %H:%M:%S License agreement accepted." >> $LOGFILE | |
else | |
date "+%A %m/%d/%Y %H:%M:%S ERROR! Unable to accept license agreement." >> $LOGFILE | |
fi | |
# Script spacer - adds a couple of blank lines to the end of the log session | |
awk 'BEGIN { print "\n" }' >> $LOGFILE | |
} | |
checkSetupDone | |
populateUserInformation | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save the above file as LyncSetup-1.0.sh into /Library/talkingmoose/Scripts.