-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashtemplate.sh
More file actions
95 lines (87 loc) · 3.17 KB
/
bashtemplate.sh
File metadata and controls
95 lines (87 loc) · 3.17 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
#!/bin/bash
# ==============================================================================
# Contact : https://github.com/harkx
# Purpose :
# Name :
# Revision : v0.1
# ==============================================================================
# Change history:
# 2015.12.06 : 0.1 - initial script
# ==============================================================================
# Usage:
# sh ./bashtemplate.sh
# ==============================================================================
## RESOURCES: http://redsymbol.net/articles/unofficial-bash-strict-mode/
# -e = any failing command will cause the script to stop
# -u = treats unset variables as an error (in case an unset variable is used
set -euo pipefail # Short for: set -e, set -u and set -o pipefail
IFS=$'\n\t' # Internal Field Separator
# VARIABLES
VERSION=0.1
this_path=$(readlink -f $0) ## Path of this file
myname=`basename ${this_path}` ## this script.
# Functions
#--- FUNCTION ----------------------------------------------------------------
# NAME: __help
# DESCRIPTION: Help!
#-------------------------------------------------------------------------------
function help {
echo "
usage: $myname [options]
-h optional Print this help message
-q optional Suppress log messages on screen, just log them."
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __detect_color_support
# DESCRIPTION: Try to detect color support.
#-------------------------------------------------------------------------------
_COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)}
__detect_color_support() {
if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then
RC="\033[1;31m"
GC="\033[1;32m"
BC="\033[1;34m"
YC="\033[1;33m"
EC="\033[0m"
else
RC=""
GC=""
BC=""
YC=""
EC=""
fi
}
__detect_color_support
#--- FUNCTION ----------------------------------------------------------------
# NAME: echoerr
# DESCRIPTION: Echo errors to stderr.
#-------------------------------------------------------------------------------
echoerror() {
printf "${RC} * ERROR${EC}: %s\n" "$@" 1>&2;
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: echoinfo
# DESCRIPTION: Echo information to stdout.
#-------------------------------------------------------------------------------
echoinfo() {
printf "${GC} * INFO${EC}: %s\n" "$@";
}
#--- NO ARGS -----------------------------------------------------------------
# NAME: no args
# DESCRIPTION: If no arguments are supplied show the usage info
#-------------------------------------------------------------------------------
if [ $# == 0 ] ; then
# Show usage info
help
exit 1;
fi
#--- MAIN --------------------------------------------------------------------
# NAME: echoinfo
# DESCRIPTION: Echo information to stdout.
#-------------------------------------------------------------------------------
function main {
help
# Some argument parsing needs to be done..
}
# Execute the main code block
main "$@"