-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.sh
43 lines (36 loc) · 798 Bytes
/
utils.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
#!/usr/bin/env bash
#
# Shared functions and variables across scripts.
set -o errexit
set -o pipefail
set -o nounset
readonly PROJECT_NAME='YOUR PROJECT'
readonly LOG_DIR='./log'
# Automatically create log dir, if it doesn't exist already
mkdir -p "$LOG_DIR"
timestamp() {
# Default timezone to date's built-in format
# macOS outputs code e.g. CET whereas Linux as time difference +08
local timezone=%Z
# Set timezone to contents of system file if exists
if [ -f /etc/timezone ]; then
timezone=$(cat /etc/timezone)
fi
date "+%a %b %d %I:%M:%S %p $timezone %Y"
}
fancy_echo() {
echo
timestamp
echo "[$PROJECT_NAME] ==> $1"
echo
}
err_exit() {
echo
echo "ERROR: $1"
echo
exit 1
}
summary() {
fancy_echo "Logs written to $LOG_FILENAME"
fancy_echo "Done"
}