From d72da01ade32b492103365c8e9161ff18c34ab23 Mon Sep 17 00:00:00 2001 From: st33v Date: Sat, 14 Jan 2017 20:18:48 +1100 Subject: working script and systemd path/service combo --- .gitignore | 4 +++- editpix.path | 10 ++++++++++ editpix.service | 10 ++++++++++ editpix.sh | 50 ++++++++++++++++++++++++++++++++------------------ getpix.service | 10 ---------- 5 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 editpix.path create mode 100644 editpix.service mode change 100644 => 100755 editpix.sh delete mode 100644 getpix.service diff --git a/.gitignore b/.gitignore index 2c348c6..435158d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ lucerne/* - +bump* +mark* +*.config diff --git a/editpix.path b/editpix.path new file mode 100644 index 0000000..232191f --- /dev/null +++ b/editpix.path @@ -0,0 +1,10 @@ +# SJP 14 Jan 2017 +[Unit] +Description=Triggers webcam-pix editing and copy to webserver + +[Path] +PathModified=/home/st33v/cams/ + +[Install] +WantedBy=multi-user.target + diff --git a/editpix.service b/editpix.service new file mode 100644 index 0000000..21c7083 --- /dev/null +++ b/editpix.service @@ -0,0 +1,10 @@ +[Unit] +Description=edit and copy pix to webserver + +[Service] +Type=simple +User=st33v +# prefix call to script with '-' to accept nonzero ('failed') exit status +# I woulod prefer to know how to prevent the 'failure' in the first place. +ExecStart=-/usr/local/bin/editpix.sh + diff --git a/editpix.sh b/editpix.sh old mode 100644 new mode 100755 index cf3bb6d..6b1d202 --- a/editpix.sh +++ b/editpix.sh @@ -3,24 +3,32 @@ # SJP 30 Dec 2015 V1 (Copy and process photos from a cam-equipped raspi) ########### Constants ################## -wanWebServer="f3rr3t.com" -#sourcedir="/home/st33v/pix" # where the image is on the source computer (i.e. $campi) -thisdir="/home/st33v/cams" # this directory (on this computer) -threshold="2000" # minimum value of average pixel brightness. Tests if pic is too dark +web="example.com:/path/to/remote/camrootdir" # web server. configured in paths.config +thisdir="/path/to/cams" # this directory (on this computer) Configured in paths.config +if [ -e /usr/local/share/editpix/paths.config ]; then + . /usr/local/share/editpix/paths.config +else echo "paths.config does not exist, see readme"; exit 1 +fi +threshold="2000" # minimum value of average pixel brightness. Tests if pic is too dark ########### end Consts ################ # cam names in an array: -#declare -a camz=(neatherd lucerne) +declare -a camz=(neatherd lucerne) -########### Functions ################## -# get the filename of the most recent photo stored on this computer. -########### end Funcs ################# +cd ${thisdir} # root directory for uploaded pix -cd ${thisdir} - - # record the latest photo BEFORE we look for a new one - newpic=$(ls "$campi"/*.jpg -t | head -1); +for campi in "${camz[@]}" +do + # filename of the latest photo + newpic=$(ls "$campi"/*.jpg -t 2>/dev/null | head -1) + echo newpic=$newpic + # Is the newest pic older than the marker we placed previously? + if [ -e "$campi" ]; then + if [ "$newpic" -ot mark-"$campi" ]; then continue; fi + else + touch mark-$campi # should only happen on the first ever execution + fi # Check to see if the pic is too dark (i.e. taken at night) mean=$(identify -format %[mean] ${newpic} | sed s/[.].*//) # echo "mean is $mean" @@ -33,13 +41,19 @@ cd ${thisdir} # Improve sharpness and resize photo, ready for upload to webserver # Break into two steps to avoid out-of-memory errors (OS kills process) - convert ${newpic} -unsharp 1.5x1+0.7+0.02 temp.jpg - convert temp.jpg -resize 33% -quality 70 ${newpic} - rm temp.jpg + convert ${newpic} -unsharp 1.5x1+0.7+0.02 transfer.jpg + convert transfer.jpg -resize 33% -quality 70 transfer.jpg + # Create a marker file with the name of the webcam, so next time we can + # check to see if a new photo is present for that camera; the PATH + # may have been triggered by a phot from another camera. + touch mark-$campi # upload latest pic to web server # echo "/home/st33v/cams/$newpic" -# echo "$wanWebServer:/home/st33v/farm/cam/$campi/" - scp /home/st33v/cams/$newpic $wanWebServer:/home/st33v/farm/cam/$campi/. - +# echo "$web:/home/st33v/farm/cam/$campi/" + scp transfer.jpg $web/$campi/. + touch bump-$(hostname) + scp bump-$(hostname) $web/. + rm transfer.jpg +done #exit(0) # force success exit code for fussy systemd diff --git a/getpix.service b/getpix.service deleted file mode 100644 index e2ca248..0000000 --- a/getpix.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Retrieve photos from cam raspis, situated within LAN - -[Service] -Type=simple -User=st33v -# prefix call to script with '-' to accept nonzero ('failed') exit status -# I woulod prefer to know how to prevent the 'failure' in the first place. -ExecStart=-/usr/local/bin/getpix.sh - -- cgit v1.3