-
Notifications
You must be signed in to change notification settings - Fork 15
/
menubox.sh
197 lines (175 loc) · 6.22 KB
/
menubox.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
ver="1.9"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
pyconfigfile="./settings.py"
filename_conf="./settings.conf"
filename_temp="./settings.conf.temp"
#------------------------------------------------------------------------------
function do_anykey ()
{
echo ""
echo "######################################"
echo "# Review Output #"
echo "######################################"
read -p " Press Enter to Return to Main Menu"
}
#------------------------------------------------------------------------------
function init_status ()
{
if [ -z "$( pgrep -f webserver.py )" ]; then
WEB_1="START"
WEB_2="webserver.py in Background"
else
webserver_pid=$( pgrep -f webserver.py )
WEB_1="STOP"
WEB_2="webserver.py - PID is $webserver_pid"
fi
if [ -z "$( pgrep -f picamera-motion.py )" ]; then
PICAM_1="START"
PICAM_2="picamera-motion.py in Background"
else
picamera_motion_pid=$( pgrep -f picamera-motion.py )
PICAM_1="STOP"
PICAM_2="picamera-motion.py - PID is $picamera_motion_pid"
fi
}
#------------------------------------------------------------------------------
function do_picamera_motion ()
{
if [ -z "$( pgrep -f picamera-motion.py )" ]; then
$DIR/picamera-motion.py >/dev/null 2>&1 &
if [ -z "$( pgrep -f picamera-motion.py )" ]; then
whiptail --msgbox "Failed to Start picamera-motion.py Please Investigate Problem " 20 70
fi
else
picamera_motion_pid=$( pgrep -f picamera-motion.py )
sudo kill $picamera_motion_pid
if [ ! -z "$( pgrep -f picamera-motion.py )" ]; then
whiptail --msgbox "Failed to Stop picamera-motion.py Please Investigate Problem" 20 70
fi
fi
do_main_menu
}
#------------------------------------------------------------------------------
function do_webserver ()
{
if [ -z "$( pgrep -f webserver.py )" ]; then
$DIR/webserver.py >/dev/null 2>&1 &
if [ -z "$( pgrep -f webserver.py )" ]; then
whiptail --msgbox "Failed to Start webserver.py Please Investigate Problem." 20 70
else
myip=$(ifconfig | grep 'inet ' | grep -v 127.0.0 | cut -d " " -f 12 | cut -d ":" -f 2 )
myport=$( grep "web_server_port" settings.py | cut -d "=" -f 2 | cut -d "#" -f 1 | awk '{$1=$1};1' )
whiptail --msgbox --title "Webserver Access" "Access picamera-motion web server from another network computer web browser using url http://$myip:$myport" 15 50
fi
else
webserver_pid=$( pgrep -f webserver.py )
sudo kill $webserver_pid
if [ ! -z "$( pgrep -f webserver.py )" ]; then
whiptail --msgbox "Failed to Stop webserver.py Please Investigate Problem." 20 70
fi
fi
do_main_menu
}
#------------------------------------------------------------------------------
function do_nano_main ()
{
cp $pyconfigfile $filename_conf
nano $filename_conf
if (whiptail --title "Save Nano Edits" --yesno "Save nano changes to $filename_conf\n or cancel all changes" 8 65 --yes-button "Save" --no-button "Cancel" ) then
cp $filename_conf $pyconfigfile
fi
}
#------------------------------------------------------------------------------
function do_settings_menu ()
{
SET_SEL=$( whiptail --title "Settings Menu" --menu "Arrow/Enter Selects or Tab Key" 0 0 0 --ok-button Select --cancel-button Back \
"a EDIT" "nano Edit settings.py" \
"b VIEW" "settings.py" \
"d BACK" "Return to Main Menu" 3>&1 1>&2 2>&3 )
RET=$?
if [ $RET -eq 1 ]; then
clear
rm -f $filename_temp
rm -f $filename_conf
do_main_menu
elif [ $RET -eq 0 ]; then
case "$SET_SEL" in
a\ *) do_nano_main
do_settings_menu ;;
b\ *) more -d settings.py
do_anykey
do_settings_menu ;;
d\ *) clear
rm -f $filename_temp
rm -f $filename_conf
do_main_menu ;;
*) whiptail --msgbox "Programmer error: unrecognised option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running selection $SELECTION" 20 60 1
fi
}
#------------------------------------------------------------------------------
function do_upgrade ()
{
if (whiptail --title "GitHub Upgrade webserver" --yesno "Upgrade webserver files from GitHub" 8 65 --yes-button "upgrade" --no-button "Cancel" ) then
curl -L https://raw.github.com/pageauc/picamera-motion/master/install.sh | bash
do_anykey
fi
}
#------------------------------------------------------------------------------
function do_about ()
{
whiptail --title "About" --msgbox " \
Manage picamera-motion operation and settings
written by Claude Pageau
for more information
View Readme.md (use menubox.sh help option)
or
visit web repo at https://github.com/pageauc/picamera-motion
Raise a github issue for issues or questions
\
" 0 0 0
}
#------------------------------------------------------------------------------
function do_main_menu ()
{
init_status
temp="$(/opt/vc/bin/vcgencmd measure_temp)"
SELECTION=$(whiptail --title "Main Menu" --menu "Arrow/Enter Selects or Tab Key" 0 0 0 --cancel-button Quit --ok-button Select \
"a $PICAM_1" "$PICAM_2" \
"b $WEB_1" "$WEB_2" \
"c SETTINGS" "Edit/View Settings" \
"d UPGRADE" "Upgrade Files from GitHub.com" \
"e STATUS" "CPU $temp Select to Refresh" \
"f HELP" "View Readme.md" \
"g ABOUT" "Information about this program" \
"q QUIT" "Exit menubox.sh" 3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
exit 0
elif [ $RET -eq 0 ]; then
case "$SELECTION" in
a\ *) do_picamera_motion ;;
b\ *) do_webserver ;;
c\ *) do_settings_menu ;;
d\ *) do_upgrade ;;
e\ *) clear
do_main_menu ;;
f\ *) pandoc -f markdown -t plain Readme.md | more
do_anykey;;
g\ *) do_about ;;
q\ *) clear
exit 0 ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running selection $SELECTION" 20 60 1
fi
}
#------------------------------------------------------------------------------
# Main Script
#------------------------------------------------------------------------------
if [ $# -eq 0 ] ; then
while true; do
do_main_menu
done
fi