Desktop login and SMB/CIFS mountpoints made easy

Having lots of users with kind of “magic hands” got us to think what they did not need to think about, so they could do more of their research.

Since we got everyone on AD using Quest (see previous post) we where able to launch the following script each time they log on their Desktops, making a nice direct access to all the resource from their groups and from their research.

Also, we used the library.

#!/bin/bash -x
#===============================================================================
#
#          FILE:  fbm_logon_script_workstation.sh
# 
#         USAGE:  ./fbm_logon_script_workstation.sh 
# 
#   DESCRIPTION:  
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Joan Marc Riera Duocastella (), 
#       COMPANY: Fundació Barcelona Media
#       CREATED: 12/22/2010 11:07:00 AM CET
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error

logger -i -s "$0 - launched"
#clean temp files
LOGFILE=/$0.log
cd /tmp
exec 1>>$LOGFILE
exec 2>>$LOGFILE
SERVERIP="xxyy.tt.rrr"
SERVERPATH="scripts"
MASTERURL=http://$SERVERIP/$SERVERPATH
## Don't edit above this line
SCRIPTNAME=$0
DATETIME=`date +%Y%m%d%H%M%S`
HNAME=`hostname`
# load marcs library
tempscript="library.sh"
if [ ! -f /tmp/$tempscript ]
then
         wget $MASTERURL/lib/$tempscript -O /tmp/$tempscript
         . /tmp/$tempscript && rm /tmp/$tempscript
fi
# define environment
shootProfile
# check if USER env variable is set, or otherwise set it
[ -n "${USER:-x}" ] && USER=`whoami` 
#check if .desktop exists else do it
if [[ -f /home/$USER/.config/user-dirs.dirs ]]
then
	desktop_dir=/home/$USER/`grep XDG_DESKTOP_DIR /home/$USER/.config/user-dirs.dirs  | cut -f2 -d\" | cut -f2 -d\/`
fi
if [[ -n "${desktop_dir:+x}" ]] && [[ ! -f "$desktop_dir/montar unitat de xarxa.desktop" ]]
then
	
	case $OS in
		 linux )	
			  tempscript="fs_fbm.tar"
			  ;;
		 mac )
			  tempscript="fs_fbm_macosx.tar"
			  ;;
		 * ) #at least try if there is luck
			  tempscript="fs_fbm.tar"
			  ;;
	esac
	
	#download fs_fbm.tar
	if [ ! -f /tmp/$tempscript ]
	then
		 wget $MASTERURL/src/$tempscript -O /tmp/$tempscript
	fi
	cd /tmp
	tar -xvf /tmp/$tempscript 
	rm  /tmp/$tempscript
	cd ${tempscript%%.???}
	datasrc_dir="`pwd`/data"
	#if [[ $CANGOSUDO -eq $TRUE ]]
	#then
	#we are not installing anything on a logonscript 
	#	sudo ./install.sh 
	#else
	cp $datasrc_dir/*.desktop $desktop_dir
	chmod +x $desktop_dir/montar*.desktop
	chmod +x $desktop_dir/desmontar*.desktop
	#fi
#	rm -r /tmp/${tempscript%%.???}
fi
#############################################fbm_mount end
##########################check sudoers
 # :TODO:12/22/2010 11:09:09 AM CET:: if uptime>15 dies mail with reboot and upgrade request
uptime
exit 0

Expect script to mount the remote CIFS

#!/usr/bin/expect -f

#mount cm01 software repository

# Se definen la svariables USERNAME y PASS con el valor de los parametros que recibe el script.
set USERNAME [lindex $argv 0]
set PASS [lindex $argv 1]

# Montar //fbmcm01/software en /home/sysop/fs con los credenciales del usuario pasado como parametro
spawn mount.cifs //84.88.79.25/software /home/sysop/fs -o username=$USERNAME
#spawn mount -t cifs //84.88.79.25/software /home/sysop/fs -o username=$USERNAME
# Con la orden expect, indicamos la cadena de texto que esperamso que aparezca y con send, 
# se envia el parametro que queremso introducir de forma automatica
expect "Password:^"
sleep 5
send "$PASS\n"

expect eof

Author: Marc

https://www.linkedin.com/in/joanmarcriera/