-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_root_dir
executable file
·86 lines (68 loc) · 2.14 KB
/
get_root_dir
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# ------------------------------------------------------------------------------
# usage
# ------------------------------------------------------------------------------
usage() {
cat <<USAGE
Usage: $0 <dir>
Description:
Get root directory based on OS and hostname
Options:
<dir>
directory name. can be one of the following:
kmk
kmr
kenrod
-h, --help
show this help message and exit
USAGE
# exit 1
}
# ------------------------------------------------------------------------------
# parse args
# ------------------------------------------------------------------------------
# if no arguments supplied, show usage
if [ $# -eq 0 ]; then
usage
exit 1
fi
if [[ $1 == "-h" || $1 == "--help" ]]; then
usage
exit 0
fi
dir_list=(kmk kmr kenrod)
if [[ ! " ${dir_list[@]} " =~ " $1 " ]]; then
# echo "error: unknown argument ($1)"
usage
bash error_msg "unknown argument ($1)"
fi
dir=$1
# ------------------------------------------------------------------------------
# main
# ------------------------------------------------------------------------------
os=`uname`
code_dir=`dirname $0`
hostname=${HOSTNAME}
if [[ ${hostname} =~ "compute-" || ${hostname} == "login-01" || ${hostname} =~ 'vdi-' ]]; then
hostname=`get_cluster_name`
fi
if [[ ${os} == 'Linux' ]]; then
root_dir=`cat ${code_dir}/root_dir.csv | grep ${dir} | grep ${os} | grep ${hostname} | awk -F, '{print $4}'`
elif [[ ${os} == 'Darwin' ]] || [[ ${os} == 'Windows_NT' ]]; then
root_dir=`cat ${code_dir}/root_dir.csv | grep ${dir} | grep ${os} | awk -F, '{print $4}'`
fi
root_dir=`eval echo ${root_dir}`
if [[ -z ${root_dir} ]]; then
error_msg "no root_dir found (os: ${os}; HOSTNAME: ${HOSTNAME}, hostname: ${hostname})"
elif [[ ! -e ${root_dir} ]]; then
if [[ ${os} == 'Darwin' ]]; then
root_dir=`echo ${root_dir} | sed "s|/Volumes|/Users/${USER}/mnt/cvl|g"`
fi
if [[ ! -e ${root_dir} ]]; then
error_msg "file does not exist (${root_dir})"
else
echo "${root_dir}"
fi
else
echo "${root_dir}"
fi