Commit e3aa3c67 authored by Hermann Mayer's avatar Hermann Mayer

[Config] Added install targets for source-installation, added a PKGBUILD file…

[Config] Added install targets for source-installation, added a PKGBUILD file for ArchLinux packaging and a systemd unit for it. (See #10)
parent e27dbf13
......@@ -2,5 +2,6 @@
*.out
*.o
*.bin
*.gz
/src/bin/avmctl
/src/bin/avm-motion-triggerd
......@@ -9,8 +9,10 @@ DOCS = $(MAN_PAGES:%=docs-%)
build:
$(MAKE) build -C src/
$(MAKE) build -C docs/man/
clean:
$(MAKE) clean -C src/
$(MAKE) clean -C docs/man/
test:
$(MAKE) test -C src/test/
$(TEST_BINS):
......@@ -19,6 +21,14 @@ $(TEST_MEM_BINS):
$(MAKE) $@ -C src/test/
$(DOCS):
$(MAKE) $@ -C docs/man/
install:
$(MAKE) $@ -C src/
$(MAKE) $@ -C docs/man/
$(MAKE) $@ -C dist/
uninstall:
$(MAKE) $@ -C src/
$(MAKE) $@ -C docs/man/
$(MAKE) $@ -C dist/
all: build
.PHONY: all clean test
export TEST := test
export PRINTF := printf
export CP := cp
export MV := mv
export RM := rm
export FIND := find
export GCC := gcc
export MAN := man
export INSTALL := install
XML_CONF := xml2-config
export CFLAGS = $(shell $(XML_CONF) --cflags) -Wall -Werror -g -O0
export INCLUDES = $(shell $(XML_CONF) --libs) -lcurl -lcrypto -lconfig -lbcm2835
DESTDIR ?=
export prefix ?= /usr/local
export datarootdir ?= $(prefix)/share
export exec_prefix ?= $(prefix)
export bindir ?= $(exec_prefix)/bin
export mandir ?= $(datarootdir)/man
export sysconfdir ?= $(prefix)/etc
export libdir ?= $(exec_prefix)/lib
install:
-$(TEST) -d $(DESTDIR)$(sysconfdir) || \
$(INSTALL) -dm755 $(DESTDIR)$(sysconfdir)
$(INSTALL) -m644 avm-motion-trigger.conf $(DESTDIR)$(sysconfdir)
uninstall:
-$(TEST) -f $(DESTDIR)$(sysconfdir)/avm-motion-trigger.conf && \
$(RM) $(DESTDIR)$(sysconfdir)/avm-motion-trigger.conf
# Maintainer: <hermann.mayer92@gmail.com>
pkgname=avm-motion-trigger
pkgver=0.1.0
pkgrel=1
pkgdesc="AVM Smart Home Motion Trigger Daemon"
url="http://code.jity.de/Jack12816/avm-motion-trigger"
arch=('armv6h' 'armv7h' 'x86_64')
license=('GPLv3')
depends=('glibc' 'libconfig' 'curl' 'libbcm2835' 'libxml2')
source=("http://code.jity.de/Jack12816/${pkgname}/repository/archive.tar.gz?ref=${pkgver}")
md5sums=('7b11f805f0e7c8505129ae6e368ff91a')
build() {
cd ${pkgname}-${pkgver}-*
make build
}
package() {
cd ${pkgname}-${pkgver}-*
make prefix=/usr sysconfdir=/etc DESTDIR="${pkgdir}" install
install -Dm644 dist/archlinux/avm-motion-triggerd.service "$pkgdir"/usr/lib/systemd/system/avm-motion-triggerd.service
install -Dm644 dist/shell-completion/bash/avmctl "$pkgdir"/usr/share/bash-completion/completions/avmctl
}
[Unit]
Description=AVM Smart Home Motion Trigger Daemon
After=local-fs.target network.target
Documentation=man:avm-motion-triggerd(1)
[Service]
ExecStart=/usr/bin/avm-motion-triggerd -c /etc/avm-motion-trigger.conf -f
Restart=always
[Install]
WantedBy=multi-user.target
#
# AVM Motion Trigger
#
#
# AVM FRITZ!Box credentials
#
# The hostname/ip[:port] of the fritzbox without protocol scheme or URI paths,
# by default "fritz.box"
# hostname = "";
# The username of the fritzbox which is able to perform smart home management
# According to the documentation from AVM this setting can be empty, by default empty
# username = "";
# The plaintext password of the fritzbox, by default 0000
# password = "";
#
# Device configuration
#
# The Actor Identification Number of the AVM Smart Switch to control
ain = "FF:FF:FF:FF:FF:FF";
# Turn off the device after n seconds
# 0 will disable automatic turn off, defaults to 0
turn_device_off_after = 600;
# The specified command will be send to the actor in case a motion
# was detected. Available commands are: `on`, `off`, `toggle`.
# Defaults to `on`.
# actor_command = "on";
#
# Sensor thresholds
#
# With a 10-bit ADC (eg. MCP3008) the range is 0-1023
# The daemon takes care of a PIR motion trigger if the value of the light is
# below the specified threshold
# 0 will disable the light sensor check
# light_sensor_thold = 500;
# If you set the turn_device_off_after parameter to 0 you probably want
# to build a toggle-by-motion setup. In this case it is advisable to specify
# a time range which prevent jitter triggering. So no action is performed
# for n seconds after a motion was detected. Defaults to 30 seconds.
# motion_sensor_locktime = 0;
#
# Sensor ports
#
# Specify a GPIO pin for the PIR motion sensor
# The daemon assumes a state change from LOW to HIGH represents a recognized motion
motion_sensor_gpio = 17;
# The daemon assumes to read the light level from a MCP3008 which is connected
# to the SPI bus. With this setting you can configure which channel of the chip
# will be read out.
# light_sensor_channel = 0;
# avmctl(1) completion -*- shell-script -*-
#
# Copyright (c) 2015 Hermann Mayer
#
# This file is part of avm-motion-trigger.
#
# avm-motion-trigger is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# avm-motion-trigger is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with avm-motion-trigger. If not, see <http://www.gnu.org/licenses/>.
__contains_word () {
local w word=$1; shift
for w in "$@"; do
[[ $w = "$word" ]] && return
done
}
_avmctl () {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local i verb comps
local -A OPTS=(
[ARG]='--host -H --help -h --config -c --user -u --password -p'
)
if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in
--host|-H)
comps=$(compgen -A hostname)
;;
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
fi
if [[ "$cur" = -* ]]; then
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
return 0
fi
local -A VERBS=(
[MISC]='check-config list present state status toggle off on'
)
for ((i=0; i < COMP_CWORD; i++)); do
if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
verb=${COMP_WORDS[i]}
break
fi
done
if __contains_word "${prev}" ${VERBS[*]}; then
return 0
fi
comps="${VERBS[*]}"
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
}
complete -F _avmctl avmctl
PAGE_FILES = $(wildcard *.[0-9])
PAGES = $(PAGE_FILES:%=docs-%)
BUILD_PAGES = $(PAGE_FILES:%=build-%.gz)
CLEAN_PAGES = $(PAGE_FILES:%=clean-%.gz)
DOCS_PAGES = $(PAGE_FILES:%=docs-%)
INSTALL_PAGES = $(PAGE_FILES:%=install-%.gz)
UNINSTALL_PAGES = $(PAGE_FILES:%=uninstall-%.gz)
$(PAGES): PAGE = $(@:docs-%=%)
$(PAGES): docs-%:%
$(BUILD_PAGES): IN_FILE = $(@:build-%.gz=%)
$(BUILD_PAGES): OUT_FILE = $(@:build-%=%)
$(BUILD_PAGES):
$(TEST) -f $(OUT_FILE) || \
gzip -c $(IN_FILE) > $(OUT_FILE)
$(CLEAN_PAGES): PAGE = $(@:clean-%=%)
$(CLEAN_PAGES):
$(TEST) -f $(PAGE) && \
$(RM) $(PAGE) 2>/dev/null || true
build: $(BUILD_PAGES)
clean: $(CLEAN_PAGES)
$(DOCS_PAGES): PAGE = $(@:docs-%=%)
$(DOCS_PAGES):
$(MAN) ./$(PAGE)
.PHONY: $(PAGES)d
$(INSTALL_PAGES): PAGE = $(@:install-%=%)
$(INSTALL_PAGES): PAGE_SUF = $(suffix $(@:install-%.gz=%))
$(INSTALL_PAGES): PAGE_DIR = $(PAGE_SUF:.%=man%)
$(INSTALL_PAGES):
-$(TEST) -d $(DESTDIR)$(mandir) || \
$(INSTALL) -dm755 $(DESTDIR)$(mandir)
-$(TEST) -d $(DESTDIR)$(mandir)/$(PAGE_DIR) || \
$(INSTALL) -dm755 $(DESTDIR)$(mandir)/$(PAGE_DIR)
$(INSTALL) -m644 $(PAGE) $(DESTDIR)$(mandir)/$(PAGE_DIR)
$(UNINSTALL_PAGES): PAGE = $(@:uninstall-%=%)
$(UNINSTALL_PAGES): PAGE_SUF = $(suffix $(@:uninstall-%.gz=%))
$(UNINSTALL_PAGES): PAGE_DIR = $(PAGE_SUF:.%=man%)
$(UNINSTALL_PAGES):
-$(TEST) -f $(DESTDIR)$(mandir)/$(PAGE_DIR)/$(PAGE) && \
$(RM) $(DESTDIR)$(mandir)/$(PAGE_DIR)/$(PAGE)
install: build $(INSTALL_PAGES)
uninstall: $(UNINSTALL_PAGES)
.PHONY: $(DOCS_PAGES)
SUBDIRS ?= utils avm sensors test bin
BUILD_SUBDIRS := $(SUBDIRS:%=build-%)
INSTALL_SUBDIRS := $(SUBDIRS:%=install-%)
UNINSTALL_SUBDIRS := $(SUBDIRS:%=uninstall-%)
CLEAN_SUBDIRS := $(SUBDIRS:%=clean-%)
OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
......@@ -27,6 +29,18 @@ $(CLEAN_SUBDIRS):
clean: $(CLEAN_OBJS) $(CLEAN_SUBDIRS)
build: $(OBJS) $(BUILD_SUBDIRS)
$(INSTALL_SUBDIRS): DIR = $(@:install-%=%)
$(INSTALL_SUBDIRS):
$(MAKE) install -C $(DIR)
$(UNINSTALL_SUBDIRS): DIR = $(@:uninstall-%=%)
$(UNINSTALL_SUBDIRS):
$(MAKE) uninstall -C $(DIR)
install: build $(INSTALL_SUBDIRS)
uninstall: $(UNINSTALL_SUBDIRS)
all: build
.PHONY: all clean $(BUILD_SUBDIRS) $(CLEAN_SUBDIRS) $(OBJS)
OBJS = $(shell $(FIND) .. -type f -name *.o)
BINS = $(patsubst %.c,%,$(wildcard *.c))
CLEAN_BINS = $(BINS:%=clean-%)
INSTALL_BINS = $(BINS:%=install-%)
UNINSTALL_BINS = $(BINS:%=uninstall-%)
$(BINS): INFILE = $(@:%=%.c)
$(BINS):
......@@ -17,6 +19,20 @@ $(CLEAN_BINS):
clean: $(CLEAN_BINS)
build: $(BINS)
$(INSTALL_BINS): BIN = $(@:install-%=%)
$(INSTALL_BINS):
-$(TEST) -d $(DESTDIR)$(bindir) || \
$(INSTALL) -dm755 $(DESTDIR)$(bindir)
$(INSTALL) -m755 $(BIN) $(DESTDIR)$(bindir)
$(UNINSTALL_BINS): BIN = $(@:uninstall-%=%)
$(UNINSTALL_BINS):
-$(TEST) -f $(DESTDIR)$(bindir)/$(BIN) && \
$(RM) $(DESTDIR)$(bindir)/$(BIN)
install: $(INSTALL_BINS)
uninstall: $(UNINSTALL_BINS)
all: build
.PHONY: clean build
......@@ -42,6 +42,8 @@ clean: $(CLEAN_BINS)
test: $(TEST_BINS)
test-mem: $(TEST_MEM_BINS)
build: $(BINS)
install: ;
uninstall: ;
all: build
.PHONY: clean build
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment