-
Notifications
You must be signed in to change notification settings - Fork 0
/
wittyPiRTC.sh
executable file
·141 lines (102 loc) · 2.81 KB
/
wittyPiRTC.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
[ -z $BASH ] && { exec bash "$0" "$@" || exit; }
#
#--------------------------------------
#!/bin/bash
# file: wittyPiRTC.sh
#
# Show (RTC) date-time
#
# (C) M.A. O'Neill. Tumbling Dice 2019
#--------------------------------------
#-----------------------------------------------
# Include utilities script in current directory
#-----------------------------------------------
current_dir="`dirname \"$0\"`"
current_dir="`( cd \"$current_dir\" && pwd )`"
if [ -z "$current_dir" ] ; then
exit 1
fi
. $current_dir/utilities.sh
#-----------------------
# Check if root UID
#-----------------------
if [ "$(id -u)" != 0 ]; then
echo 'ERROR: script must be run with effective root UID'
exit 1
fi
#---------------------------------
# Check for wiringPi installation
#---------------------------------
hash gpio 2>/dev/null
if [ $? -ne 0 ]; then
echo ''
echo 'ERROR: wiringPi is not installed properly (missing "gpio" command). Quitting...'
echo ''
exit
fi
#-------------------------
# Check for wittyPi board
#-------------------------
if ! is_rtc_connected ; then
echo ''
log 'ERROR: Witty Pi board is not connected? Quitting...'
echo ''
exit
fi
#---------------------------
# Get time from wittyPi RTC
#---------------------------
echo ""
echo ""
now=$(get_rtc_time)
echo "Time now: " $now
#--------------------------------
# Get startup and shutdown times
#--------------------------------
echo ""
echo "--------------------------------------------"
#----------
# Shutdown
#----------
shutdown_time=$(get_local_date_time "$(get_shutdown_time)" )
day_in_month=$(echo $shutdown_time | cut -d' ' -f 1)
time_of_day=$(echo "$shutdown_time" | cut -d' ' -f 2)
day_name=$(date | awk '{print $1}')
dateChanged
if [ "$?" -eq 255 ] ; then
month_name=$(date | awk '{print $2}')
else
month_name=$(date | awk '{print $3}')
fi
tzone=$(date | awk '{print $5}')
year=$(date | awk '{print $6}')
if [ "$shutdown_time" != " ::" ]; then
echo "shutdown time: $day_name $day_in_month $month_name $year $time_of_day $tzone"
else
echo "shutdown time: notset"
fi
#---------
# Startup
#---------
shutdown_day_in_month=$day_in_month
startup_time=$(get_local_date_time "$(get_startup_time)" )
day_in_month=$(echo $startup_time | cut -d' ' -f 1)
time_of_day=$(echo "$startup_time" | cut -d' ' -f 2)
if [ "$startup_time" != " ::" ]; then
offset=$(("$day_in_month" - "$shutdown_day_in_month"))
day_name=$(date --date="+ $offset day" | awk '{print $1}')
dateChanged
if [ "$?" -eq 255 ] ; then
month_name=$(date | awk '{print $2}')
else
month_name=$(date | awk '{print $3}')
fi
tzone=$(date | awk '{print $5}')
year=$(date | awk '{print $6}')
echo "startup time: $day_name $day_in_month $month_name $year $time_of_day $tzone"
else
echo "startup time: notset"
fi
echo "--------------------------------------------"
echo ""
exit 0