-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.sh
More file actions
executable file
·65 lines (51 loc) · 1.11 KB
/
utils.sh
File metadata and controls
executable file
·65 lines (51 loc) · 1.11 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
#!/bin/bash
# A set of pre-defined variables and common functions used by Nextoo scripts
BOLD="\e[1m"
RED="\e[31m"
GREEN="\e[32m"
RESET="\e[0m"
YELLOW="\e[33m"
set -e
function getDateTimestamp() {
if [[ "${PRINT_DATE_TIMESTAMP}" == 'true' ]]; then
echo "$(date +%Y-%m-%d\ %H:%M:%S) "
fi
}
function debug() {
if [[ "${DEBUG}" == 'true' ]]; then
echo -e "${RESET}$(getDateTimestamp)${BOLD}${YELLOW}${*}${RESET}"
fi
}
function finish() {
local x=$?
if [[ "$x" -ne '0' ]]; then
error "Unsuccessful completion, you may need to clean up now..."
else
status "Completed successfully"
fi
return $x
}
function error() {
echo -e "${RESET}$(getDateTimestamp)${RED}${BOLD}${*}${RESET}" >&2
}
function run() {
local x=0
debug "exec \"$*\""
"$@" || x=$?
if [[ "$x" -ne '0' ]]; then
error "Running command \"$*\" failed with exit code $x"
fi
return $x
}
function status() {
echo -e "${RESET}$(getDateTimestamp)${BOLD}${*}${RESET}"
}
function ensure_root() {
if [[ $EUID -ne 0 ]]; then
error "You must be root to run this script"
exit 1
fi
}
function define() {
IFS='\n' read -r -d '' ${1} || true
}