From 520566417ed568be022dfedc5e7196a5e0d4122f Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Mon, 25 May 2015 15:47:44 +0200 Subject: [PATCH] Added Pre/Post Lock/Unlock Scripts --- doorlockd/CMakeLists.txt | 8 ++++++++ doorlockd/config.h.in | 5 +++++ doorlockd/door.cpp | 14 ++++++++++++-- doorlockd/scripts/post_lock | 3 +++ doorlockd/scripts/post_unlock | 1 + doorlockd/scripts/pre_lock | 1 + doorlockd/scripts/pre_unlock | 1 + 7 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 doorlockd/scripts/post_lock create mode 100755 doorlockd/scripts/post_unlock create mode 100755 doorlockd/scripts/pre_lock create mode 100755 doorlockd/scripts/pre_unlock diff --git a/doorlockd/CMakeLists.txt b/doorlockd/CMakeLists.txt index 7bb1ce4..8a94b80 100644 --- a/doorlockd/CMakeLists.txt +++ b/doorlockd/CMakeLists.txt @@ -46,3 +46,11 @@ install(DIRECTORY scripts/ DESTINATION share/doorlockd/ PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE OWNER_WRITE) install(FILES scripts/doorlockd.service DESTINATION /etc/systemd/system/) install(FILES scripts/doorlockd DESTINATION /etc/sysconfig/) + +install(DIRECTORY scripts/ DESTINATION etc/doorlockd/ + FILES_MATCHING PATTERN "scripts/pre_*lock" + PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE OWNER_WRITE) + +install(DIRECTORY scripts/ DESTINATION etc/doorlockd/ + FILES_MATCHING PATTERN "scripts/post_*lock" + PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE OWNER_WRITE) diff --git a/doorlockd/config.h.in b/doorlockd/config.h.in index 392cc19..94fa872 100644 --- a/doorlockd/config.h.in +++ b/doorlockd/config.h.in @@ -19,4 +19,9 @@ #define TEMPLATE_LOCATION "@CMAKE_INSTALL_PREFIX@/share/doorlockd/template.png" +#define PRE_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_lock &" +#define POST_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_lock &" +#define PRE_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_unlock &" +#define POST_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_unlock &" + #endif diff --git a/doorlockd/door.cpp b/doorlockd/door.cpp index 553fc10..af8ae20 100644 --- a/doorlockd/door.cpp +++ b/doorlockd/door.cpp @@ -3,6 +3,7 @@ #include #include +#include "config.h" #include "logger.h" #include "door.h" @@ -31,6 +32,9 @@ Door &Door::get() void Door::lock() { + _l(LogLevel::notice, "Executing Pre Lock Script"); + system(PRE_LOCK_SCRIPT); + digitalWrite(_SCHNAPPERPIN, HIGH); _l(LogLevel::info, "Door closed"); @@ -41,12 +45,15 @@ void Door::lock() _heartbeat.join(); } - // Turn off all lights - system("wget -O /dev/null --timeout 3 \"http://homer.binary.kitchen:8080/set?color=000000\" > /dev/null 2>&1"); + _l(LogLevel::notice, "Executing Post Lock Script"); + system(POST_LOCK_SCRIPT); } void Door::unlock() { + _l(LogLevel::notice, "Executing Pre Unlock Script"); + system(PRE_UNLOCK_SCRIPT); + // In any case, klacker the schnapper _schnapper = true; @@ -103,4 +110,7 @@ void Door::unlock() }); _l(LogLevel::info, "Door opened"); + + _l(LogLevel::notice, "Executing Post Unlock Script"); + system(POST_UNLOCK_SCRIPT); } diff --git a/doorlockd/scripts/post_lock b/doorlockd/scripts/post_lock new file mode 100755 index 0000000..36cdca5 --- /dev/null +++ b/doorlockd/scripts/post_lock @@ -0,0 +1,3 @@ +#!/bin/bash + +wget -O /dev/null --timeout 3 "http://homer.binary.kitchen:8080/set?color=000000" > /dev/null 2>&1 diff --git a/doorlockd/scripts/post_unlock b/doorlockd/scripts/post_unlock new file mode 100755 index 0000000..a9bf588 --- /dev/null +++ b/doorlockd/scripts/post_unlock @@ -0,0 +1 @@ +#!/bin/bash diff --git a/doorlockd/scripts/pre_lock b/doorlockd/scripts/pre_lock new file mode 100755 index 0000000..a9bf588 --- /dev/null +++ b/doorlockd/scripts/pre_lock @@ -0,0 +1 @@ +#!/bin/bash diff --git a/doorlockd/scripts/pre_unlock b/doorlockd/scripts/pre_unlock new file mode 100755 index 0000000..a9bf588 --- /dev/null +++ b/doorlockd/scripts/pre_unlock @@ -0,0 +1 @@ +#!/bin/bash