Repository navigation
Expand file tree
/
Copy pathfunction.sh
More file actions
129 lines (98 loc) · 2.28 KB
/
Copy pathfunction.sh
File metadata and controls
129 lines (98 loc) · 2.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
run() {
local retval
local cmd_line=''
for cmd in "$@" ; do
if [[ -z $cmd_line ]]; then
cmd_line="$cmd"
else
cmd_line="$cmd_line $cmd"
fi
done
if "$@"; then
retval=$?
good_msg "Executed: '$cmd_line'"
else
retval=$?
bad_msg "Failed (${retval}): '$cmd_line'"
fi
return ${retval}
}
log_msg() {
if [ ${LOG_DISABLED} ]; then
return
fi
if [ ! -f "${LOG_FILE}" ]
then
touch "${LOG_FILE}"
fi
local log_prefix=
[ -n "${LOG_PREFIX}" ] && log_prefix="${LOG_PREFIX}: "
local msg=${1}
LANG=C echo "[$(date +"%Y-%m-%d %H:%M:%S")] ${log_prefix}${msg}" >> "${LOG_FILE}"
}
splash() {
return 0
}
# msg functions arguments
# $1 string
# $2 hide flag
good_msg() {
if [[ -z "$2" ]]; then
local hide_flag=0
else
local hide_flag=$2
fi
if [ -n "${QUIET}" ] && [ -z "${DEBUG}" ]; then
hide_flag=1
fi
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[OK] ${msg_string}"
if [ "$hide_flag" != '1' ]; then
printf "%b\n" "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
fi
}
good_msg_n() {
if [[ -z "$2" ]]; then
local hide_flag=0
else
local hide_flag=$2
fi
if [ -n "${QUIET}" ] && [ -z "${DEBUG}" ]; then
hide_flag=1
fi
local hide_flag=$2
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[OK] ${msg_string}"
if [ "$hide_flag" != '1' ]; then
printf "%b" "${GOOD}>>${NORMAL}${BOLD} ${msg_string}"
fi
}
bad_msg() {
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[!!] ${msg_string}"
if [ "$2" != '1' ]
then
splash 'verbose' >/dev/null &
printf "%b\n" "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
fi
}
warn_msg() {
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[**] ${msg_string}"
[ "$2" != '1' ] && printf "%b\n" "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
mkdir_ifnot_exist() {
if [[ $# != 1 ]]; then
echo "mkdir_ifnot_exist(): don't have enough arguments!"
exit 1
fi
local dir=$1
if [ ! -d $dir ]; then
run mkdir -p $dir
fi
}