rc.cygwinxp-user 1.56 KB
Newer Older
1 2 3 4 5 6
#!/bin/bash
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004 University of Utah and the Flux Group.
# All rights reserved.
#
Russ Fish's avatar
Russ Fish committed
7 8 9 10
# CygWin user setup for each rdesktop login.  This gets run from a Registry key:
#   HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\EmulabLogin
# with value: 
#   C:\cygwin\bin\bash /usr/local/etc/emulab/rc/rc.cygwinxp-user
11 12
#
# We also arrange for this to be run by login shells under ssh.
13

14
PATH=/usr/local/etc/emulab:/bin:`cygpath -u "$SYSTEMROOT/system32"`:$PATH
Russ Fish's avatar
Russ Fish committed
15
export PATH
16

17
# Samba server.
18
host=fs
19

20
# Explanation: Shares are local to the Win32 login session context.
21 22
# We must process a user name and password for the first one to be opened, and it
# has to go onto a drive letter.  After that, we can use UNC //host paths freely.
23

24 25 26 27 28 29
# Nothing to do if the mount has already been done.
if (net use | grep -q Z:); then
    ##echo "Remote directories have already been enabled by a Z: mount."
    ##sleep 5
    exit 0
fi
30

31 32
# Get the password for the user.
user=`id -un`
33 34 35 36
# Root isn't a real login, use the swapper's login instead.
if [ $user == root ]; then
    user=`tmcc creator | sed 's|.*SWAPPER=\([^ ]*\).*|\1|'`
fi
37
pswd=`tmcc accounts windows | awk '/^ADDUSER LOGIN='$user' /{print substr($0,index($0," PSWD=")+6,8)}'`
38 39 40 41 42
if [ -z "$pswd" ]; then
    echo "No account for user $user, so no remote file access."
    sleep 5
    exit 1
fi
Russ Fish's avatar
Russ Fish committed
43

44
echo "Connecting Z: to //$host as $user."
Russ Fish's avatar
Russ Fish committed
45
if ! net use Z: '\\'$host'\'$user "$pswd" /user:$host'\'$user /persistent:no; then
46 47 48 49 50
    echo "Connection failed."
else
    # Show network mount status.
    net use
fi
51

52 53
sleep 5
exit 0