Motion Scripts
Jump to navigation
Jump to search
Main Article: MidsouthMakers_Webcams
Motion Scripts
We use two bash scripts to manage motion data. One simply copies the last snapshot to the live web server for the main domain to link to.
- imagedelay.sh
cp /motion/1.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-1.jpg cp /motion/2.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-2.jpg cp /motion/3.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-3.jpg cp /motion/4.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-4.jpg cp /motion/5.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-5.jpg
Our second script rotates the previous day's images into it's own archive folder and copies an easy to view gallery.
- archivemotion.sh
#!/bin/bash DATE=`date -d '1 day ago' +%Y-%m-%d` echo $DATE PATH1="/motion/1.camera.midsouthmakers.org/$DATE" echo $PATH1 mkdir $PATH1 mv /motion/1.camera.midsouthmakers.org/$DATE-* $PATH1/. cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/1.camera.midsouthmakers.org/$DATE/index.php # PATH2="/motion/2.camera.midsouthmakers.org/$DATE" echo $PATH2 mkdir $PATH2 mv /motion/2.camera.midsouthmakers.org/$DATE-* $PATH2/. cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/2.camera.midsouthmakers.org/$DATE/index.php # PATH3="/motion/3.camera.midsouthmakers.org/$DATE" echo $PATH3 mkdir $PATH3 mv /motion/3.camera.midsouthmakers.org/$DATE-* $PATH3/. cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/3.camera.midsouthmakers.org/$DATE/index.php # PATH4="/motion/4.camera.midsouthmakers.org/$DATE" echo $PATH4 mkdir $PATH4 mv /motion/4.camera.midsouthmakers.org/$DATE-* $PATH4/. cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/4.camera.midsouthmakers.org/$DATE/index.php # PATH5="/motion/5.camera.midsouthmakers.org/$DATE" echo $PATH5 mkdir $PATH5 mv /motion/5.camera.midsouthmakers.org/$DATE-* $PATH5/. cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/5.camera.midsouthmakers.org/$DATE/index.php
Gallery Sciprts
We use 2 gallery scripts, one lists folders to be placed in the root of the individual camera folder, the other is to be copied into each archived folder.
- gallery.php
<?php ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); function folderlist(){ $startdir = './'; $ignoredDirectory[] = '.'; $ignoredDirectory[] = '..'; if (is_dir($startdir)){ if ($dh = opendir($startdir)){ while (($folder = readdir($dh)) !== false){ if (!(array_search($folder,$ignoredDirectory) > -1)){ if (filetype($startdir . $folder) == "dir"){ $directorylist[$startdir . $folder]['name'] = $folder; $directorylist[$startdir . $folder]['path'] = $startdir; } } } closedir($dh); } } return($directorylist); } echo("<table><tr><td>Past Archives</td></tr>"); $folders = folderlist(); foreach ($folders as $folder){ $path = $folder['path']; $name = $folder['name']; echo '<tr><td><a href="'. $path . $name .'">' . $name . '</a></td></tr>'; } echo("</table>"); // open the current directory by opendir $handle=opendir("."); $images = array(); $videos = array(); $imagestring = ".jpg"; $videostring = ".mov"; while (($file = readdir($handle))!==false) { if ($file == "." || $file == ".."){ //nothing } else { //echo "$file <br>"; if(strstr($file,$imagestring)) { //echo "found it."; //echo("$file : " . date ("Ymd Gis", filemtime($file)) . "<BR>"); $imagedate = date("Ymd Gis", filemtime($file)); $images["$imagedate"][] = "<img src=\"" . $file . "\">"; //$images[] = $file; } else { //echo "not found."; } if(strstr($file,$videostring)) { //echo "found it."; $videos[] = $file; } else { //echo "not found."; } } } sort($images); //ksort($videos); foreach ($images as $imagelink) { //echo("$imagelink"); foreach ($imagelink as $key=>$temptwo) { echo "$temptwo", "\n"; } } closedir($handle); ?>
- galleryarchive.php
<?php ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); function folderlist(){ $startdir = './'; $ignoredDirectory[] = '.'; $ignoredDirectory[] = '..'; if (is_dir($startdir)){ if ($dh = opendir($startdir)){ while (($folder = readdir($dh)) !== false){ if (!(array_search($folder,$ignoredDirectory) > -1)){ if (filetype($startdir . $folder) == "dir"){ $directorylist[$startdir . $folder]['name'] = $folder; $directorylist[$startdir . $folder]['path'] = $startdir; } } } closedir($dh); } } return($directorylist); } // open the current directory by opendir $handle=opendir("."); $images = array(); $videos = array(); $imagestring = ".jpg"; $videostring = ".mov"; while (($file = readdir($handle))!==false) { if ($file == "." || $file == ".."){ //nothing } else { //echo "$file <br>"; if(strstr($file,$imagestring)) { //echo "found it."; //echo("$file : " . date ("Ymd Gis", filemtime($file)) . "<BR>"); $imagedate = date("Ymd Gis", filemtime($file)); $images["$imagedate"][] = "<img src=\"" . $file . "\">"; //$images[] = $file; } else { //echo "not found."; } if(strstr($file,$videostring)) { //echo "found it."; $videos[] = $file; } else { //echo "not found."; } } } sort($images); //ksort($videos); foreach ($images as $imagelink) { //echo("$imagelink"); foreach ($imagelink as $key=>$temptwo) { echo "$temptwo", "\n"; } } closedir($handle); ?>
Apache Configuration
Six site files make up the local Apache server. This allows us to serve the camera data from a secondary location to our main web server.
- /etc/apache2/sites-available/camera.midsouthmakers.org
<VirtualHost *:80> ServerName camera.midsouthmakers.org ServerAlias camera.midsouthmakers.org ServerAdmin admin@midsouthmakers.org DocumentRoot /motion/camera.midsouthmakers.org <Directory /motion/camera.midsouthmakers.org/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/midsouthmakers.log combined </VirtualHost>
- /etc/apache2/sites-available/1.camera.midsouthmakers.org
<VirtualHost *:80> ServerName 1.camera.midsouthmakers.org ServerAlias 1.camera.midsouthmakers.org ServerAdmin admin@midsouthmakers.org DocumentRoot /motion/1.camera.midsouthmakers.org <Directory /motion/1.camera.midsouthmakers.org/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/midsouthmakers.log combined </VirtualHost>
- /etc/apache2/sites-available/2.camera.midsouthmakers.org
<VirtualHost *:80> ServerName 2.camera.midsouthmakers.org ServerAlias 2.camera.midsouthmakers.org ServerAdmin admin@midsouthmakers.org DocumentRoot /motion/2.camera.midsouthmakers.org <Directory /motion/2.camera.midsouthmakers.org/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/midsouthmakers.log combined </VirtualHost>
- /etc/apache2/sites-available/3.camera.midsouthmakers.org
<VirtualHost *:80> ServerName 3.camera.midsouthmakers.org ServerAlias 3.camera.midsouthmakers.org ServerAdmin admin@midsouthmakers.org DocumentRoot /motion/3.camera.midsouthmakers.org <Directory /motion/3.camera.midsouthmakers.org/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/midsouthmakers.log combined </VirtualHost>
- /etc/apache2/sites-available/4.camera.midsouthmakers.org
<VirtualHost *:80> ServerName 4.camera.midsouthmakers.org ServerAlias 4.camera.midsouthmakers.org ServerAdmin admin@midsouthmakers.org DocumentRoot /motion/4.camera.midsouthmakers.org <Directory /motion/4.camera.midsouthmakers.org/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/midsouthmakers.log combined </VirtualHost>
- /etc/apache2/sites-available/5.camera.midsouthmakers.org
<VirtualHost *:80> ServerName 5.camera.midsouthmakers.org ServerAlias 5.camera.midsouthmakers.org ServerAdmin admin@midsouthmakers.org DocumentRoot /motion/5.camera.midsouthmakers.org <Directory /motion/5.camera.midsouthmakers.org/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/midsouthmakers.log combined </VirtualHost>