-
Notifications
You must be signed in to change notification settings - Fork 36
/
utils.sh
executable file
·61 lines (44 loc) · 947 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
# some utility functions...
#
#############################
######### Functions #########
#############################
promptUser() {
# This function accepts a OPTIONS array and return an CHOICE index
prompt=$1
default=$2
question=${3:-"Make a selection"}
echo
echo $prompt
i=0
for p in "${OPTIONS[@]}"
do
echo " [$i]: $p"
((i++))
done
echo
read -e -p "$question [$default]: " CHOICE
CHOICE=${CHOICE:-"$default"}
if ! [ "$CHOICE" -eq "$CHOICE" ] || [ "$CHOICE" -lt 0 ] || [ "$CHOICE" -ge "${#OPTIONS[@]}" ] 2>/dev/null
then
echo Invalid choice: $CHOICE
exit 1;
fi
echo
}
getTimeZone() {
# Check to see if the user has a timezone set.
TZ_HOST=${TZ}
if [ -z ${TZ_HOST} ]
then
# Check to see if the system has timezone set
TZ_HOST=`timedatectl 2>/dev/null | grep "Time zone:" | awk '{print $3}'`
if [ -z ${TZ_HOST} ]
then
# Use default Timezone
TZ_HOST="UTC"
fi
fi
}