-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon
More file actions
108 lines (98 loc) · 3.74 KB
/
common
File metadata and controls
108 lines (98 loc) · 3.74 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
#!/usr/bin/env bash
: '
Common bash code sourced into various scripts.
'
# Constants
# shellcheck disable=SC2034
readonly HOST_DNS_NAME="test.learnyouahaskell.github.io"
readonly DATE_FORMAT='%FT%H:%M:%S.%3NZ'
readonly TIME_ZONE="UTC0"
# shellcheck disable=SC2034
readonly VM_PROPERTY_CONFIG_FILE_PATH="io.github.learnyouahaskell.test.config"
# shellcheck disable=SC2034
readonly VM_PROPERTY_KEYSTORE_FILE_PATH="io.github.learnyouahaskell.test.keyStore"
# shellcheck disable=SC2034
readonly VM_PROPERTY_KEYSTORE_PASSWORD="io.github.learnyouahaskell.test.keyStorePassword"
# shellcheck disable=SC2034
readonly VM_PROPERTY_PRIVATE_KEY_PASSWORD="io.github.learnyouahaskell.test.privateKeyPassword"
# shellcheck disable=SC2034
readonly KEYSTORE_PASSWORD="ksp"
# shellcheck disable=SC2034
readonly PRIVATE_KEY_PASSWORD="pkp"
# shellcheck disable=SC2034
readonly CONFIGURATION_CLASS_NAME='Configuration.kt'
# Terminal Output
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
_B="1"; _IT="3"; _U="4"; _F="5"; _I="7"
_MOD='['; __='[0m'
_BLACK='30'; _RED='31'; _GREEN='32'; _BROWN='33'; _BLUE='34' _PURPLE='35'; _CYAN='36'; _LGREY='37'
BLACK_='40'; RED_='41'; GREEN_='42'; BROWN_='43'; BLUE_='44' PURPLE_='45'; CYAN_='46'; LGREY_='47'
else
_B=""; _IT=""; _U=""; _F=""; _I=""
_MOD=''; __=''
_BLACK=''; _RED=''; _GREEN=''; _BROWN=''; _BLUE='' _PURPLE=''; _CYAN=''; _LGREY=''
BLACK_=''; RED_=''; GREEN_=''; BROWN_=''; BLUE_='' PURPLE_=''; CYAN_=''; LGREY_=''
fi
function wC { echo -n "${_MOD}${1}m$2${__}" ; }
function sQuote { echo -n "'${1}'" ; }
function colour { wC "${1}" "${2}" ; }
function red { wC $_RED "${1}" ; }
function green { wC $_GREEN "${1}" ; }
function brown { wC $_BROWN "${1}" ; }
function blue { wC $_BLUE "${1}" ; }
function purple { wC $_PURPLE "${1}" ; }
function cyan { wC $_CYAN "${1}" ; }
function lgrey { wC $_LGREY "${1}" ; }
function datef {
local output
output=$(lgrey "$(TZ=${TIME_ZONE} date +${DATE_FORMAT})")
output="${output//:/$(colour "$_BLUE" ":")}"
output="${output//./$(colour "$_BLUE" ".")}"
echo "${output//-/$(colour "$_BLUE" "-")}"
}
function logInfo { echo -e "$(datef)" "$(purple "$1")" "$(green "INFO")" "${2}" ; }
function logError { echo -e "$(datef)" "$(purple "$1")" "$(red "ERROR")" "${2}" ; }
# Fetches a URL until a given status code is returned. Up to a specified number attempts and with a configurable
# sleep between each request.
#
# #1 = the name of the calling script
# #2 = the name of the site
# #3 = the URL to get
# #4 = the expected success HTTP status code
# #5 = the maximum number of attempts
# #6 = the 'sleep' argument to use between fetches
function waitForStatusCode {
logInfo "${1}" "Waiting for $(brown "${2}") ($(blue "${3}"))..."
local statusCode
# shellcheck disable=SC2034
for attempt in $(seq 1 "${5}"); do
statusCode=$(curl --insecure --silent --head "${3}" | awk '/^HTTP/{print $2}')
[[ $statusCode == "$4" ]] && { logInfo "${ME}" "$(green "${2}") is $(green "READY")." ; return 0 ; }
sleep "${6}"
done
logError "${ME}" "$(red "${2}") took too long."
return 1
}
# Pushes a directory onto the stack and asserts it succeeds
#
# #1 = the name of the calling script
# #2 = the directory to push onto the stack
function pushDir {
pushd "${2}" &>/dev/null || \
{ logError "${1}" "Failed to push $(sQuote "$(red "${2}")") onto directory stack." && exit 1 ; }
}
# Pops a directory from the stack and asserts it succeeds
#
# #1 = the name of the calling script
function popDir {
popd &>/dev/null || { logError "${1}" "Failed to pop from directory stack." && exit 1 ; }
}
# Naively formats a URL given: scheme, host, port & path components
#
# #1 = the scheme
# #2 = the host
# #3 = the port
# #4 = the path
function makeUrl {
echo "${1}://${2}:${3}${4}"
}