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