Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (48 sloc) 1.53 KB
#!/bin/bash
SMGUID=0
SMBGID=0
VERSION=3.0
while getopts 'd:s:u:p:v:U:G:' flag; do
case "${flag}" in
d) DIRECTORY="${OPTARG}" ;;
s) SHARE="${OPTARG}" ;;
u) USERNAME="${OPTARG}" ;;
p) PASSWORD="${OPTARG}" ;;
v) VERSION="${OPTARG}" ;;
U) SMGUID="${OPTARG}" ;;
G) SMBGID="${OPTARG}" ;;
esac
done
if [ -z $DIRECTORY ] || [ -z $SHARE ] || [ -z $USERNAME ] || [ -z $PASSWORD ] ; then
echo "smbmount [OPTIONS...]"
echo "";
echo "Mounts a samba share as read only";
echo "";
echo "Flags:";
echo " -d Directory to mount samba share to."
echo " -s samba share ex //192.168.60.200/myshare"
echo " -u username to access samba share"
echo " -p password to access samba share"
echo " -v samba protocol version to use. for windows xp/2003 use 2.0 default: 3.0"
echo " "
echo " -U UID of user who will own files in samba share. Default: 0 (root)"
echo " -G GID of group who will own files in samba share. Default: 0 (root)"
echo " "
echo "Example"
echo "./smbmount -d /mnt/share/192.168.60.200/myshare -s //192.168.60.200/myshare -u backup -p secret -U 0 -G 100"
exit 3;
fi;
mount | grep "$DIRECTORY" > /dev/null
if [ $? -eq "0" ] ; then
echo "Already mounted"
exit 0
fi
if [ ! -d "$DIRECTORY" ] ; then
mkdir -p "$DIRECTORY"
if [ $? -ne "0" ]; then
echo "Failed to create directory"
exit 3;
fi;
fi;
mount -t cifs -o username=$USERNAME,password=$PASSWORD,dir_mode=0750,file_mode=0750,uid=$SMGUID,gid=$SMBGID,ro,vers=$VERSION "$SHARE" ""$DIRECTORY"
exit $?
You can’t perform that action at this time.