-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash-guide-functions.sh
72 lines (50 loc) · 1.8 KB
/
bash-guide-functions.sh
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
#!/usr/bin/env bash
function function_header() {
# Where ever this is included it will write out the function header
# and any message passed in. The Header name will be parse and any
# underscores will be replaced with a space
local _message=$1
echo ""
echo "Function: ${FUNCNAME[1]//_/ }"
echo "================================================================================"
echo ""
echo -e " ${_message}"
echo ""
}
function error() {
local _return_code=$1
local _message=$2
if [ ${_return_code} -ne 0 ]; then
echo ""
echo " ----------------------------------------------------------------------------------------"
echo ""
echo " Error in: ${FUNCNAME[1]}"
echo " Return Code: ${_return_code}"
echo -e " Message: ${_message}"
echo ""
echo " ----------------------------------------------------------------------------------------"
echo ""
exit 1
fi
}
function example_pre_install() {
# Example description if needed
local _msg="Carrying out preinstall steps..."
local _system=$(python -c 'import platform; print(platform.system());')
local _dist=''
function_header "${_msg}"
if [[ ${_system} == "Darwin" ]]; then
_dist=$(python -c "import platform; print(platform.mac_ver());")
else
_dist=$(python -c "import platform; print(platform.dist());")
fi
echo " * ${_system}: ${_dist}"
echo " * Verifying system..."
# Do Verification stuff.
echo " * Installing packages..."
# Do Install stuff
_http_return_code=$(curl -s -I http://www.example.org/exampleinstaller | head -n 1| cut -d$' ' -f2)
if [[ ${_return_code} -ne 200 ]]; then
error 1 "Unable to download file"
fi
}