-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexample.bash
More file actions
123 lines (104 loc) · 2.06 KB
/
example.bash
File metadata and controls
123 lines (104 loc) · 2.06 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
#!/usr/bin/env bash
########################################################
# Author: lfkdev #
# Info: example usage script #
# License: MIT (c) #
########################################################
# color pallet
readonly cf="\\033[0m"
readonly red="\\033[0;31m"
readonly green="\\033[0;32m"
readonly yellow="\\033[0;33m"
readonly purple="\\033[0;35m"
is_debug=false # debugmode
trap exit_EXIT EXIT
trap exit_CTRL QUIT SIGINT
main() {
example
}
example() {
info "Information"
warn "Warning!"
succ "Success!"
debug "Debug"
}
err() {
local _date
_date=$(showdate)
echo -e "[$_date][${red}ERROR${cf}]: $1" 1>&2
}
err_die() {
local _date
_date=$(showdate)
echo -e "[$_date][${red}ERROR${cf}]: $1 -> use -h parameter for help." 1>&2
echo -e "[$_date][${red}ERROR${cf}]: Cleaning & Exiting."
if [[ "$2" == "1" ]]; then
showhelp
fi
exit 1
}
warn() {
local _date
_date=$(showdate)
echo -e "[$_date][${yellow}WARNING${cf}]: $1"
}
info() {
local _date
_date=$(showdate)
echo -e "[$_date][INFO]: $1 "
}
succ() {
local _date
_date=$(showdate)
echo -e "[$_date][${green}SUCCESS${cf}]: $1"
}
showdate() {
local _date
_date=$(date +%d-%H.%M)
printf "%s" "$_date"
}
debug () {
local _date
_date=$(showdate)
if [[ "$is_debug" == "true" ]]; then
echo -e "[$_date][${purple}DEBUG${cf}]: $1"
fi
}
exit_EXIT() {
info "Script ended! Cleanup & Exit."
cleanup
exit 1
}
exit_CTRL() {
err "User pressed CTRL+C!"
exit 1
}
cleanup() {
info "cleanup.."
}
showhelp() {
echo " Help:"
echo " Usage: $0 [-d] / [-h]"
echo " Where:"
echo " -d: For optional debug messages."
echo " -h: Shows this help text."
echo ""
echo " Example:"
echo " Info:"
echo ""
}
while getopts ":hd" o; do
case "${o}" in
h)
showhelp
exit 1
;;
d)
is_debug=true
;;
*)
err "No valid option choosed."
;;
esac
done
main