Advertisement
Guest User

z-connector OpenWRT init script

a guest
Dec 4th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.36 KB | None | 0 0
  1. #!/bin/sh /etc/rc.common
  2.  
  3. # Service for running z-agent on OpenWRT or other uci-managed system
  4.  
  5. # Put your certificates into /etc/z-connector/Certificates
  6. # Enable the service by editing the config: /etc/config/z-connector
  7.  
  8. # The config has following format (remove leading # below)
  9.  
  10. #config service zagent
  11. #   option Enabled  '0'
  12. ##  option Device   '/dev/ttyUSB0'
  13. ##  option Server   'z-cloud.z-wave.me'
  14. ##  option CaCert   '/etc/z-connector/Certificates/cacert.pem'
  15. ##  option Cert '/etc/z-connector/Certificates/cert.pem'
  16. ##  option Key  '/etc/z-connector/Certificates/cert.key'
  17. ##  option Log  'syslog'
  18. ##  option Port '9087'
  19.  
  20. # Copyright (c) 2012 by Alexey N. Vinogradov (a.n.vinogradov@gmail.com)
  21.  
  22.  
  23. START=50
  24.  
  25. NAME="z-connector"
  26. EXECUTABLE="z-agent"
  27. SERVICE_DAEMONIZE=1
  28. SERVICE_WRITE_PID=1
  29. PROG="/bin/$EXECUTABLE"
  30.  
  31. start() {
  32.     local section="zagent"
  33.     local pid_file="/var/run/${NAME}.pid"
  34.     config_load ${NAME}
  35.    
  36.     #check if the service is enabled
  37.     local enabled
  38.     config_get_bool enabled "${section}" Enabled 0
  39.     if [ "${enabled}" -eq 0 ] ; then
  40.         echo "Service is disabled. Edit your config to enable"
  41.         return 1
  42.     fi
  43.    
  44.     local args=""
  45.     local val
  46.     config_get val "${section}" Device "/dev/ttyUSB0"
  47.     if [ -e "${val}" ] ; then
  48.         append args "-d ${val}"
  49.     else
  50.         echo "you must specify path to the serial port of Z-Wave as 'Device' in config"
  51.         return 1
  52.     fi
  53.  
  54.     config_get val "${section}" Server "z-cloud.z-wave.me"
  55.     if [ "z${val}"!="z" ] ; then
  56.         append args "-s ${val}"
  57.     else
  58.         echo "you must specify IP address or host name to connect to 'Server' in config"
  59.         return 1
  60.     fi
  61.     config_get val "${section}" Port 0
  62.     [ "${val}" -ne 0 ] && append args "-P $val"
  63.  
  64.     local certs="/etc/z-connector/Certificates"
  65.     config_get val "${section}" Cert "$certs/cert.pem"
  66.     [ -f "${val}" ] && append args "--cert=$val"
  67.     config_get val "${section}" Key "$certs/cert.key"
  68.     [ -f "${val}" ] && append args "--key=$val"
  69.     config_get val "${section}" CaCert "$certs/cacert.pem"
  70.     [ -f "${val}" ] && append args "--cacert=$val"
  71.     config_get val "${section}" Log syslog
  72.     append args "-L ${val}"
  73.     config_get_bool val "${section}" Debug 0
  74.     [ "${val}" -eq 1 ] && append args "--debug"
  75.    
  76.     SERVICE_PID_FILE="$pid_file" service_start ${PROG} ${args}
  77. }
  78.  
  79. stop()
  80. {
  81.     local pid_file="/var/run/${NAME}.pid"
  82.     SERVICE_PID_FILE="$pid_file" service_stop ${PROG} && {
  83.         rm -f ${pid_file}
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement