diff --git a/install.sh b/install.sh new file mode 100644 index 00000000..33953019 --- /dev/null +++ b/install.sh @@ -0,0 +1,340 @@ +#!/bin/bash + +# Copyright (c) 2015, Bob Tidey +# 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. +# RPI_Cam_Web_Interface installer by Silvan Melchior +# Edited by jfarcher to work with github +# Edited by slabua to support custom installation folder +# Additions by btidey, miraaz, gigpi +# Rewritten and split up by Bob Tidey + +#Debug enable next 3 lines +exec 5> install.txt +BASH_XTRACEFD="5" +set -x + +cd $(dirname $(readlink -f $0)) + +if [ $(dpkg-query -W -f='${Status}' "dialog" 2>/dev/null | grep -c "ok installed") -eq 0 ]; then + sudo apt-get install -y dialog +fi + +# Terminal colors +color_red="tput setaf 1" +color_green="tput setaf 2" +color_reset="tput sgr0" + +# Version stuff moved out functions as we need it more when one time. +versionfile="./www/config.php" +version=$(cat $versionfile | grep "'APP_VERSION'" | cut -d "'" -f4) +backtitle="Copyright (c) 2015, Bob Tidey. RPi Cam $version" + +# Config options located in ./config.txt. In first run script makes that file for you. +if [ ! -e ./config.txt ]; then + sudo echo "#This is config file for main installer. Put any extra options in here." > ./config.txt + sudo echo "rpicamdir=\"html\"" >> ./config.txt + sudo echo "webserver=\"apache\"" >> ./config.txt + sudo echo "webport=\"80\"" >> ./config.txt + sudo echo "user=\"\"" >> ./config.txt + sudo echo "webpasswd=\"\"" >> ./config.txt + sudo echo "autostart=\"yes\"" >> ./config.txt + sudo echo "" >> ./config.txt + sudo chmod 664 ./config.txt +fi + +source ./config.txt + +#Allow for a quiet install +if [ $# -eq 0 ] || [ "$1" != "q" ]; then + exec 3>&1 + dialog \ + --separate-widget $'\n' \ + --title "Configuration Options" \ + --backtitle "$backtitle" \ + --form "" \ + 0 0 0 \ + "Cam subfolder:" 1 1 "$rpicamdir" 1 32 15 0 \ + "Autostart:(yes/no)" 2 1 "$autostart" 2 32 15 0 \ + "Server:(apache/nginx)" 3 1 "$webserver" 3 32 15 0 \ + "Webport:" 4 1 "$webport" 4 32 15 0 \ + "User:(blank=nologin)" 5 1 "$user" 5 32 15 0 \ + "Password:" 6 1 "$webpasswd" 6 32 15 0 \ + 2>&1 1>&3 | { + read -r rpicamdir + read -r autostart + read -r webserver + read -r webport + read -r user + read -r webpasswd + if [ -n "$webport" ]; then + sudo echo "#This is edited config file for main installer. Put any extra options in here." > ./config.txt + sudo echo "rpicamdir=\"$rpicamdir\"" >> ./config.txt + sudo echo "webserver=\"$webserver\"" >> ./config.txt + sudo echo "webport=\"$webport\"" >> ./config.txt + sudo echo "user=\"$user\"" >> ./config.txt + sudo echo "webpasswd=\"$webpasswd\"" >> ./config.txt + sudo echo "autostart=\"$autostart\"" >> ./config.txt + sudo echo "" >> ./config.txt + fi + } + returncode=$? + exec 3>&- + + if [ ! "$returncode" == "0" ]; then + exit + fi + + source ./config.txt +fi + +if [ ! "${rpicamdir:0:1}" == "" ]; then + rpicamdirEsc="\\/$rpicamdir" + rpicamdir=/$rpicamdir +else + rpicamdirEsc = "" +fi + +fn_stop () +{ # This is function stop + sudo killall raspimjpeg + sudo killall php + sudo killall motion +} + +fn_reboot () +{ # This is function reboot system + dialog --title "You must reboot your system!" --backtitle "$backtitle" --yesno "Do you want to reboot now?" 5 33 + response=$? + case $response in + 0) sudo reboot;; + 1) dialog --title 'Reboot message' --colors --infobox "\Zb\Z1"'Pending system changes that require a reboot!' 4 28 ; sleep 2;; + 255) dialog --title 'Reboot message' --colors --infobox "\Zb\Z1"'Pending system changes that require a reboot!' 4 28 ; sleep 2;; + esac +} + +fn_apache () +{ +aconf="etc/apache2/sites-available/raspicam.conf" +cp $aconf.1 $aconf +if [ -e "\/$aconf" ]; then + sudo rm "\/$aconf" +fi +if [ -e /etc/apache2/conf-available/other-vhosts-access-log.conf ]; then + aotherlog="/etc/apache2/conf-available/other-vhosts-access-log.conf" +else + aotherlog="/etc/apache2/conf.d/other-vhosts-access-log" +fi +tmpfile=$(mktemp) +sudo awk '/NameVirtualHost \*:/{c+=1}{if(c==1){sub("NameVirtualHost \*:.*","NameVirtualHost *:'$webport'",$0)};print}' /etc/apache2/ports.conf > "$tmpfile" && sudo mv "$tmpfile" /etc/apache2/ports.conf +sudo awk '/Listen/{c+=1}{if(c==1){sub("Listen.*","Listen '$webport'",$0)};print}' /etc/apache2/ports.conf > "$tmpfile" && sudo mv "$tmpfile" /etc/apache2/ports.conf +awk '/",$0)};print}' $aconf > "$tmpfile" && sudo mv "$tmpfile" $aconf +sudo sed -i "s//g" $aconf +if [ "$user" == "" ]; then + sudo awk '/AllowOverride/{c+=1}{if(c==2){sub("AllowOverride.*","AllowOverride None",$0)};print}' $aconf > "$tmpfile" && sudo mv "$tmpfile" $aconf +else + sudo awk '/AllowOverride/{c+=1}{if(c==2){sub("AllowOverride.*","AllowOverride All",$0)};print}' $aconf > "$tmpfile" && sudo mv "$tmpfile" $aconf + sudo htpasswd -b -c /usr/local/.htpasswd $user $webpasswd + if [ ! -e /var/www$rpicamdir/.htaccess ]; then + sudo bash -c "cat > /var/www$rpicamdir/.htaccess" << EOF +AuthName "RPi Cam Web Interface Restricted Area" +AuthType Basic +AuthUserFile /usr/local/.htpasswd +AuthGroupFile /dev/null +Require valid-user +EOF + sudo chown -R www-data:www-data /var/www$rpicamdir/.htaccess + fi +fi +sudo mv $aconf /$aconf +sudo sed -i 's/^CustomLog/#CustomLog/g' $aotherlog +sudo service apache2 restart +} + +fn_nginx () +{ +sudo sed -e "s:root /var/www;:root /var/www$rpicamdirEsc;:g" etc/nginx/sites-available/rpicam.1 > etc/nginx/sites-available/rpicam +sudo cp -r etc/nginx/sites-available/rpicam /etc/nginx/sites-available/rpicam +sudo chmod 644 /etc/nginx/sites-available/rpicam + + +if [ ! -e /etc/nginx/sites-enabled/rpicam ]; then + sudo ln -s /etc/nginx/sites-available/rpicam /etc/nginx/sites-enabled/rpicam +fi + +# Update nginx main config file +sudo sed -i "s/worker_processes 4;/worker_processes 2;/g" /etc/nginx/nginx.conf +sudo sed -i "s/worker_connections 768;/worker_connections 128;/g" /etc/nginx/nginx.conf +sudo sed -i "s/gzip on;/gzip off;/g" /etc/nginx/nginx.conf +if ["$NGINX_DISABLE_LOGGING"]; then + sudo sed -i "s:access_log /var/log/nginx/nginx/access.log;:access_log /dev/null;:g" /etc/nginx/nginx.conf +fi + +# Configure php-apc +sudo sh -c "echo \"cgi.fix_pathinfo = 0;\" >> /etc/php5/fpm/php.ini" +sudo cp etc/php5/apc.ini /etc/php5/conf.d/20-apc.ini +sudo chmod 644 /etc/php5/conf.d/20-apc.ini +} + +fn_motion () +{ +sudo sed -i "s/^; netcam_url.*/netcam_url/g" /etc/motion/motion.conf +sudo sed -i "s/^netcam_url.*/netcam_url http:\/\/localhost$rpicamdirEsc\/cam_pic.php/g" /etc/motion/motion.conf +if [ "$user" == "" ]; then + sudo sed -i "s/^netcam_userpass.*/; netcam_userpass value/g" /etc/motion/motion.conf +else + sudo sed -i "s/^; netcam_userpass.*/netcam_userpass/g" /etc/motion/motion.conf + sudo sed -i "s/^netcam_userpass.*/netcam_userpass $user:$webpasswd/g" /etc/motion/motion.conf +fi +sudo sed -i "s/^; on_event_start.*/on_event_start/g" /etc/motion/motion.conf +sudo sed -i "s/^on_event_start.*/on_event_start echo -n \'1\' >\/var\/www\/FIFO1/g" /etc/motion/motion.conf +sudo sed -i "s/^; on_event_end.*/on_event_end/g" /etc/motion/motion.conf +sudo sed -i "s/^on_event_end.*/on_event_end echo -n \'0\' >\/var\/www\/FIFO1/g" /etc/motion/motion.conf +sudo sed -i "s/control_port.*/control_port 6642/g" /etc/motion/motion.conf +sudo sed -i "s/control_html_output.*/control_html_output off/g" /etc/motion/motion.conf +sudo sed -i "s/^output_pictures.*/output_pictures off/g" /etc/motion/motion.conf +sudo sed -i "s/^ffmpeg_output_movies on/ffmpeg_output_movies off/g" /etc/motion/motion.conf +sudo sed -i "s/^ffmpeg_cap_new on/ffmpeg_cap_new off/g" /etc/motion/motion.conf +sudo sed -i "s/^stream_port.*/stream_port 0/g" /etc/motion/motion.conf +sudo sed -i "s/^webcam_port.*/webcam_port 0/g" /etc/motion/motion.conf +sudo sed -i "s/^process_id_file/; process_id_file/g" /etc/motion/motion.conf +sudo sed -i "s/^videodevice/; videodevice/g" /etc/motion/motion.conf +sudo sed -i "s/^event_gap 60/event_gap 3/g" /etc/motion/motion.conf +sudo sed -i "s/www/www$rpicamdirEsc/" /etc/motion/motion.conf +sudo chown motion:www-data /etc/motion/motion.conf +sudo chmod 664 /etc/motion/motion.conf +} + +fn_autostart () +{ +tmpfile=$(mktemp) +sudo sed '/#START/,/#END/d' /etc/rc.local > "$tmpfile" && sudo mv "$tmpfile" /etc/rc.local +# Remove to growing plank lines. +sudo awk '!NF {if (++n <= 1) print; next}; {n=0;print}' /etc/rc.local > "$tmpfile" && sudo mv "$tmpfile" /etc/rc.local +if [ "$autostart" == "yes" ]; then + if ! grep -Fq '#START RASPIMJPEG SECTION' /etc/rc.local; then + sudo sed -i '/exit 0/d' /etc/rc.local + sudo bash -c "cat >> /etc/rc.local" << EOF +#START RASPIMJPEG SECTION +mkdir -p /dev/shm/mjpeg +chown www-data:www-data /dev/shm/mjpeg +chmod 777 /dev/shm/mjpeg +sleep 4;su -c 'raspimjpeg > /dev/null 2>&1 &' www-data +if [ -e /etc/debian_version ]; then + sleep 4;su -c 'php /var/www$rpicamdir/schedule.php > /dev/null 2>&1 &' www-data +else + sleep 4;su -s '/bin/bash' -c 'php /var/www$rpicamdir/schedule.php > /dev/null 2>&1 &' www-data +fi +#END RASPIMJPEG SECTION + +exit 0 +EOF + fi + +fi +sudo chown root:root /etc/rc.local +sudo chmod 755 /etc/rc.local +} + +#Main install) +fn_stop + +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 [ "$webserver" == "apache" ]; then + sudo apt-get install -y apache2 php5 php5-cli libapache2-mod-php5 gpac motion zip libav-tools + fn_apache +else + sudo apt-get install -y nginx php5-fpm php5-cli php5-common php-apc gpac motion zip libav-tools + fn_nginx +fi + +#Make sure user www-data has bash shell +sudo sed -i "s/^www-data:x.*/www-data:x:33:33:www-data:\/var\/www:\/bin\/bash/g" /etc/passwd + +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/FIFO1 ]; then + sudo mknod /var/www$rpicamdir/FIFO1 p +fi +sudo chmod 666 /var/www$rpicamdir/FIFO1 +sudo chmod 755 /var/www$rpicamdir/raspizip.sh + +if [ ! -e /var/www$rpicamdir/cam.jpg ]; then + sudo ln -sf /run/shm/mjpeg/cam.jpg /var/www$rpicamdir/cam.jpg +fi + +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 + +sed -e "s/www/www$rpicamdirEsc/" etc/raspimjpeg/raspimjpeg.1 > etc/raspimjpeg/raspimjpeg +if [ `cat /proc/cmdline |awk -v RS=' ' -F= '/boardrev/ { print $2 }'` == "0x11" ]; then + sed -i 's/^camera_num 0/camera_num 1/g' etc/raspimjpeg/raspimjpeg +fi +if [ -e /etc/raspimjpeg ]; then + $color_green; echo "Your custom raspimjpg backed up at /etc/raspimjpeg.bak"; $color_reset + sudo cp -r /etc/raspimjpeg /etc/raspimjpeg.bak +fi +sudo cp -r etc/raspimjpeg/raspimjpeg /etc/ +sudo chmod 644 /etc/raspimjpeg +if [ ! -e /var/www$rpicamdir/raspimjpeg ]; then + sudo ln -s /etc/raspimjpeg /var/www$rpicamdir/raspimjpeg +fi + +sudo usermod -a -G video www-data +if [ -e /var/www$rpicamdir/uconfig ]; then + sudo chown www-data:www-data /var/www$rpicamdir/uconfig +fi + +fn_motion +fn_autostart + +if [ -e /var/www$rpicamdir/uconfig ]; then + sudo chown www-data:www-data /var/www$rpicamdir/uconfig +fi + +if [ -e /var/www$rpicamdir/schedule.php ]; then + sudo rm /var/www$rpicamdir/schedule.php +fi + +sudo sed -e "s/www/www$rpicamdirEsc/g" www/schedule.php > www/schedule.php.1 +sudo mv www/schedule.php.1 /var/www$rpicamdir/schedule.php +sudo chown www-data:www-data /var/www$rpicamdir/schedule.php + +fn_reboot \ No newline at end of file diff --git a/installreadme.txt b/installreadme.txt new file mode 100644 index 00000000..e722a9b3 --- /dev/null +++ b/installreadme.txt @@ -0,0 +1,30 @@ +The normal way of installing is to run ./RPi_Cam_Web_Interface_Installer.sh +This remains the case. + +There are now some experimental scripts, which have not been fully proven and are still being developed, +but you are welcome to try out. +The main install seems to work for me on Jessie. Not tried on Wheezy yet but in principle it should work. + +The scripts are a re-factoring of the install scripts to simplify the process. + +5 scripts are used instead of combining all together. +This avoids the overhead of a separate selection and makes it easier to run a particular function automatically. +So start and stop can just be run as separate activities. + +The scripts are +install.sh main installation +upgrade.sh check for updates and then run main installation +start.sh starts the software +stop.sh stops the software +remove.sh removes the software + +The main installation always does the same thing to simplify its logic. +It gathers all user parameters first in one combined dialog and then always +applies the parameters as it goes through the process. +A q (quiet) parameter may be used to skip this and give an automatic install based on config.txt +All parameters are always in the config.txt file, a default version is created if one +doesn't exist and is then changed just once after the initial user dialog. +The installation always tries to upgrade the main software components and then functionally goes through +the configuration steps for each area like apache, motion start up. + +Debug is turned on for th emoment so it logs its activity to a file called install.txt \ No newline at end of file diff --git a/remove.sh b/remove.sh new file mode 100644 index 00000000..1c4a86c1 --- /dev/null +++ b/remove.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +# Copyright (c) 2015, Bob Tidey +# 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 removes the browser-interface to control the RPi Cam. It can be run +# on any Raspberry Pi with a newly installed raspbian and enabled camera-support. +# Based on RPI_Cam_WEb_Interface installer by Silvan Melchior +# Edited by jfarcher to work with github +# Edited by slabua to support custom installation folder +# Additions by btidey, miraaz, gigpi +# Split up and refactored by Bob Tidey + +#Debug enable next 3 lines +exec 5> remove.txt +BASH_XTRACEFD="5" +set -x + + +cd $(dirname $(readlink -f $0)) + +# Terminal colors +color_red="tput setaf 1" +color_green="tput setaf 2" +color_reset="tput sgr0" + +source ./config.txt + +fn_stop () +{ # This is function stop + sudo killall raspimjpeg + sudo killall php + sudo killall motion + dialog --title 'Stop message' --infobox 'Stopped.' 4 16 ; sleep 2 +} + +fn_apache_default () +{ +if [ -e /etc/apache2/sites-available/000-default.conf ]; then + adefault="/etc/apache2/sites-available/000-default.conf" + subdir="\/html" +else + adefault="/etc/apache2/sites-available/default" + subdir="" +fi +tmpfile=$(mktemp) +webport="80" +user="" +passwd="" +sudo awk '/NameVirtualHost \*:/{c+=1}{if(c==1){sub("NameVirtualHost \*:.*","NameVirtualHost *:'$webport'",$0)};print}' /etc/apache2/ports.conf > "$tmpfile" && sudo mv "$tmpfile" /etc/apache2/ports.conf +sudo awk '/Listen/{c+=1}{if(c==1){sub("Listen.*","Listen '$webport'",$0)};print}' /etc/apache2/ports.conf > "$tmpfile" && sudo mv "$tmpfile" /etc/apache2/ports.conf +sudo awk '/",$0)};print}' $adefault > "$tmpfile" && sudo mv "$tmpfile" $adefault +sudo sed -i "s/DocumentRoot\ \/var\/www\/.*/DocumentRoot\ \/var\/www$subdir/g" $adefault +sudo awk '/AllowOverride/{c+=1}{if(c==2){sub("AllowOverride.*","AllowOverride None",$0)};print}' /etc/apache2/sites-available/default > "$tmpfile" && sudo mv "$tmpfile" $adefault +sudo service apache2 restart +} + + +fn_stop + +dialog --title "Uninstall packages!" --backtitle "$backtitle" --yesno "Do You want uninstall webserver and php packages also?" 6 35 +response=$? +case $response in + 0) package=('apache2' 'php5' 'libapache2-mod-php5' 'php5-cli' 'zip' 'nginx' 'php5-fpm' 'php5-common' 'php-apc' 'gpac motion' 'libav-tools');; + 1) package=('zip' 'gpac motion' 'libav-tools');; + 255) dialog --title 'Uninstall message' --infobox 'Webserver and php packages not uninstalled.' 4 33 ; sleep 2;; +esac +for i in "${package[@]}" + do + if [ $(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + sudo apt-get remove -y "$i" + fi + done +sudo apt-get autoremove -y + +if [ ! "$rpicamdir" == "" ]; then + sudo rm -r /var/www/$rpicamdir +else + sudo rm -r /var/www/* +fi +sudo rm /etc/sudoers.d/RPI_Cam_Web_Interface +sudo rm /usr/bin/raspimjpeg +sudo rm /etc/raspimjpeg +fn_autostart_disable + +if [ $(dpkg-query -W -f='${Status}' "apache2" 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + fn_apache_default +fi +fn_reboot + diff --git a/scr.zip b/scr.zip deleted file mode 100644 index d9dae94c..00000000 Binary files a/scr.zip and /dev/null differ diff --git a/start.sh b/start.sh new file mode 100644 index 00000000..2269ef56 --- /dev/null +++ b/start.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Copyright (c) 2015, Bob Tidey +# 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 stops a running RPi_Cam interface +# Based on RPI_Cam_Web_Interface installer by Silvan Melchior +# Edited by jfarcher to work with github +# Edited by slabua to support custom installation folder +# Additions by btidey, miraaz, gigpi +# Split up and refactored by Bob Tidey + +#Debug enable next 3 lines +exec 5> start.txt +BASH_XTRACEFD="5" +set -x + +cd $(dirname $(readlink -f $0)) + +source ./config.txt + +fn_stop () +{ # This is function stop + sudo killall raspimjpeg + sudo killall php + sudo killall motion +} + +#start operation +fn_stop +sudo mkdir -p /dev/shm/mjpeg +sudo chown www-data:www-data /dev/shm/mjpeg +sudo chmod 777 /dev/shm/mjpeg +sleep 1;sudo su -c 'raspimjpeg > /dev/null &' www-data +if [ -e /etc/debian_version ]; then + sleep 1;sudo su -c "php /var/www/$rpicamdir/schedule.php > /dev/null &" www-data +else + sleep 1;sudo su -c '/bin/bash' -c "php /var/www/$rpicamdir/schedule.php > /dev/null &" www-data +fi diff --git a/stop.sh b/stop.sh new file mode 100644 index 00000000..037b5f1a --- /dev/null +++ b/stop.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Copyright (c) 2015, Bob Tidey +# 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 stops a running RPi_Cam interface +# Based on RPI_Cam_Web_Interface installer by Silvan Melchior +# Edited by jfarcher to work with github +# Edited by slabua to support custom installation folder +# Additions by btidey, miraaz, gigpi +# Split up and refactored by Bob Tidey + +#Debug enable next 3 lines +exec 5> stop.txt +BASH_XTRACEFD="5" +set -x + +cd $(dirname $(readlink -f $0)) + +source ./config.txt + +fn_stop () +{ # This is function stop + sudo killall raspimjpeg + sudo killall php + sudo killall motion +} + +#stop operation +fn_stop diff --git a/update.sh b/update.sh new file mode 100644 index 00000000..aecfab86 --- /dev/null +++ b/update.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# Copyright (c) 2015, Bob Tidey +# 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 updates the installer for the browser-interface to control the RPi Cam. It can be run +# on any Raspberry Pi with a newly installed raspbian and enabled camera-support. +# Based on RPI_Cam_WEb_Interface installer by Silvan Melchior +# Edited by jfarcher to work with github +# Edited by slabua to support custom installation folder +# Additions by btidey, miraaz, gigpi +# Split up and refactored by Bob Tidey + +#Debug enable next 3 lines +exec 5> update.txt +BASH_XTRACEFD="5" +set -x + +cd $(dirname $(readlink -f $0)) + +# Terminal colors +color_red="tput setaf 1" +color_green="tput setaf 2" +color_reset="tput sgr0" + +# Config options located in ./config.txt. In first run script makes that file for you. +if [ ! -e ./config.txt ]; then + sudo echo "#This is config file for main installer. Put any extra options in here." > ./config.txt + sudo echo "" >> ./config.txt + sudo chmod 664 ./config.txt +fi + +source ./config.txt + + +fn_abort() +{ + $color_red; echo >&2 ' +*************** +*** ABORTED *** +*************** +' + echo "An error occurred. Exiting..." >&2; $color_reset + exit 1 +} + +update) + trap 'fn_abort' 0 + set -e + remote=$( + git ls-remote -h origin master | + awk '{print $1}' + ) + local=$(git rev-parse HEAD) + printf "Local : %s\nRemote: %s\n" $local $remote + if [[ $local == $remote ]]; then + dialog --title 'Update message' --infobox 'Commits match. Nothing update.' 4 35 ; sleep 2 + else + dialog --title 'Update message' --infobox "Commits don't match. We update." 4 35 ; sleep 2 + git pull origin master + fi + trap : 0 + dialog --title 'Update message' --infobox 'Update finished.' 4 20 ; sleep 2 + # We call updated install script + + ./install.sh