-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmountsmb
executable file
·57 lines (53 loc) · 1.49 KB
/
mountsmb
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
#!/bin/bash
set -e
unmount=0
PARAMS=`getopt -n $0 -o u --long unmount -- "$@"`
eval set -- "$PARAMS"
while true ; do
case "$1" in
-u|--unmount) unmount=1; shift ;;
--) shift ; break ;;
esac
done
passfile="$HOME/.config/smbcredentials"
MOUNT=$(which mount.cifs)
if [ $(hostname) = 'astoria' ] ; then
DESTDIR="$HOME/Shares/"
SHARES=('video' 'applications' 'games' 'backup')
SMB_HOST="newport"
else
DESTDIR="$HOME/Partages/"
SMB_HOST="nagano"
SHARES=('qweb' 'public')
fi
if [ ! -f $passfile ] ; then
touch $passfile
chmod 600 $passfile
SMB_USER=$(zenity --entry --title "Enter the username")
SMB_PASSWD=$(zenity --password)
echo "username="${SMB_USER} > $passfile
echo "password="${SMB_PASSWD} >>$passfile
fi
if [ ! $MOUNT ] ; then
echo "smbfs is not installed"
sudo apt-get install -y smbfs
fi
for share in ${SHARES[*]} ; do
if [ 1 = $(mount | grep ${DESTDIR}${share} | wc -l) ] ; then
echo "$share already mounted"
if [ $unmount = 1 ] ; then
echo "unmounting "$share
umount ${DESTDIR}${share}
fi
else
if [ $unmount != 1 ] ; then
echo -ne "Mounting "
mkdir -p ${DESTDIR}${share}
chown ${USER}:${USER} ${DESTDIR}${share}
full_path="//"${SMB_HOST}/${share}
echo $full_path
sudo mount -t cifs -o credentials=$passfile,uid=$(id -u $USER),gid=$(id -g $USER) \
$full_path ${DESTDIR}${share}
fi
fi
done