-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathocs_new.sh
More file actions
executable file
·174 lines (147 loc) · 4.63 KB
/
ocs_new.sh
File metadata and controls
executable file
·174 lines (147 loc) · 4.63 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
# Set flag for whether the space is open or closed (true or false)
isSpaceOpen=$1
# Set configurable variables
source "/opt/uas/Occupancy/ocs.cfg"
set -euo pipefail
###############################################################################
# New Occupancy Service
# Unallocated Space
# Written by Usako - 2018-07-15
# filename = ocs_new.sh
#
# Usage:
# The php status page executes this script.
#
# Must have access to /tmp/ to write JPEGs and TXT files
###############################################################################
# log()
# A function to make log messages consistant
log()
{
echo "[$(date "+%Y-%m-%d %T")]: $*" >> "${OCS_LOGFILE}"
}
# getWallPicture()
# moves camera to preset 'TheWall' and sets flag
# then takes picture and puts it at /tmp/thewall.jpg
getWallPicture ()
{
log "Call to getWallPicture"
curl -s "http://${OCS_AXISCAMERA_IP}/axis-cgi/com/ptz.cgi?gotoserverpresetname=TheWall&camera=1"
#log "0"
sleep 3
#log "1"
#curl -s "http://${OCS_AXISCAMERA_IP}/axis-cgi/com/ptz.cgi?camera=1&rzoom=-2500"
#sleep 1
#log "2"
#curl -s "http://${OCS_AXISCAMERA_IP}/axis-cgi/com/ptz.cgi?camera=1&rzoom=+2500"
#sleep 4
log "write wall image to temp location"
wget "http://${OCS_AXISCAMERA_IP}/axis-cgi/jpg/image.cgi" -q -O "${OCS_TMP_WALL}"
sleep 1
}
###############################################################################
# Website functions
#
# pushStatusToWebsite()
# moves the /tmp/status file to the websites status file
pushStatusToWebsite ()
{
log "Call to pushStatusToWebsite"
ftp -n "${OCS_UAS_URL}" << END_FTP_COMMANDS
quote USER ${OCS_UAS_USER}
quote PASS ${OCS_UAS_PASS}
ascii
passive
put ${OCS_TMP_STATUS} ${OCS_UAS_STATUS_FILE}
quit
END_FTP_COMMANDS
}
# pushWallToWebsite()
# moves the /tmp/thewall.jpg file to the websites status file
pushWallToWebsite ()
{
log "Call to pushWallToWebsite"
stamp=$(date '+%F_%T')
ftp -n "${OCS_UAS_URL}" << END_FTP_COMMANDS
quote USER ${OCS_UAS_USER}
quote PASS ${OCS_UAS_PASS}
ascii
passive
put ${OCS_TMP_WALL} ${OCS_UAS_WALL_FILE}
put ${OCS_TMP_WALL} ${OCS_UAS_WALL_ARCHIVE_FILEPATH}/${stamp}.jpg
quit
END_FTP_COMMANDS
#nc "${OCS_IRC_IP}" "${OCS_IRC_PORT}" \
# "!JSON" \
# "{\"Service\":${OCS_IRC_SERVICE}, \"Key\":${OCS_IRC_KEY}, \"Data\":\"New Wall Image: http://${OCS_UAS_WALL_ARCHIVE_FILEPATH}/${stamp}.jpg\"}" \
# &>/dev/null
}
# openTheSpace()
# Tells the world that we're open by posting to all of our various social media
# and other services
openTheSpace()
{
# status file
echo "Live Status: The space is currently open (Updated: $(date '+%m/%d %H:%M'))" > "${OCS_TMP_STATUS}"
# Turn on open sign
kasa --type plug --host open-sign.uas.run on
# website status
pushStatusToWebsite
# Tweet (not correct yet)
python /opt/uas/statustweet/statustweet.py "$(cat "${OCS_TMP_STATUS}") #Unallocated" &>/dev/null
# IRC
#curl -X POST 127.0.0.1:9999/ --data '{"Service":"Occupancy","Data":"The space is now open"}'
#Wall image to website
getWallPicture
pushWallToWebsite
}
# closeTheSpace()
# Tells the world that we're closed by posting to all of our various social
# media and other services
closeTheSpace()
{
#Update flags, IRC, website status file, checkin, logging
echo "Live Status: The space is currently closed (Updated: $(date '+%m/%d %H:%M'))" > "${OCS_TMP_STATUS}"
# Turn off open sign
kasa --type plug --host open-sign.uas.run off
#website status
pushStatusToWebsite
#checkin
#python "${OCS_CHECKIN_SCRIPT}" "closing"
# Twitter
python /opt/uas/statustweet/statustweet.py "$(cat "${OCS_TMP_STATUS}") #Unallocated" &>/dev/null
# IRC
#curl -X POST 127.0.0.1:9999/ --data '{"Service":"Occupancy","Data":"The space is now closed"}'
}
# cleanUp()
# Perform any necessary script clean up here like deleting the PID
cleanUp()
{
log "Caught signal, exiting"
exit
}
###############################################################################
# main()
# Main logic function
# Checks the status and performs the necessary procedures based on open vs. closed.
main ()
{
# Capture signals so we clean up the pid file properly.
trap cleanUp SIGHUP SIGINT SIGTERM
log "STARTING ocs_new.sh"
if $isSpaceOpen ; then
openTheSpace
log "Space is OPEN"
else
closeTheSpace
log "Space is CLOSED"
fi
}
###############################################################################
# Script Entry
# All functions and variables need to be set above these lines
# (i.e. keep this at the end)
log "starting main"
main
exit 0