check-and-mount-shares.sh 3.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#!/bin/sh
# Mount network shares for MacBooks.
# Nina Pollak, Jozef Reisinger, Liviu Radulescu

rm -f  $HOME/.mount_staffdata

DESKTOP="$HOME/Desktop"
LOG_FILE='/tmp/mountist.log'
username=`/usr/bin/id -un`
DOMAIN='IST.LOCAL'
IST_SHARES_FOLDER=$HOME/Desktop/IST-Net-Shares
# bash builtin echo does not support -n
ECHO_N='/bin/echo -n'

mount_ist() {
    msg="$1"
    share_point="$2"
    mount_point="$3"
    $ECHO_N "$msg"
    mount_smbfs $share_point $mount_point > /dev/null 2>&1
    [ $? -eq 0 ] && echo "done." || echo "failed."
}

date > $LOG_FILE

# Check osx version and if Snow Leopard or less don't use dfs
use_dfs=0
macversion=`sw_vers -productVersion | cut -d "." -f 2`
if [ $macversion -gt 6 ]; then use_dfs=1; fi

dfs_group="dfsgroup"
dfs_home="dfshome"
dfs_q="dfsq/$username"

# Cleanup
$ECHO_N 'Unmounting existing IST network shares ... ' &&
umount -h istsmb3.ist.local -t smbfs > /dev/null 2>&1 && 
umount -h istsmb3.ista.local -t smbfs > /dev/null 2>&1 && 
umount -h smb3.ista.local -t smbfs > /dev/null 2>&1 && 
umount -h archive3.ista.local -t smbfs > /dev/null 2>&1 && 
echo 'done.' ||
echo 'failed.'

$ECHO_N "Setting up the 'IST-Net-Shares' desktop folder ... "

# Create desktop folder holding links to mount points
if [ -d $IST_SHARES_FOLDER ]; then
    # Remove old folders
    find $IST_SHARES_FOLDER -iname .DS_Store -print -delete > /dev/null 2>&1
    for f in `echo $IST_SHARES_FOLDER/Q/*`; do rmdir $f; unlink $f; done > /dev/null 2>&1
    for f in `echo $IST_SHARES_FOLDER/*`; do rmdir $f; unlink $f; done > /dev/null 2>&1
fi
mkdir -p $IST_SHARES_FOLDER

echo 'done.'
open -g $IST_SHARES_FOLDER

#
# Main shares
#

[ ! -d $IST_SHARES_FOLDER/$username ] && mkdir $IST_SHARES_FOLDER/$username

[ ! -d $IST_SHARES_FOLDER/Idrive ] && mkdir $IST_SHARES_FOLDER/Idrive

if [ -f $HOME/.mount_staffdata -a ! -d $IST_SHARES_FOLDER/staffdata ]; then
    mkdir -p $IST_SHARES_FOLDER/staffdata
fi

echo "Mounting IST-Net-Shares ... (please be patient)"

if [ -f $HOME/.mount_staffdata ]; then
    mount_ist "Mounting staffdata ... " "//w1521030.ist.local/staffdata" "$IST_SHARES_FOLDER/staffdata"
fi

if [ $use_dfs -ne 0 ]; then
    mount_ist "Mounting Idrive ... " //istsmb3.ist.local/Idrive $IST_SHARES_FOLDER/Idrive
    mount_ist "Mounting $username home ... " "//istsmb3.ist.local/$dfs_home/$username" "$IST_SHARES_FOLDER/$username"
else
    mount_ist "Mounting Idrive ... " "//istsmb3.ist.local/Idrive" "$IST_SHARES_FOLDER/Idrive"
    mount_ist "Mounting $username home ... " "//istsmb3.ist.local/$username" "$IST_SHARES_FOLDER/$username"
fi

#
# Other shares: groups and archive
#

# Loop all the linux nis group the user belongs to
groups=`ldapsearch -LLL -x -h ldap.ista.local -b "ou=group,dc=ist,dc=ac,dc=at" memberUid=$username cn | grep cn: | cut -d " " -f 2`
for g in $groups
do
   [ ! -d $IST_SHARES_FOLDER/$g ] && mkdir $IST_SHARES_FOLDER/$g 

   # Main group share
   if [ $use_dfs -ne 0 ]; then
       mount_ist "Mounting $g ... " "//istsmb3.ist.local/$dfs_group/$g" "$IST_SHARES_FOLDER/$g"
   else
       mount_ist "Mounting $g ... " "//istsmb3.ist.local/$g" "$IST_SHARES_FOLDER/$g"
   fi
done

# User archive share
if [ $use_dfs -ne 0 ]; then
    mkdir -p $IST_SHARES_FOLDER/Q
    [ ! -d $IST_SHARES_FOLDER/Q/archive-$username ] && mkdir $IST_SHARES_FOLDER/Q/archive-$username
    mount_ist "Mounting archive-$username ... " "//istsmb3.ist.local/$dfs_q/archive-$username" "$IST_SHARES_FOLDER/Q/archive-$username"

    # Archive group share
    for g in $groups; do
        [ ! -d $IST_SHARES_FOLDER/Q/archive-$g ] && mkdir $IST_SHARES_FOLDER/Q/archive-$g
        mount_ist "Mounting archive-$g ... " "//istsmb3.ist.local/${dfs_q}/archive-$g" "$IST_SHARES_FOLDER/Q/archive-$g"
    done
fi

# Replace the imount script if it is not the current one
# curl -o $IMOUNT_COMMAND http://script.ista.local/mac/$IMOUNT > $LOG_FILE 2>&1
# chmod +x $IMOUNT_COMMAND
cd $HOME/.mac-scripts && git pull
rm "$DESKTOP/Mount IST Shares"
ln -s $HOME/.mac-scripts/mount-shares.command "$DESKTOP/Mount IST Shares"
sleep 2