-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlib.sh
More file actions
executable file
·75 lines (65 loc) · 1.28 KB
/
lib.sh
File metadata and controls
executable file
·75 lines (65 loc) · 1.28 KB
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
#
# Remove double quotes from start and end of input
#
remove_double_quotes() {
sed -e 's/^"//' -e 's/"$//' <<< "${1}"
}
#
# Generate random string of given length
#
random_string() {
LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "${1}" | head -n 1
}
#
# Check if all dependencies are installed.
#
check_depends() {
for X in ${1}; do
if ! [ -x "$(command -v ${X})" ]; then
echo Dependency '"'"${X}"'"' not found. >&2
exit 1
fi
done
}
#
# Get absolute path, base name and extension only for file
# See https://stackoverflow.com/questions/3915040/bash-fish-command-to-print-absolute-path-to-a-file
#
fullpath() {
printf "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
}
basefilename() {
filename=$(basename -- "${1}")
printf "${filename%.*}"
}
extension() {
filename=$(basename -- "${1}")
printf "${filename##*.}"
}
#
# Check that a file exists and is readable
#
file_readable() {
if [ -n "${1}" ] && [ ! -r "${1}" ]; then
echo "Cannot read file ${1}"
exit 1
fi
}
#
# Test SSH access
#
l_test_ssh_access() {
if ! ssh "${1}" true; then
echo "Cannot access target via SSH" >&2
exit 1
fi
}
#
# File exists at path in host
#
lcopy() {
scp -rv "${1}" "${2}:${3}"
}
#
# Line exists at file
#