-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskeleton.sample.sh
More file actions
141 lines (94 loc) · 2.56 KB
/
skeleton.sample.sh
File metadata and controls
141 lines (94 loc) · 2.56 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
129
130
131
132
133
134
135
136
137
#!/bin/bash
#########################
# IMPORT ENV VARS HERE ##
#########################
#########################
# ENV SETTINGS ##########
#########################
set -e # exit all shells if script fails
set -u # exit script if uninitialized variable is used
set -o pipefail # exit script if anything fails in pipe
# set -x; # debug mode
#########################
# GLOBALS ###############
#########################
declare -ra ARGS=("$@")
CALLING_DIRPATH="$(pwd)"; declare -r CALLING_DIRPATH
SCRIPT_FILENAME="$(basename "${0}")"; declare -r SCRIPT_FILENAME
SCRIPT_DIRPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; declare -r SCRIPT_DIRPATH
declare -r SCRIPT_FILEPATH="${SCRIPT_DIRPATH}/${SCRIPT_FILENAME}"
LOG_FILE="/tmp/$(date +%s).log"; declare -r LOG_FILE
#########################
# UTILITY FUNCTIONS ####
#########################
function log(){
local -r msg="${1}"
local -r full_msg="${SCRIPT_FILENAME}: ${msg}"
echo "${full_msg}" >&2
echo "${full_msg}" >> "${LOG_FILE}"
}
function error_log(){
local -r msg="${1}"
log "ERROR: ${msg}"
exit 1
}
function warning_log(){
local -r msg="${1}"
log "WARNING (1/2): ${msg}"
log "WARNING (2/2): continuing"
}
function log_func(){
local -r function_name="${1}"
log "${function_name}()"
}
function usage(){
log_func "${FUNCNAME[0]}"
}
#########################
# FUNCTIONS #############
#########################
#########################
# INIT ##################
#########################
function initialize_input(){
log_func "${FUNCNAME[0]}"
local -ra args=( "${@}" )
local is_help='false'
local is_flags='true'
local -r opts=$( getopt -o dish --long ,help -- "${args[@]}" );
eval set -- "${opts}";
while true ; do
case "${1}" in
--help)
is_help='true'
is_flags='true'
shift 1;
;;
*)
break;
;;
esac
done;
###########################
# CREATES GLOBAL VARIABLES
readonly IS_HELP="${is_help}"
readonly IS_FLAGS="${is_flags}"
# CREATES GLOBAL VARIABLES
###########################
}
function validate_input(){
log_func "${FUNCNAME[0]}"
}
function initialize(){
log_func "${FUNCNAME[0]}"
initialize_input "${ARGS[@]-}"
}
#########################
# MAIN ##################
#########################
function main(){
log_func "${FUNCNAME[0]}"
initialize
exit 0
}
main