-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
96 lines (81 loc) · 1.46 KB
/
utils.sh
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
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
#
# Utility functions
######################################################################
#
# Testing functions
# Is the given variable non-null?
function defined()
{
test "X${1}" != "X"
}
# Is the given variable undefined?
function undefined()
{
test "X${1}" = "X"
}
# Is the given value a valid file?
function is_file()
{
$(defined ${1}) && test -f ${1} -a -r ${1}
}
# Is the given value a valid directory?
function is_dir()
{
$(defined ${1}) && test -d ${1} -a -r ${1}
}
# Given a list of potential directories, filter those that don't exist
function filter_dirs()
{
local exist
for dir; do
if $(is_dir ${dir}) ; then
if $(defined ${exist}) ; then
exist+=" "${dir}
else
exist=${dir}
fi
fi
done
echo $exist
}
######################################################################
#
# Print warning
warn()
{
echo $* 1>&2
}
######################################################################
#
# Are we root?
#
function am_root()
{
test $UID -eq 0
}
function am_not_root()
{
test $UID -ne 0
}
######################################################################
#
# Are we on a remote machine?
#
function am_remote()
{
defined "${SSH_CLIENT}"
}
######################################################################
#
# Are we interactive?
#
function am_interactive()
{
# Checking for -i file in invocation arguments
if [[ "$-" == *i* ]] ; then
return 0
else
return 1
fi
}