-
Notifications
You must be signed in to change notification settings - Fork 0
/
plutomount
executable file
·55 lines (45 loc) · 1.3 KB
/
plutomount
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
#!/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 PLUTOid sharename mountpoint"
exit 1
fi
CREDFILE=$(getent passwd $SUDO_USER | cut -d: -f6)/.cred
function finish {
rm -f $CREDFILE
}
trap finish EXIT
PLUTOID=$1
SHARENAME=$2
MOUNTPOINT=$3
SERVER=pluto.mclean.harvard.edu
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
nodes="1 2"
nodename=mickey-node
echo -n "Going to mount //${SERVER}/${SHARENAME} on $(readlink -f $MOUNTPOINT) as $PLUTOID. OK? (y/n): "
read -r answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
read -s -p "PLUTO password: " PLUTOPASS
echo
touch $CREDFILE
chmod 400 $CREDFILE
echo -e "username=$PLUTOID\npassword=$PLUTOPASS\ndomain=SAMBA\n" > $CREDFILE
mount -t cifs -o vers=3.0,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/plutomount-node "$SHARENAME" "$MOUNTPOINT" "$SUDO_USER" "$CREDFILE"
done
else
echo Aborted.
fi