-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfs
executable file
·69 lines (64 loc) · 3.08 KB
/
dfs
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
60
61
62
63
64
65
66
67
68
69
#! /bin/sh
# Convenience script for starting distributed filesystem client applications.
# This version of the script is meant to be sourced by sh or bash.
#
# This script has two main purposes: the first is abbreviating script startup
# commands, and the second is implementing the cd (change directory) command.
#
# Ordinarily, to run one of the client applications, one needs to issue a
# command such as
# java -jar dfs.jar touch unix.qatar.cmu.edu:/directory/some-file.txt
# With this script, the command is immediately shortened to
# ./dfs touch unix.qatar.cmu.edu:/directory/some-file.txt
# Additionally, if the user has set the current host to unix.qatar.cmu.edu and
# the current directory to directory using the cd command, it is sufficient to
# write
# ./dfs touch some-file.txt
#
# The current host and current directory are stored in the environment variables
# DFSHOST and DFSCWD, respectively. The path parser accesses these environment
# variables when the user omits the host, or does not provide an absolute path.
# The cd command, implemented in this script, sets these environment variables.
#
# Note that these environment variables must be set in the shell from which
# further commands are to be run. This usually means that the script must not
# simply be started from the shell, but must be sourced, in order for the cd
# command to work properly. So, to run the cd command, run
# . dfs cd new-host:new-directory
# where the new host may be omitted if one is already set, and the new directory
# may be either absolute or relative.
#
# To implement cd, the script interacts with the Parse application. This
# application, when given a remote path, returns the hostname and absolute path
# that the remote path refers to. If the remote path given had no hostname, the
# hostname returned is the current hostname. If the remote path given was
# relative, it is appended to the absolute current path. The results are then
# used by this script to update DFSHOST and DFSCWD.
#
# The script avoids using the exit command, as when the script is sourced, the
# exit command will cause the user's shell to quit.
# Path to the jar file to be used to launch applications.
JAR_FILE="dfs.jar"
JAR_COMMAND="java -jar $JAR_FILE"
# Check that the jar file exists. If the path is otherwise correct, it may have
# been cleaned and not rebuilt since.
if [ ! -f "$JAR_FILE" ]; then
echo $JAR_FILE does not exist
echo check that the file has been built and that the path is correct
else
# If the command being requested is cd, execute the cd command. Otherwise,
# pass the arguments to the script to the application launcher.
if [ $# = 2 -a "$1" = cd ]; then
HOSTNAME=`$JAR_COMMAND parse $2 hostname`
EXIT_STATUS=$?
if [ $EXIT_STATUS = 0 ]; then
# If the first call to parse succeeded, the second call will also
# succeed, and there is no need to check the exit code.
REMOTEPATH=`$JAR_COMMAND parse $2 path`
export DFSHOST=$HOSTNAME
export DFSCWD=$REMOTEPATH
fi
else
$JAR_COMMAND "$@"
fi
fi