-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_utils.sh
executable file
·80 lines (67 loc) · 1.57 KB
/
file_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
#!/bin/sh
remove_path() {
path="$1"
host="$2"
user="$3"
port="$4"
[ -n "$port" ] && port_flag="-p$port"
if [ -z "$host" ]; then
rm -rf "$path"
else
if [ -z "$user" ]; then
ssh $port_flag $host "rm -rf \"$path\""
else
ssh $port_flag $user@$host "rm -rf \"$path\""
fi
fi
}
create_directory() {
path="$1"
host="$2"
user="$3"
port="$4"
[ -n "$port" ] && port_flag="-p$port"
if [ -z "$host" ]; then
mkdir -p "$path"
else
if [ -z "$user" ]; then
ssh $port_flag $host "mkdir -p \"$path\""
else
ssh $port_flag $user@$host "mkdir -p \"$path\""
fi
fi
}
create_link() {
target="$1"
link_path="$2"
host="$3"
user="$4"
port="$5"
[ -n "$port" ] && port_flag="-p$port"
if [ -z "$host" ]; then
ln -s "$target" "$link_path"
else
if [ -z "$user" ]; then
ssh $port_flag $host "ln -s \"$target\" \"$link_path\""
else
ssh $port_flag $user@$host "ln -s \"$target\" \"$link_path\""
fi
fi
}
test_nonexistent_link() {
link_path="$1"
message="$2"
host="$3"
user="$4"
port="$5"
[ -n "$port" ] && port_flag="-p$port"
if [ -z "$host" ]; then
[ ! -L $link_path ] && echo "$message"
else
if [ -z "$user" ]; then
ssh $port_flag $host "[ ! -L \"$link_path\" ] && echo \"$message\""
else
ssh $port_flag $user@$host "[ ! -L \"$link_path\" ] && echo \"$message\""
fi
fi
}