#!/bin/bash
#Download and install Lync for mac 14.0.8 using bash
USERNAME=$(ls -l /dev/console | awk '{print $3}' )
#get current username of AD user
HOME=$(sudo dscl . -read /Users/$USERNAME NFSHomeDirectory | awk '{print $2}')
#get user's home directory
MobileUsers=`dscl . read /Users/$USERNAME OriginalNodeName | grep "Active Directory"`
#do only for AD users
dmg="lync_14.0.8_140321.dmg"
give the current folder name
logfile="/private/var/log/Lyncwebupgrade.log"
log () {
echo $1
echo $(date "+%Y-%m-%d %H:%M:%S: ") $1 >> $logFile
}
#logging function
receipt='/private/var/db/receipts/com.microsoft.lync.all.lync.pkg.14.0.8.plist'
if [ -f "$receipt" ]
then
log "lync reciept found aborting"
exit 0
else
check=$(osascript -e 'tell application "System Events" to display dialog "Your Lync is out of date, please click OK to upgrade Lync" with title "Lync Sign in Details" with icon note buttons {"OK","Do Later"} default button 1')
if [[ $check =~ OK ]];
then
#kill lync if open
LYNC_PID=$(ps ax | grep "/Applications/Microsoft Lync.app/Contents/MacOS/Microsoft Lync" | grep -v grep | awk '{ print $1 }')
kill -9 ${LYNC_PID}
if [ $? = 0 ] ; then
log "Lync is open killing it now "
else
log "Lync is not running"
fi
for username in $MobileUsers
do
#this is in case user had pervious version of Lync
rm -rf $HOME/Documents/Microsoft\ User\ Data/Microsoft\ Lync\ Data/sip_*
done
log "Removed SIP dir"
if [ -f "$dmg" ];
then
#attach the dmg if its already on current folder
hdiutil attach "$dmg" -nobrowse -noverify -noautoopen
else
#dl the lync dmg
curl -O http://download.microsoft.com/download/5/0/0/500C7E1F-3235-47D4-BC11-95A71A1BA3ED/lync_14.0.8_140321.dmg
hdiutil attach "$dmg" -nobrowse -noverify -noautoopen
fi
/usr/sbin/installer -dumplog -verbose -pkg /Volumes/Microsoft\ Lync/Lync\ Installer.pkg -target / &>/private/var/log/Lyncwebupgrade.log
#install it silently
sleep 3
/usr/bin/hdiutil detach "/Volumes/Microsoft Lync"
sleep 3
rm -f lync_14.0.8_140321.dmg
#remove the dmg
#add lync icon to dock, again only for AD users
for username in $MobileUsers
do
defaults write $HOME/Library/Preferences/com.apple.dock.plist persistent-apps -array-add "tile-data file-data _CFURLString /Applications/VMware Fusion.app/ _CFURLStringType 0 "
log "Lync icon added to dock"
done
sleep 5
chown $USERNAME:"CORP\Domain Users" $HOME/Library/Preferences/com.apple.dock.plist
chmod 600 $HOME/Library/Preferences/com.apple.dock.plist
log "perms changed on dock plist"
killall -HUP cfprefsd
killall -HUP Dock
sleep 3
log "bounced dock"
else
log "user declined"
exit 0
fi
fi
exit 0
#Download and install Lync for mac 14.0.8 using bash
USERNAME=$(ls -l /dev/console | awk '{print $3}' )
#get current username of AD user
HOME=$(sudo dscl . -read /Users/$USERNAME NFSHomeDirectory | awk '{print $2}')
#get user's home directory
MobileUsers=`dscl . read /Users/$USERNAME OriginalNodeName | grep "Active Directory"`
#do only for AD users
dmg="lync_14.0.8_140321.dmg"
give the current folder name
logfile="/private/var/log/Lyncwebupgrade.log"
log () {
echo $1
echo $(date "+%Y-%m-%d %H:%M:%S: ") $1 >> $logFile
}
#logging function
receipt='/private/var/db/receipts/com.microsoft.lync.all.lync.pkg.14.0.8.plist'
if [ -f "$receipt" ]
then
log "lync reciept found aborting"
exit 0
else
check=$(osascript -e 'tell application "System Events" to display dialog "Your Lync is out of date, please click OK to upgrade Lync" with title "Lync Sign in Details" with icon note buttons {"OK","Do Later"} default button 1')
if [[ $check =~ OK ]];
then
#kill lync if open
LYNC_PID=$(ps ax | grep "/Applications/Microsoft Lync.app/Contents/MacOS/Microsoft Lync" | grep -v grep | awk '{ print $1 }')
kill -9 ${LYNC_PID}
if [ $? = 0 ] ; then
log "Lync is open killing it now "
else
log "Lync is not running"
fi
for username in $MobileUsers
do
#this is in case user had pervious version of Lync
rm -rf $HOME/Documents/Microsoft\ User\ Data/Microsoft\ Lync\ Data/sip_*
done
log "Removed SIP dir"
if [ -f "$dmg" ];
then
#attach the dmg if its already on current folder
hdiutil attach "$dmg" -nobrowse -noverify -noautoopen
else
#dl the lync dmg
curl -O http://download.microsoft.com/download/5/0/0/500C7E1F-3235-47D4-BC11-95A71A1BA3ED/lync_14.0.8_140321.dmg
hdiutil attach "$dmg" -nobrowse -noverify -noautoopen
fi
/usr/sbin/installer -dumplog -verbose -pkg /Volumes/Microsoft\ Lync/Lync\ Installer.pkg -target / &>/private/var/log/Lyncwebupgrade.log
#install it silently
sleep 3
/usr/bin/hdiutil detach "/Volumes/Microsoft Lync"
sleep 3
rm -f lync_14.0.8_140321.dmg
#remove the dmg
#add lync icon to dock, again only for AD users
for username in $MobileUsers
do
defaults write $HOME/Library/Preferences/com.apple.dock.plist persistent-apps -array-add "
log "Lync icon added to dock"
done
sleep 5
chown $USERNAME:"CORP\Domain Users" $HOME/Library/Preferences/com.apple.dock.plist
chmod 600 $HOME/Library/Preferences/com.apple.dock.plist
log "perms changed on dock plist"
killall -HUP cfprefsd
killall -HUP Dock
sleep 3
log "bounced dock"
else
log "user declined"
exit 0
fi
fi
exit 0
No comments:
Post a Comment