forked from silvanmelchior/RPi_Cam_Web_Interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPi_Cam_Web_Interface_Installer.sh
executable file
·173 lines (141 loc) · 6.17 KB
/
RPi_Cam_Web_Interface_Installer.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
#!/bin/bash
# Copyright (c) 2014, Silvan Melchior
# All rights reserved.
# Redistribution and use, with or without modification, are permitted provided
# that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Description
# This script installs a browser-interface to control the RPi Cam. It can be run
# on any Raspberry Pi with a newly installed raspbian and enabled camera-support.
#
# Edited by jfarcher to work with github
# Edited by slabua to support custom installation folder
# Configure below the folder name where to install the software to,
# or leave empty to install to the root of the webserver.
# The folder name must be a subfolder of /var/www/ which will be created
# accordingly, and must not include leading nor trailing / character.
# Default upstream behaviour: rpicamdir="" (installs in /var/www/)
rpicamdir=""
case "$1" in
remove)
sudo killall raspimjpeg
sudo apt-get remove -y apache2 php5 libapache2-mod-php5 gpac motion
sudo apt-get autoremove -y
sudo rm -r /var/www/$rpicamdir/*
sudo rm /etc/sudoers.d/RPI_Cam_Web_Interface
sudo rm /usr/bin/raspimjpeg
sudo rm /etc/raspimjpeg
sudo cp -r /etc/rc.local.bak /etc/rc.local
sudo chmod 755 /etc/rc.local
echo "Removed everything"
;;
autostart_yes)
sudo cp -r etc/rc_local_run/rc.local /etc/
sudo chmod 755 /etc/rc.local
echo "Changed autostart"
;;
autostart_no)
sudo cp -r /etc/rc.local.bak /etc/rc.local
sudo chmod 755 /etc/rc.local
echo "Changed autostart"
;;
install)
sudo killall raspimjpeg
git pull origin master
sudo apt-get install -y apache2 php5 libapache2-mod-php5 gpac motion
sudo mkdir -p /var/www/$rpicamdir/media
sudo cp -r www/* /var/www/$rpicamdir/
if [ -e /var/www/$rpicamdir/index.html ]; then
sudo rm /var/www/$rpicamdir/index.html
fi
sudo chown -R www-data:www-data /var/www/$rpicamdir
if [ ! -e /var/www/$rpicamdir/FIFO ]; then
sudo mknod /var/www/$rpicamdir/FIFO p
fi
sudo chmod 666 /var/www/$rpicamdir/FIFO
if [ ! -e /var/www/$rpicamdir/cam.jpg ]; then
sudo ln -sf /run/shm/mjpeg/cam.jpg /var/www/$rpicamdir/cam.jpg
fi
if [ "$rpicamdir" == "" ]; then
cat etc/apache2/sites-available/default.1 > etc/apache2/sites-available/default
else
sed -e "s/Directory \/var\/www/Directory \/var\/www\/$rpicamdir/" etc/apache2/sites-available/default.1 > etc/apache2/sites-available/default
fi
sudo cp -r etc/apache2/sites-available/default /etc/apache2/sites-available/
sudo chmod 644 /etc/apache2/sites-available/default
sudo cp etc/apache2/conf.d/other-vhosts-access-log /etc/apache2/conf.d/other-vhosts-access-log
sudo chmod 644 /etc/apache2/conf.d/other-vhosts-access-log
sudo cp etc/sudoers.d/RPI_Cam_Web_Interface /etc/sudoers.d/
sudo chmod 440 /etc/sudoers.d/RPI_Cam_Web_Interface
sudo cp -r bin/raspimjpeg /opt/vc/bin/
sudo chmod 755 /opt/vc/bin/raspimjpeg
if [ ! -e /usr/bin/raspimjpeg ]; then
sudo ln -s /opt/vc/bin/raspimjpeg /usr/bin/raspimjpeg
fi
if [ "$rpicamdir" == "" ]; then
cat etc/raspimjpeg/raspimjpeg.1 > etc/raspimjpeg/raspimjpeg
else
sed -e "s/www/www\/$rpicamdir/" etc/raspimjpeg/raspimjpeg.1 > etc/raspimjpeg/raspimjpeg
fi
sudo cp -r /etc/raspimjpeg /etc/raspimjpeg.bak
sudo cp -r etc/raspimjpeg/raspimjpeg /etc/
sudo chmod 644 /etc/raspimjpeg
if [ "$rpicamdir" == "" ]; then
cat etc/rc_local_run/rc.local.1 > etc/rc_local_run/rc.local
else
sed -e "s/www/www\/$rpicamdir/" etc/rc_local_run/rc.local.1 > etc/rc_local_run/rc.local
fi
sudo cp -r /etc/rc.local /etc/rc.local.bak
sudo cp -r etc/rc_local_run/rc.local /etc/
sudo chmod 755 /etc/rc.local
if [ "$rpicamdir" == "" ]; then
cat etc/motion/motion.conf.1 > etc/motion/motion.conf
else
sed -e "s/www/www\/$rpicamdir/" etc/motion/motion.conf.1 > etc/motion/motion.conf
fi
sudo cp -r etc/motion/motion.conf /etc/motion/
sudo chmod 640 /etc/motion/motion.conf
echo "Installer finished"
;;
start)
shopt -s nullglob
video=-1
for f in /var/www/$rpicamdir/media/video_*.mp4; do
video=`echo $f | cut -d '_' -f2 | cut -d '.' -f1`
done
video=`echo $video | sed 's/^0*//'`
video=`expr $video + 1`
image=-1
for f in /var/www/$rpicamdir/media/image_*.jpg; do
image=`echo $f | cut -d '_' -f2 | cut -d '.' -f1`
done
image=`echo $image | sed 's/^0*//'`
image=`expr $image + 1`
shopt -u nullglob
sudo mkdir -p /dev/shm/mjpeg
sudo raspimjpeg -ic $image -vc $video > /dev/null &
echo "Started"
;;
stop)
sudo killall raspimjpeg
sudo killall motion
echo "Stopped"
;;
*)
echo "No option selected"
;;
esac