Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh /etc/rc.common
- # Service for running z-agent on OpenWRT or other uci-managed system
- # Put your certificates into /etc/z-connector/Certificates
- # Enable the service by editing the config: /etc/config/z-connector
- # The config has following format (remove leading # below)
- #config service zagent
- # option Enabled '0'
- ## option Device '/dev/ttyUSB0'
- ## option Server 'z-cloud.z-wave.me'
- ## option CaCert '/etc/z-connector/Certificates/cacert.pem'
- ## option Cert '/etc/z-connector/Certificates/cert.pem'
- ## option Key '/etc/z-connector/Certificates/cert.key'
- ## option Log 'syslog'
- ## option Port '9087'
- # Copyright (c) 2012 by Alexey N. Vinogradov (a.n.vinogradov@gmail.com)
- START=50
- NAME="z-connector"
- EXECUTABLE="z-agent"
- SERVICE_DAEMONIZE=1
- SERVICE_WRITE_PID=1
- PROG="/bin/$EXECUTABLE"
- start() {
- local section="zagent"
- local pid_file="/var/run/${NAME}.pid"
- config_load ${NAME}
- #check if the service is enabled
- local enabled
- config_get_bool enabled "${section}" Enabled 0
- if [ "${enabled}" -eq 0 ] ; then
- echo "Service is disabled. Edit your config to enable"
- return 1
- fi
- local args=""
- local val
- config_get val "${section}" Device "/dev/ttyUSB0"
- if [ -e "${val}" ] ; then
- append args "-d ${val}"
- else
- echo "you must specify path to the serial port of Z-Wave as 'Device' in config"
- return 1
- fi
- config_get val "${section}" Server "z-cloud.z-wave.me"
- if [ "z${val}"!="z" ] ; then
- append args "-s ${val}"
- else
- echo "you must specify IP address or host name to connect to 'Server' in config"
- return 1
- fi
- config_get val "${section}" Port 0
- [ "${val}" -ne 0 ] && append args "-P $val"
- local certs="/etc/z-connector/Certificates"
- config_get val "${section}" Cert "$certs/cert.pem"
- [ -f "${val}" ] && append args "--cert=$val"
- config_get val "${section}" Key "$certs/cert.key"
- [ -f "${val}" ] && append args "--key=$val"
- config_get val "${section}" CaCert "$certs/cacert.pem"
- [ -f "${val}" ] && append args "--cacert=$val"
- config_get val "${section}" Log syslog
- append args "-L ${val}"
- config_get_bool val "${section}" Debug 0
- [ "${val}" -eq 1 ] && append args "--debug"
- SERVICE_PID_FILE="$pid_file" service_start ${PROG} ${args}
- }
- stop()
- {
- local pid_file="/var/run/${NAME}.pid"
- SERVICE_PID_FILE="$pid_file" service_stop ${PROG} && {
- rm -f ${pid_file}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement