-
Notifications
You must be signed in to change notification settings - Fork 0
/
nisabamount
executable file
·60 lines (50 loc) · 1.37 KB
/
nisabamount
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
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run via sudo"
exit 1
fi
if [ "$#" -ne 3 ]; then
echo "Usage: $0 MGBid sharename mountpoint"
exit 1
fi
CREDFILE=$(getent passwd $SUDO_USER | cut -d: -f6)/.cred
function finish {
rm -f $CREDFILE
}
trap finish EXIT
MGBID=$1
SHARENAME=$2
MOUNTPOINT=$3
SERVER=nisaba
if [ ! -d "$MOUNTPOINT" ]; then
echo "$MOUNTPOINT" must be an empty directory
exit 1
fi
if ls -1qA "$MOUNTPOINT" | grep -q . ; then
echo "$MOUNTPOINT" must be an empty directory
exit 1
fi
if [ $(hostname) == "micc" ];then
nodes="1 2 3 4 5"
nodename=node
else
nodes="1 2 3 4"
nodename=mickey-node
fi
echo -n "Going to mount //${SERVER}/${SHARENAME} on $(readlink -f $MOUNTPOINT) as $MGBID. OK? (y/n): "
read -r answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
read -s -p "MGB password: " MGBPASS
echo
touch $CREDFILE
chmod 400 $CREDFILE
echo -e "username=$MGBID\npassword=$MGBPASS\ndomain=PARTNERS\n" > $CREDFILE
mount -t cifs -o vers=3.0,sec=ntlmv2i,credentials=$CREDFILE,uid="$SUDO_USER" //${SERVER}/"$SHARENAME" "$MOUNTPOINT"
MOUNTPOINT=$(realpath $MOUNTPOINT)
for i in $nodes ; do
echo mounting ${nodename}${i}
sudo -u $SUDO_USER ssh ${nodename}${i} sudo /usr/local/bin/nisabamount-node "$SHARENAME" "$MOUNTPOINT" "$SUDO_USER" "$CREDFILE"
done
else
echo Aborted.
fi