-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.checks.rc
68 lines (60 loc) · 1.46 KB
/
.checks.rc
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
#!/bin/sh
_CHECKS_DIR=`dirname "$(readlink -f "$0")"`
# --------------------
# If log functions do not exist, define some simple ones.
[[ $(type -t _log_error) ]] || _log_error() {
echo "[ERR] $1"
}
[[ $(type -t _log_warning) ]] || _log_warning() {
echo "[WRN] $1"
}
# --------------------
# Check functions
_check_file_exist() {
if [[ ! -f "$1" ]]; then
_log_error "'$1' does not exists."
exit 1
fi
}
_check_file_not_exist() {
if [[ -f "$1" ]]; then
if [[ "$2" == "overwrite" ]]; then
_log_warning "'$1' already exists and will be overwritten."
rm "$1"
if [[ -f "$1" ]]; then
_log_error "Fail to remove '$1'."
exit 1
fi
else
_log_error "'$1' already exists."
exit 1
fi
fi
}
_check_dir_exist() {
if [[ ! -d "$1" ]]; then
if [[ "$2" == "mkdir" ]]; then
_log_warning "'$1' does not exist and will be created."
mkdir -p "$1"
if [[ ! -d "$1" ]]; then
_log_error "Fail to create '$1'."
exit 1
fi
else
_log_error "'$1' does not exist."
exit 1
fi
fi
}
_check_dir_not_exist() {
if [[ -d "$1" ]]; then
_log_error "'$1' already exists."
exit 1
fi
}
_check_drive_exist() {
if [[ -d "$1/" ]]; then
_log_error "$1 already exists."
exit 1
fi
}